Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 break and tell me a error:

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

can you tell me how can i do

click to hide/show revision 2
No.2 Revision

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 I call the knnMatch 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 I run the program,which break program, which crashes and tell me a shows the error:

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

can you tell help me how can i do

I fix this?

click to hide/show revision 3
No.3 Revision

some problem about knnMatch

Hi guys,I guys, I am a frensh man in opencv developers,I developers, I read the book “Mastering OpenCV with Practical Computer Vision Projects”,in Projects”, in the three character,I character, I find a problem,the problem, the book use ORB ORB as detector,Freak detector, FREAK as descriptorextractor,and the BFMatcher DescriptorExtractor, and the BFMatcher as matcher,when matcher. When I call the knnMatch function,the function, the program pop a bug。here 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?