我试图找到凸包,以便我得到opencv库,代码是:
import cv2
import numpy as np
a = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]]
cv2.convexHull(np.array(a))
我收到的错误是 -
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
cv2.convexHull(np.array(a))
error: C:\projects\opencv-python\opencv\modules\imgproc\src\convhull.cpp:137: error: (-215) total >= 0 && (depth == 5 || depth == 4) in function cv::convexHull
怎么解决?
问题在于C ++代码期望“双通道或三通道浮点阵列,其中每个元素都是2D / 3D向量”,它将Python / NumPy转换为3维数组。
import cv2
import numpy as np
a = [[0, 0], [1, 0], [0, 1], [1, 1], [0.5, 0.5]]
cv2.convexHull(np.array(a,dtype='float32'))
资料来源: - http://answers.opencv.org/question/252/cv2perspectivetransform-with-python/