c++ - Opencv2.4.9 SimpleBlobDetector 掩码不起作用

标签 c++ opencv feature-detection

我已仔细阅读此网站以寻求解释,但无济于事...希望有人知道答案。

我正在使用 simpleBlobDetector 来跟踪一些 Blob 。我想通过检测方法指定一个 mask ,但由于某种原因, mask 似乎不起作用——我的关键点显示在整个图像上。以下是我的一些代码片段:

Mat currFrame;
Mat mask;
Mat roi;
cv::Ptr<cv::FeatureDetector> blob_detector = new cv::SimpleBlobDetector(params);//custom set of params I've left out for legibility 
blob_detector->create("SimpleBlob");

vector<cv::KeyPoint> myblob;

while(true)
{   
    captured >> currFrame; // get a new frame from camera >> is grab and retrieve in one go, note grab does not allow frame to be modified but edges can be

    // do nothing if frame is empty
    if(currFrame.empty())
    {
        break;
    }

    /******************** make mask***********************/
    mask = Mat::zeros(currFrame.size(),CV_8U);
    roi = Mat(mask,Rect(400,400,400,400));
    roi = 255;

    /******************** image cleanup with some filters*/
    GaussianBlur(currFrame,currFrame, Size(5,5), 1.5, 1.5);
    cv::medianBlur(currFrame,currFrame,3);

    blob_detector->detect(fgMaskMOG,myblob,mask);//fgMaskMOG is currFrame after some filtering and background subtraction
    cv::drawKeypoints(fgMaskMOG,myblob,fgMaskMOG,Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

    imshow("mogForeground", fgMaskMOG);
    imshow("original", currFrame);
    imshow("mask",mask);
    if(waitKey(1) != -1)
        break;
}

事实是,我确认我的面具是通过使用此处描述的 SurfFeatureDetector 正确制作的 (OpenCV: howto use mask parameter for feature point detection (SURF)) 如果有人能看出我的面具有什么问题,我将非常感谢您的帮助。抱歉乱码!

最佳答案

我遇到了同样的问题,找不到解决办法,所以我自己检查掩码解决了:

blob_detector->detect(img, keypoints);

std::vector<cv::KeyPoint> keypoints_in_range;

for (cv::KeyPoint &kp : keypoints)
    if (mask.at<char>(kp.pt) > 0)
         keypoints_in_range.push_back(kp)

关于c++ - Opencv2.4.9 SimpleBlobDetector 掩码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24357516/

相关文章:

用于识别多个不同图像的OpenCV特征检测

c++ - 目标文件不包含应该存在的符号

python - 我已经安装了 OpenCV C++。我可以在不重新安装库的情况下在 Python 中使用它的功能吗?

c++ - 如何附加到 C++ 预处理器宏?

opencv - 在 Tesseract 中处理 IplImage(OpenCV) 数据

python - 来自 python 的 OpenCV 中的随机树

java - cvFindHomography 抛出错误

python - opencv-python : drawMatchesKnn() always return NULL

c++ - 将运算符重载为成员函数或非成员(友元)函数?

c++ - 具有嵌套类的模板 LinkedList 类