@@ -93,6 +93,7 @@ void Matrix::Init(Local<Object> target) {
93
93
Nan::SetPrototypeMethod (ctor, " equalizeHist" , EqualizeHist);
94
94
Nan::SetPrototypeMethod (ctor, " floodFill" , FloodFill);
95
95
Nan::SetPrototypeMethod (ctor, " matchTemplate" , MatchTemplate);
96
+ Nan::SetPrototypeMethod (ctor, " matchTemplateByMatrix" , MatchTemplateByMatrix);
96
97
Nan::SetPrototypeMethod (ctor, " templateMatches" , TemplateMatches);
97
98
Nan::SetPrototypeMethod (ctor, " minMaxLoc" , MinMaxLoc);
98
99
Nan::SetPrototypeMethod (ctor, " pushBack" , PushBack);
@@ -2246,6 +2247,36 @@ NAN_METHOD(Matrix::TemplateMatches) {
2246
2247
info.GetReturnValue ().Set (probabilites_array);
2247
2248
}
2248
2249
2250
+ // @author Evilcat325
2251
+ // MatchTemplate accept a Matrix
2252
+ // Usage: output = input.matchTemplateByMatrix(matrix. method);
2253
+ NAN_METHOD (Matrix::MatchTemplateByMatrix) {
2254
+ Nan::HandleScope scope;
2255
+
2256
+ Matrix *self = Nan::ObjectWrap::Unwrap<Matrix>(info.This ());
2257
+ Matrix *templ = Nan::ObjectWrap::Unwrap<Matrix>(info[0 ]->ToObject ());
2258
+
2259
+ Local<Object> out = Nan::New (Matrix::constructor)->GetFunction ()->NewInstance ();
2260
+ Matrix *m_out = Nan::ObjectWrap::Unwrap<Matrix>(out);
2261
+ int cols = self->mat .cols - templ->mat .cols + 1 ;
2262
+ int rows = self->mat .rows - templ->mat .rows + 1 ;
2263
+ m_out->mat .create (cols, rows, CV_32FC1);
2264
+
2265
+ /*
2266
+ TM_SQDIFF =0
2267
+ TM_SQDIFF_NORMED =1
2268
+ TM_CCORR =2
2269
+ TM_CCORR_NORMED =3
2270
+ TM_CCOEFF =4
2271
+ TM_CCOEFF_NORMED =5
2272
+ */
2273
+
2274
+ int method = (info.Length () < 2 ) ? (int )cv::TM_CCORR_NORMED : info[1 ]->Uint32Value ();
2275
+ if (!(method >= 0 && method <= 5 )) method = (int )cv::TM_CCORR_NORMED;
2276
+ cv::matchTemplate (self->mat , templ->mat , m_out->mat , method);
2277
+ info.GetReturnValue ().Set (out);
2278
+ }
2279
+
2249
2280
// @author ytham
2250
2281
// Match Template filter
2251
2282
// Usage: output = input.matchTemplate("templateFileString", method);
@@ -2277,19 +2308,19 @@ NAN_METHOD(Matrix::MatchTemplate) {
2277
2308
int method = (info.Length () < 2 ) ? (int )cv::TM_CCORR_NORMED : info[1 ]->Uint32Value ();
2278
2309
cv::matchTemplate (self->mat , templ, m_out->mat , method);
2279
2310
cv::normalize (m_out->mat , m_out->mat , 0 , 1 , cv::NORM_MINMAX, -1 , cv::Mat ());
2280
- double minVal;
2281
- double maxVal;
2282
- cv::Point minLoc;
2311
+ double minVal;
2312
+ double maxVal;
2313
+ cv::Point minLoc;
2283
2314
cv::Point maxLoc;
2284
2315
cv::Point matchLoc;
2285
2316
2286
2317
minMaxLoc (m_out->mat , &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat ());
2287
2318
2288
- if (method == CV_TM_SQDIFF || method == CV_TM_SQDIFF_NORMED) {
2289
- matchLoc = minLoc;
2319
+ if (method == CV_TM_SQDIFF || method == CV_TM_SQDIFF_NORMED) {
2320
+ matchLoc = minLoc;
2290
2321
}
2291
- else {
2292
- matchLoc = maxLoc;
2322
+ else {
2323
+ matchLoc = maxLoc;
2293
2324
}
2294
2325
2295
2326
// detected ROI
0 commit comments