poster
2019-12-10, 16:49
我有一个从OpenCV的 (http://opencv.willowgarage.com/)边缘检测模块中提取的边缘贴图(Canny边缘检测)。我要做的是填补边缘贴图中的孔。
我正在使用C ++和OpenCV库。在OpenCV中,有一个cvFloodFill() (http://opencv.willowgarage.com/documentation/image_processing.html?highlight=cvfloodfill#cvFloodFill)函数,它将用种子填充孔(其中一个位置开始填充)。但是,我试图在不知道种子的情况下填充所有内部孔(类似于MATLAB中的imfill() (http://www.mathworks.com/help/images/ref/imfill.html) )
问题1:如何查找所有种子,以便我可以应用“ cvFloodFill()”?
问题2:如何实现“ imfill()”等效项?
OpenCV中的新手,任何提示都值得赞赏。
回答:
根据MATLAB中imfill (http://www.mathworks.com/help/images/ref/imfill.html)的文档:
BW2 = imfill(BW,'holes'); 填充二进制图像BW中的孔。孔是一组背景像素,无法通过从图像边缘填充背景来达到。
因此,要获取“孔”像素,请使用图像的左角像素作为种子来调用cvFloodFill (http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#floodfill) 。您可以通过补充上一步中获得的图像来获得漏洞。
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) https://i.stack.imgur.com/6kKjV.png (https://i.stack.imgur.com/6kKjV.png) https://i.stack.imgur.com/8TF1r.png (https://i.stack.imgur.com/8TF1r.png)
更多&回答... (https://stackoverflow.com/questions/1716274)
我正在使用C ++和OpenCV库。在OpenCV中,有一个cvFloodFill() (http://opencv.willowgarage.com/documentation/image_processing.html?highlight=cvfloodfill#cvFloodFill)函数,它将用种子填充孔(其中一个位置开始填充)。但是,我试图在不知道种子的情况下填充所有内部孔(类似于MATLAB中的imfill() (http://www.mathworks.com/help/images/ref/imfill.html) )
问题1:如何查找所有种子,以便我可以应用“ cvFloodFill()”?
问题2:如何实现“ imfill()”等效项?
OpenCV中的新手,任何提示都值得赞赏。
回答:
根据MATLAB中imfill (http://www.mathworks.com/help/images/ref/imfill.html)的文档:
BW2 = imfill(BW,'holes'); 填充二进制图像BW中的孔。孔是一组背景像素,无法通过从图像边缘填充背景来达到。
因此,要获取“孔”像素,请使用图像的左角像素作为种子来调用cvFloodFill (http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#floodfill) 。您可以通过补充上一步中获得的图像来获得漏洞。
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) https://i.stack.imgur.com/6kKjV.png (https://i.stack.imgur.com/6kKjV.png) https://i.stack.imgur.com/8TF1r.png (https://i.stack.imgur.com/8TF1r.png)
更多&回答... (https://stackoverflow.com/questions/1716274)