【发布时间】:2018-08-10 21:00:51
【问题描述】:
我想在那个类中使用 opencv SimpleBlobDetector 检测 blob
cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(parameters);
detector->detect( inputImage, keypoints);
这很好用,直到我想引入一个掩码,以便检测器只查找掩码中的斑点。
detector->detect( inputImage, keypoints, zmat );
从文档中,link,它说:
指定在何处查找关键点的掩码(可选)。它必须是一个 感兴趣区域中具有非零值的 8 位整数矩阵。
我的理解是检测算法将只搜索掩码矩阵中的非零元素。所以,我创建了一个掩码并以这种方式填充::
cv::Mat zmat = cv::Mat::zeros(inputImage.size(), CV_8UC1);
cv::Scalar color(255,255,255);
cv::Rect rect(x,y,w,h);
cv::rectangle(zmat, rect, color, CV_FILLED);
但是,掩码似乎没有做任何事情,而检测算法正在检测所有内容。我正在使用OpenCV 3.2。
我也尝试了简单的 roi,但检测器仍然检测到一切:
cv::Mat roi(zmat, cv::Rect(10,10,600,600));
roi = cv::Scalar(255, 255, 255);
// match keypoints of connected components with blob detection
detector->detect( inputImage, keypoints, zmat);
【问题讨论】:
-
你有没有试过在opencv源代码中查看掩码参数是如何被使用的?
-
@Cristi 好主意,我只是没有时间这样做,而且我认为已经有人可以这样做了。
标签: c++ opencv object-detection feature-detection