OpenCV 3.0.0 MSER Binary Mask

帅比萌擦擦* 提交于 2019-12-30 06:14:06

问题


I am trying to use MSER algorithm in OpenCV 3.0.0 beta to extract text regions from an image. At the end I need a binary mask with the detected MSER regions, but the algorithm only provides contours. I tried to draw these contours but I don't get the expected result.

This is the code I use:

void mserExtractor (const Mat& image, Mat& mserOutMask){
    Ptr<MSER> mserExtractor  = MSER::create();

    vector<vector<cv::Point>> mserContours;
    vector<cv::Rect> mserBbox;
    mserExtractor->detectRegions(image, mserContours, mserBbox);

    for( int i = 0; i<mserContours.size(); i++ )
    {
        drawContours(mserOutMask, mserContours, i, Scalar(255, 255, 255), 4);
    }
}

This is the result:

The problem is that non-convex regions are filled by lines crossing the actual MSER region. I would like just the list of pixels in the region like I get from MATLAB detectMSERFeatures:

Any ideas how to get the filled region from the contours (or to get the MSER mask in other ways)?


回答1:


I found the solution! Just loop over all the points and draw them!

void mserExtractor (const Mat& image, Mat& mserOutMask){
    Ptr<MSER> mserExtractor  = MSER::create();

    vector<vector<cv::Point>> mserContours;
    vector<KeyPoint> mserKeypoint;
    vector<cv::Rect> mserBbox;
    mserExtractor->detectRegions(image, mserContours,  mserBbox);

    for (vector<cv::Point> v : mserContours){
        for (cv::Point p : v){
            mserOutMask.at<uchar>(p.y, p.x) = 255;
        }
    }
}


来源:https://stackoverflow.com/questions/28515084/opencv-3-0-0-mser-binary-mask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!