用opencv python填充轮廓 [英] filling contours with opencv python

查看:4225
本文介绍了用opencv python填充轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有二维图像,其折线由:

I have binary image with polylines created with:

cv2.polylines(binaryImage,contours,1, (255,255,255))

我现在需要的是填充所有折线的有效方法。我还没有在opencv中找到这样的方法,但也许它存在。或者,也许我可以实现算法来完成这项工作(但快速 - 我有高清就绪图片)。请分享您的想法..

What I need now is effective method to fill all polylines. I haven't found such method in opencv, but maybe it exists. Alternatively, maybe I could implement algorithm to do the job (but fast one- I have HD ready pictures). Please share your thoughts..

推荐答案

我认为你要找的是 cv2.fillPoly ,填充由一个区域限定的区域或更多的多边形。这是一个简单的片段,我生成一个四个点的轮廓,表示一个正方形的顶点,然后我用白色填充多边形。

I think what you are looking for is cv2.fillPoly, which fills the area bounded by one or more polygons. This is a simple snippet, I generate a contour of four points representing vertices of a square, then I fill the polygon with a white color.

import numpy as np
import cv2

contours = np.array( [ [50,50], [50,150], [150, 150], [150,50] ] )
img = np.zeros( (200,200) ) # create a single channel 200x200 pixel black image 
cv2.fillPoly(img, pts =[contours], color=(255,255,255))
cv2.imshow(" ", img)
cv2.waitKey()

这篇关于用opencv python填充轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆