From dc02f9b9261770bc735fbb41975f101226e4d69a Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 09:59:35 +0200 Subject: [PATCH 1/7] fix assertion failed error --- src/Features2d.cc | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index fa8f1cb7..44c125a8 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -46,38 +46,46 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { extractor->compute(image1, keypoints1, descriptors1); extractor->compute(image2, keypoints2, descriptors2); - matcher->match(descriptors1, descriptors2, matches); - double max_dist = 0; - double min_dist = 100; - - //-- Quick calculation of max and min distances between keypoints - for (int i = 0; i < descriptors1.rows; i++) { - double dist = matches[i].distance; - if (dist < min_dist) { - min_dist = dist; - } - if (dist > max_dist) { - max_dist = dist; + if (descriptors1.type == descriptors2.type && descriptors1.cols == descriptors2.cols) { + matcher->match(descriptors1, descriptors2, matches); + + double max_dist = 0; + double min_dist = 100; + + //-- Quick calculation of max and min distances between keypoints + for (int i = 0; i < descriptors1.rows; i++) { + double dist = matches[i].distance; + if (dist < min_dist) { + min_dist = dist; + } + if (dist > max_dist) { + max_dist = dist; + } } - } - //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist, - //-- or a small arbitary value ( 0.02 ) in the event that min_dist is very - //-- small) - //-- PS.- radiusMatch can also be used here. - std::vector good_matches; - double good_matches_sum = 0.0; - - for (int i = 0; i < descriptors1.rows; i++) { - double distance = matches[i].distance; - if (distance <= std::max(2 * min_dist, 0.02)) { - good_matches.push_back(matches[i]); - good_matches_sum += distance; + //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist, + //-- or a small arbitary value ( 0.02 ) in the event that min_dist is very + //-- small) + //-- PS.- radiusMatch can also be used here. + std::vector good_matches; + double good_matches_sum = 0.0; + + for (int i = 0; i < descriptors1.rows; i++) { + double distance = matches[i].distance; + if (distance <= std::max(2 * min_dist, 0.02)) { + good_matches.push_back(matches[i]); + good_matches_sum += distance; + } } - } - dissimilarity = (double) good_matches_sum / (double) good_matches.size(); + dissimilarity = (double) good_matches_sum / (double) good_matches.size(); + + } + else { + dissimilarity = std::numeric_limits::quiet_NaN(); + } + } void HandleOKCallback() { From 5263a43f0832c750dc9762ab269da27040e698d9 Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 10:06:28 +0200 Subject: [PATCH 2/7] fix assertion failed error --- src/Features2d.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index 44c125a8..ef1baa23 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -47,7 +47,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { extractor->compute(image2, keypoints2, descriptors2); - if (descriptors1.type == descriptors2.type && descriptors1.cols == descriptors2.cols) { + if (descriptors1.type() == descriptors2.type() && descriptors1.cols() == descriptors2.cols()) { matcher->match(descriptors1, descriptors2, matches); double max_dist = 0; From 413dd7bf976af380e44778cd25dc5ccefa649008 Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 10:09:54 +0200 Subject: [PATCH 3/7] fix assertion failed error --- src/Features2d.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index ef1baa23..d3eb121e 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -47,7 +47,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { extractor->compute(image2, keypoints2, descriptors2); - if (descriptors1.type() == descriptors2.type() && descriptors1.cols() == descriptors2.cols()) { + if (descriptors1.type() == descriptors2.type() && descriptors1.cols == descriptors2.cols) { matcher->match(descriptors1, descriptors2, matches); double max_dist = 0; @@ -83,7 +83,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { } else { - dissimilarity = std::numeric_limits::quiet_NaN(); + dissimilarity = Nan::Null(); } } From 12c1c4fd06d378ca2607908359637d6702655cf0 Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 10:14:56 +0200 Subject: [PATCH 4/7] fix assertion failed error --- src/Features2d.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index d3eb121e..1f484386 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -83,7 +83,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { } else { - dissimilarity = Nan::Null(); + dissimilarity = null; } } From 938f048e831769c17957c0e84c86ff70c0eb78e2 Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 10:19:09 +0200 Subject: [PATCH 5/7] fix assertion failed error --- src/Features2d.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index 1f484386..6c3b9400 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -5,6 +5,7 @@ #include "Matrix.h" #include #include +#include void Features::Init(Local target) { Nan::HandleScope scope; @@ -83,7 +84,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { } else { - dissimilarity = null; + dissimilarity = std::numeric_limits::quiet_NaN(); } } From c26e95507d0330bc5d1b0fe99e57cfd6c756ebbd Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 10:49:21 +0200 Subject: [PATCH 6/7] fix assertion failed error --- src/Features2d.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index 6c3b9400..1aa96137 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -84,7 +84,14 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { } else { - dissimilarity = std::numeric_limits::quiet_NaN(); + Nan::HandleScope scope; + + Local argv[2]; + + argv[0] = Nan::Null(); + argv[1] = Nan::Null(); + + callback->Call(2, argv); } } From 5f63d23899b20f910b86eea1d79c8d1c03a7f4ec Mon Sep 17 00:00:00 2001 From: TanaseButcaru Date: Mon, 29 Feb 2016 11:15:53 +0200 Subject: [PATCH 7/7] fix assertion failed error --- src/Features2d.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Features2d.cc b/src/Features2d.cc index 1aa96137..4048a2be 100644 --- a/src/Features2d.cc +++ b/src/Features2d.cc @@ -47,7 +47,8 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { extractor->compute(image1, keypoints1, descriptors1); extractor->compute(image2, keypoints2, descriptors2); - + //fix for 'Assertion failed...' error + //source: http://stackoverflow.com/questions/15650371/matcher-assertions-failed-error-opencv-android if (descriptors1.type() == descriptors2.type() && descriptors1.cols == descriptors2.cols) { matcher->match(descriptors1, descriptors2, matches); @@ -84,14 +85,7 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { } else { - Nan::HandleScope scope; - - Local argv[2]; - - argv[0] = Nan::Null(); - argv[1] = Nan::Null(); - - callback->Call(2, argv); + dissimilarity = std::numeric_limits::quiet_NaN(); } } @@ -102,7 +96,9 @@ class AsyncDetectSimilarity: public Nan::AsyncWorker { Local argv[2]; argv[0] = Nan::Null(); - argv[1] = Nan::New(dissimilarity); + + if (dissimilarity != dissimilarity) argv[1] = Nan::Null(); + else argv[1] = Nan::New(dissimilarity); callback->Call(2, argv); }