@@ -93,6 +93,7 @@ void Matrix::Init(Local<Object> target) {
9393 Nan::SetPrototypeMethod (ctor, " equalizeHist" , EqualizeHist);
9494 Nan::SetPrototypeMethod (ctor, " floodFill" , FloodFill);
9595 Nan::SetPrototypeMethod (ctor, " matchTemplate" , MatchTemplate);
96+ Nan::SetPrototypeMethod (ctor, " matchTemplateByMatrix" , MatchTemplateByMatrix);
9697 Nan::SetPrototypeMethod (ctor, " templateMatches" , TemplateMatches);
9798 Nan::SetPrototypeMethod (ctor, " minMaxLoc" , MinMaxLoc);
9899 Nan::SetPrototypeMethod (ctor, " pushBack" , PushBack);
@@ -2246,6 +2247,36 @@ NAN_METHOD(Matrix::TemplateMatches) {
22462247 info.GetReturnValue ().Set (probabilites_array);
22472248}
22482249
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+
22492280// @author ytham
22502281// Match Template filter
22512282// Usage: output = input.matchTemplate("templateFileString", method);
@@ -2277,19 +2308,19 @@ NAN_METHOD(Matrix::MatchTemplate) {
22772308 int method = (info.Length () < 2 ) ? (int )cv::TM_CCORR_NORMED : info[1 ]->Uint32Value ();
22782309 cv::matchTemplate (self->mat , templ, m_out->mat , method);
22792310 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;
22832314 cv::Point maxLoc;
22842315 cv::Point matchLoc;
22852316
22862317 minMaxLoc (m_out->mat , &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat ());
22872318
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;
22902321 }
2291- else {
2292- matchLoc = maxLoc;
2322+ else {
2323+ matchLoc = maxLoc;
22932324 }
22942325
22952326 // detected ROI
0 commit comments