使用python在opencv中创建自己的轮廓 [英] Creating your own contour in opencv using python

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

问题描述

我有一组物体的边界点.

I have a set of boundary points of an object.

我想使用opencv作为轮廓来绘制它.

I want to draw it using opencv as contour.

我不知道如何将我的点转换为轮廓表示.

I have no idea that how to convert my points to contour representation.

对于通过后续调用获得的相同轮廓表示

To the same contour representation which is obtained by following call

  contours,_ = cv2.findContours(image,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

有什么想法吗?

谢谢

推荐答案

通过查看轮廓的格式,我认为这样就足够了:

By looking at the format of the contours I would think something like this should be sufficient:

contours = [numpy.array([[1,1],[10,50],[50,50]], dtype=numpy.int32) , numpy.array([[99,99],[99,60],[60,99]], dtype=numpy.int32)]

这个小程序提供了一个正在运行的示例:

This small program gives an running example:

import numpy
import cv2

contours = [numpy.array([[1,1],[10,50],[50,50]], dtype=numpy.int32) , numpy.array([[99,99],[99,60],[60,99]], dtype=numpy.int32)]

drawing = numpy.zeros([100, 100],numpy.uint8)
for cnt in contours:
    cv2.drawContours(drawing,[cnt],0,(255,255,255),2)

cv2.imshow('output',drawing)
cv2.waitKey(0)

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

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