OpenCV DescriptorMatcher match error. Wrong KeyPoints Descriptor type?

asked 2014-05-17 07:21:35 -0600

Guian gravatar image

updated 2014-05-17 10:57:47 -0600

berak gravatar image

I'm using OpenCV on Android for image recognition by computing distance between MatOfKeyPoints

I use the method described here : http://stackoverflow.com/questions/15572357/compare-the-similarity-of-two-images-with-opencv

At first it worked fine, then I tried to save my keyPoints for futur use.

Then, when I try to match descriptors I've got :

05-17 13:03:21.376: E/cv::error()(15762): OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in virtual void cv::BFMatcher::knnMatchImpl(const cv::Mat&, std::vector<std::vector<cv::DMatch> >&, int, const std::vector<cv::Mat>&, bool), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/features2d/src/matchers.cpp, line 351
05-17 13:03:21.376: E/org.opencv.features2d(15762): features2d::match_11() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/features2d/src/matchers.cpp:351: error: (-215) queryDescriptors.type() == trainDescCollection[0].type() in function virtual void cv::BFMatcher::knnMatchImpl(const cv::Mat&, std::vector<std::vector<cv::DMatch> >&, int, const std::vector<cv::Mat>&, bool)

I assume the error is due to a difference in the data type.

I saved one of my MatOfKeyPoints by saving each keypoint from the extracted array :

KeyPoint[] points = mat.toArray();

each keypoint is then serialized and saved for futur use.

Then I recreate my MatOfKeyPoints using :

MatOfKeyPoint mokp = new MatOfKeyPoint();
mokp.fromArray(savedKeypointsArray);

Before saving MatOfKeyPoint, the data type was CV_8UC1, after recreating it, its now CV_32FC(7)

So if I get it right, the question is : Is there a way to set the data type on a newly created MatOfKeyPoint ?

I've tried :

MatOfKeyPoint mokp = new MatOfKeyPoint();   
mokp.fromArray(array);
mokp.convertTo(mokp, CvType.CV_8UC1);

but after this code, the mokp datatype is : CV_8UC(7)

And I've got the same error, matching 2 descriptors with datatypes : CV_8UC(7) and CV_8UC1 :/

and I'm stuck. I'd like to know what's the "(7)" here ?

Thanks for any comment.

edit retag flag offensive close merge delete

Comments

1

did you miss the fact, that you have to compute descriptors from the keypoints first, and match those ? (not the keypoints)

berak gravatar imageberak ( 2014-05-17 07:47:27 -0600 )edit

Actually ... yes ^^ thank you. I forgot to compute the descriptor

Guian gravatar imageGuian ( 2014-05-18 15:14:48 -0600 )edit