MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   填补OpenCV中的漏洞 (https://www.labfans.com/bbs/showthread.php?t=22893)

poster 2019-12-10 16:49

填补OpenCV中的漏洞
 
我有一个从[URL="http://opencv.willowgarage.com/"]OpenCV的[/URL]边缘检测模块中提取的边缘贴图(Canny边缘检测)。我要做的是填补边缘贴图中的孔。

我正在使用[B]C ++[/B]和[B]OpenCV[/B]库。在OpenCV中,有一个[URL="http://opencv.willowgarage.com/documentation/image_processing.html?highlight=cvfloodfill#cvFloodFill"]cvFloodFill()[/URL]函数,它将用种子填充孔(其中一个位置开始填充)。但是,我试图在不知道种子的情况下填充所有内部孔(类似于MATLAB中的[URL="http://www.mathworks.com/help/images/ref/imfill.html"]imfill()[/URL] )

[B]问题1:[/B]如何查找所有种子,以便我可以应用“ cvFloodFill()”?
[B]问题2:[/B]如何实现“ imfill()”等效项?

OpenCV中的新手,任何提示都值得赞赏。


回答:
根据MATLAB中[URL="http://www.mathworks.com/help/images/ref/imfill.html"]imfill[/URL]的文档:
[INDENT] BW2 = imfill(BW,'holes'); 填充二进制图像BW中的孔。孔是一组背景像素,无法通过从图像边缘填充背景来达到。

[/INDENT]因此,要获取“孔”像素,请使用图像的左角像素作为种子来调用[URL="http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#floodfill"]cvFloodFill[/URL] 。您可以通过补充上一步中获得的图像来获得漏洞。

[B] MATLAB示例: [/B]

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) [URL="https://i.stack.imgur.com/6kKjV.png"][IMG]https://i.stack.imgur.com/6kKjV.png[/IMG][/URL] [URL="https://i.stack.imgur.com/8TF1r.png"][IMG]https://i.stack.imgur.com/8TF1r.png[/IMG][/URL]



[url=https://stackoverflow.com/questions/1716274]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 10:30

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.