问题描述
我试图在OpenCV 3.0.0 beta中使用MSER算法从图像中提取文本区域.最后,我需要具有检测到的MSER区域的二进制掩码,但是该算法仅提供轮廓.我试图绘制这些轮廓,但没有得到预期的结果.
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.
这是我使用的代码:
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);
}
}
这是结果:
问题在于,非凸区域由与实际MSER区域交叉的线填充.我只想像从MATLAB detectMSERFeatures
获得的区域中的像素列表:
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
:
有什么想法如何从轮廓获取填充区域(或以其他方式获取MSER蒙版)?
Any ideas how to get the filled region from the contours (or to get the MSER mask in other ways)?
推荐答案
我找到了解决方案!只需遍历所有点并绘制它们即可!
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;
}
}
}
这篇关于OpenCV 3.0.0 MSER二进制掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!