在python OpenCV(cv2)中从头开始创建轮廓 [英] Create contour from scratch in python OpenCV (cv2)

查看:268
本文介绍了在python OpenCV(cv2)中从头开始创建轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用opencv python接口cv2确定多边形是否凸出.根据我在网上发现的所有内容,输入轮廓必须是每个点的一个float32元组的numpy数组.所以我认为它是这样工作的:

I am trying to use the opencv python interface cv2 to determine if a polygon is convex. From all I found on the web, the input contour must be a numpy array of float32 tuples for each point. So I assumed it to work like this:

import cv2, numpy
contour = numpy.array( [ 
(378, 949), (375, 940), (368, 934), 
(359, 932), (350, 937), (345, 955), 
(351, 962), (359, 966), (368, 964), 
(376, 958) ], numpy.float32 )
cv2.isContourConvex(contour)

但是我得到这个错误:

OpenCV Error: Unsupported format or combination of formats (The matrix can not be converted to point sequence because of inappropriate element type) in cvPointSeqFromMat, file /tmp/buildd/opencv-2.3.1/modules/imgproc/src/utils.cpp, line 59

谁能告诉我哪种元素类型合适,以及如何从头开始创建轮廓?

Can anyone tell me what element type would be appropriate and how to therefore create a contour from scratch?

推荐答案

在debian测试中,openCV安装存在问题.从源代码安装openCV 2.4.8后,它可以工作. 感谢您的帮助!

It was a problem with the openCV installation on debian testing. After installing openCV 2.4.8 from source, it works. Thanks for the help!

这篇关于在python OpenCV(cv2)中从头开始创建轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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