OpenCV如何填充折线 [英] Opencv how to fill a polyline

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

问题描述

下面给出的python代码绘制一个三角形,如何填充内部?还是其他更简单的方法来在OpenCV中绘制三角形?

the python code given below draws a triangle, how can I fill inside? Or other easier way to draw a triangle in OpenCV?

pts = np.array([[100,350],[165,350],[165,240]], np.int32)
cv2.polylines(img,[pts],True,(0,255,255),2)

推荐答案

您必须使用cv2.fillPoly().

将第二行更改为:

cv2.fillPoly(img, [pts], 255)

插图:

img = np.zeros([400, 400],dtype=np.uint8)
pts = np.array([[100,350],[165,350],[165,240]], np.int32)
cv2.fillPoly(img, [pts], 255)
cv2.imshow('Original', img)

结果:

这篇关于OpenCV如何填充折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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