gpt4 book ai didi

opencv - SurfFeatureDetector 并使用 Mat() 创建一个空掩码

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:48 24 4
gpt4 key购买 nike

我想使用 SurfFeatureDetector检测图片指定区域的关键点:

  1. Train_pic & Source_pic
  2. 使用 SurfFeatureDetector 检测 Train_pic keypoint_1 .
  3. 使用 SurfFeatureDetector 检测 Source_pic keypoint_2在指定区域。
  4. 计算和匹配。

OpenCV SurfFeatureDetector如下所示。

void FeatureDetector::detect(const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat())

ma​​sk – 指定在何处查找关键点的掩码(可选)。必须是感兴趣区域中具有非零值的字符矩阵。

任何人都可以帮助解释如何创建mask=Mat()对于 Source_pic?

谢谢周杰伦

最佳答案

从技术上讲,您不必指定空矩阵即可使用 detect 函数,因为它是默认参数。

你可以这样调用detect:

Ptr<FeatureDetector> detector = FeatureDetector::create("SURF");
vector<KeyPoint> keyPoints;
detector->detect(anImage, keyPoints);

或者,通过显式创建空矩阵:

Ptr<FeatureDetector> detector = FeatureDetector::create("SURF");
vector<KeyPoint> keyPoints;
detector->detect(anImage, keyPoints, Mat());

如果你想在感兴趣的区域创建一个掩码,你可以这样创建一个:

假设 Source_picCV_8UC3 类型,

Mat mask = Mat::zeros(Source_pic.size(), Source_pic.type());

// select a ROI
Mat roi(mask, Rect(10,10,100,100));

// fill the ROI with (255, 255, 255) (which is white in RGB space);
// the original image will be modified
roi = Scalar(255, 255, 255);

编辑: 那里有一个复制粘贴错误。为 mask 设置 ROI,然后将其传递给 detect 函数。

希望一切都解决了!

关于opencv - SurfFeatureDetector 并使用 Mat() 创建一个空掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9902368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com