Ask Your Question

hyb's profile - activity

2020-04-17 14:16:40 -0600 received badge  Popular Question (source)
2014-09-23 06:43:27 -0600 asked a question some problem about knnMatch

Hi guys, I am a frensh man in opencv developers, I read the book “Mastering OpenCV with Practical Computer Vision Projects”, in the three character, I find a problem, the book use ORB as detector, FREAK as DescriptorExtractor, and the BFMatcher as matcher. When I call the knnMatch function, the program pop a bug. Here is my code:

cv::Mat patternImg = cv::imread("starry_night_small.jpg", 0);//starry_night
cv::Mat testImg = cv::imread("starry_night_test.jpg", 0);
std::vector<cv::KeyPoint> queryKeypoints;
std::vector<cv::KeyPoint> trainKeypoints;
std::vector<std::vector<cv::DMatch>> matches;
cv::Mat queryDescriptor;
cv::Mat trainDescriptor;
cv::ORB detector(1000);
cv::FREAK extractor(false,false);   
cv::BFMatcher matcher(cv::NORM_HAMMING, true);
detector.detect(patternImg, trainKeypoints);
detector.detect(testImg, queryKeypoints);
extractor.compute(patternImg, trainKeypoints, trainDescriptor);
extractor.compute(testImg, queryKeypoints, queryDescriptor);

matcher.knnMatch(queryDescriptor, trainDescriptor, matches, 1);
cv::imshow("pattern", patternImg);
cout << "matches size-->" << matches.size() << endl;
cv::waitKey(0);

but when I run the program, which crashes and shows the error:

OpenCV Error: Assertion failed (K == 1 && update == 0 && mask.empty()) in cv::batchDistance, file ..\..\..\sources\modules\core\src\stat.cpp, line 2500

can you help me how can I fix this?