我正试图在USB摄像头的视频中找到一个对象。 代码:
for (;;)
{
Mat frame;
cap >> frame;
Mat img_scene = frame;
if (!img_object.data || !img_scene.data)
{
string message = " Error reading ";
readme(message);
}
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect(img_object, keypoints_object);
detector.detect(img_scene, keypoints_scene);
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute(img_object, keypoints_object, descriptors_object);
extractor.compute(img_scene, keypoints_scene, descriptors_scene);
FlannBasedMatcher matcher;
vector< DMatch > matches;
descriptors_object.convertTo(descriptors_object, CV_32F);
descriptors_scene.convertTo(descriptors_scene, CV_32F);
if (descriptors_object.empty())
cvError(0, "MatchFinder", "1st descriptor empty", __FILE__, __LINE__);
if (descriptors_scene.empty())
cvError(0, "MatchFinder", "2nd descriptor empty", __FILE__, __LINE__);
matcher.match(descriptors_object, descriptors_scene, matches);
重新启动PC后,此代码正常运行。但是,下一次尝试是unsuccsessfull,因为descriptors_scene是空的。
如果发表评论if (descriptors_scene.empty())
,则会收到错误消息:
cv :: flann :: buildIndex中不支持的格式或格式组合(type = 0)...
我试图找到一个解决方案,我发现了两个建议:
1)转换为另一种类型(使用descriptors_object.convertTo(descriptors_object, CV_32F);
)-Done,但没有运气。
2)重启PC。它的工作原理和它的荒谬。
感谢您的帮助。提前谢谢。