OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl,

确认两个:

1、图像是灰度的

// Read in the image

Mat img = imread(entryPath.string(), 1);

cvtColor(img, img, CV_BGR2GRAY);

2、描述子要是CV_8UC1形式的(在之前用描述子形成词袋时,描述子格式有转换为CV_32F过)。

cv::Mat dictionary = bowTrainer.cluster();

cv::Mat uDictionary;

dictionary.convertTo(uDictionary, CV_8UC1);

bowDE.setVocabulary(uDictionary);

仍然有疑惑详见:https://answers.opencv.org/question/17460/how-to-use-bag-of-words-example-with-brief-descriptors/

原文地址:https://www.cnblogs.com/rjjhyj/p/10784929.html