我在OpenCV (精明的边缘检测)中从边缘检测模块中提取了一个边缘映射。我想要做的是填补边缘地图上的漏洞。
我正在使用C++和OpenCV库。在OpenCV中有一个cvFloodFill()函数,它将用一个种子(其中一个开始洪泛的位置)填充漏洞。然而,我试图填补所有的内部漏洞,而不知道种子。(类似于填充()中的MATLAB)
Q1:如何找到所有的种子,这样我就可以申请cvFloodFill()了?
Q2:如何实现“imfill()”等价物?
在OpenCV的新手,任何提示都是感激的。
发布于 2009-11-11 18:02:16
根据MATLAB中的imfill文档:
BW2 =填充物(BW,“孔”); 填充二进制图像
BW中的漏洞。洞是一组背景像素,不能通过从图像边缘填充背景来达到。
因此,要获得“洞”像素,可以使用图像的左角像素作为种子调用cvFloodFill。通过对上一步中获得的图像进行补充,您就可以得到这些漏洞。
MATLAB示例:
BW = im2bw( imread('coins.png') );
subplot(121), imshow(BW)
% used here as if it was cvFloodFill
holes = imfill(BW, [1 1]); % [1 1] is the starting location point
BW(~holes) = 1; % fill holes
subplot(122), imshow(BW)


发布于 2010-07-30 18:21:30
cvDrawContours函数有一个选项来填充您绘制的等值线。
这里是一个简短的例子cvDrawContours( IplImage,等高线,颜色,颜色,-1,CV_FILLED,8 );
这是文件
functions.html?highlight=cvdrawcontours#cvDrawContours
我想你很久以前就发过这个了,但我希望它能帮上忙。
这是源代码(在C#中):
Image<Gray, byte> image = new Image<Gray, byte>(@"D:\final.bmp");
CvInvoke.cvShowImage("image 1", image);
var contours = image.FindContours();
while (contours != null)
{
CvInvoke.cvDrawContours(image, contours, new Gray(255).MCvScalar, new Gray (255).MCvScalar, 0, -1, Emgu.CV.CvEnum.LINE_TYPE.CV_AA, new DPoint(0, 0));
contours = contours.HNext;
}
CvInvoke.cvShowImage("image 2", image);

发布于 2013-04-15 12:54:04
我一直在互联网上寻找一个合适的填充函数(如Matlab中的函数),但在C++中与OpenCV一起工作。经过一番思考,我终于想出了一个解决方案:
IplImage* imfill(IplImage* src)
{
CvScalar white = CV_RGB( 255, 255, 255 );
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 3);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
cvFindContours(src, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero( dst );
for( ; contour != 0; contour = contour->h_next )
{
cvDrawContours( dst, contour, white, white, 0, CV_FILLED);
}
IplImage* bin_imgFilled = cvCreateImage(cvGetSize(src), 8, 1);
cvInRangeS(dst, white, white, bin_imgFilled);
return bin_imgFilled;
}用于此:原始二值图像
结果是:最终二值图像
关键在于cvDrawContours函数的参数设置: cvDrawContours( dst,等高线,白色,白色,0,CV_FILLED);
openCV文档中有更多信息。
可能有一种直接将"dst“作为二进制映像的方法,但我无法找到如何使用带有二进制值的cvDrawContours函数。
https://stackoverflow.com/questions/1716274
复制相似问题