c – OpenCV:如何使用掩码参数进行特征点检测(SURF)

前端之家收集整理的这篇文章主要介绍了c – OpenCV:如何使用掩码参数进行特征点检测(SURF)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将SurfFeatureDetector限制为一组区域(掩码).对于测试,我只定义一个掩码:
Mat srcImage; //RGB source image
Mat mask = Mat::zeros(srcImage.size(),srcImage.type());
Mat roi(mask,cv::Rect(10,10,100,100));
roi = Scalar(255,255,255);
SurfFeatureDetector detector();
std::vector<KeyPoint> keypoints;
detector.detect(srcImage,keypoints,roi); // crash
//detector.detect(srcImage,keypoints); // does not crash

当我通过“roi”作为掩码时,我得到了这个错误

OpenCV Error: Assertion Failed (mask.empty() || (mask.type() == CV_8UC1 && mask.size() == image.size())) in detect,file /Users/ux/Downloads/OpenCV-iOS/OpenCV-iOS/../opencv-svn/modules/features2d/src/detectors.cpp,line 63

这有什么问题?如何正确地将掩码传递给SurfFeatureDetector的“detect”方法

问候,

@R_404_323@

关于面具的两件事.

>掩码应该是8位无符号字符的1通道矩阵,转换为opencv类型CV_8U.在您的情况下,掩码是srcImage.type()类型,它是一个3通道矩阵
>你正在将roi传递给探测器,但你应该通过面具.当你对roi进行更改时,你也在改变面具.

以下应该有效

Mat srcImage; //RGB source image
Mat mask = Mat::zeros(srcImage.size(),CV_8U);  // type of mask is CV_8U
// roi is a sub-image of mask specified by cv::Rect object
Mat roi(mask,100));
// we set elements in roi region of the mask to 255 
roi = Scalar(255);  
SurfFeatureDetector detector();
std::vector<KeyPoint> keypoints;
detector.detect(srcImage,mask);     // passing `mask` as a parameter
原文链接:https://www.f2er.com/c/116558.html

猜你在找的C&C++相关文章