【发布时间】:2012-01-12 06:18:18
【问题描述】:
我尝试在新的 python api (cv2) 中使用 checkContour() 函数,如果我创建要使用 findContours 检查的轮廓,它do 可以工作,例如
contours, hierarchy = cv2.findContours(imgGray, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cv2.contourArea(contours[0])
但是,当我自己创建轮廓时,以下代码不起作用
contour = numpy.array([[0,0], [10,0], [10,10], [5,4]])
area = cv2.contourArea(contour)
并在函数contourArea中返回“错误:(-215)contour.checkVector(2) >= 0 && (contour.depth() == CV_32F || contour.depth() == CV_32S)”
当我换成
contour = numpy.array([[0,0], [10,0], [10,10], [5,4]], dtype=numpy.int32)
我得到“错误:(-210)由于函数 cvPointSeqFromMat 中的元素类型不正确,矩阵无法转换为点序列”
如何从文档中用 C++ 编写以下代码
vector<Point> contour;
contour.push_back(Point2f(0, 0));
contour.push_back(Point2f(10, 0));
contour.push_back(Point2f(10, 10));
contour.push_back(Point2f(5, 4));
double area0 = contourArea(contour);
在最新的 python API (2.3) 中工作?
【问题讨论】: