OpenCV DescriptorMatcher match error. Wrong KeyPoints Descriptor type?
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.
did you miss the fact, that you have to compute descriptors from the keypoints first, and match those ? (not the keypoints)
Actually ... yes ^^ thank you. I forgot to compute the descriptor