当前位置: 首页 > 工具软件 > k0s > 使用案例 >

error: (-215) data0.dims <= 2 && type == CV_32F && K > 0

东门晨
2023-12-01



OpenCV Error: Assertion failed (data0.dims <= 2 && type == CV_32F && K > 0) in cv::kmeans, file C:\projects\opencv-python\opencv\modules\core\src\kmeans.cpp, line 232
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/sample/jiaozheng/bianyuan/cut_test.py", line 212, in <module>
    ompactness, labels, centers = cv2.kmeans(lines, 4,None,criteria, 8, cv2.KMEANS_RANDOM_CENTERS)
cv2.error: C:\projects\opencv-python\opencv\modules\core\src\kmeans.cpp:232: error: (-215) data0.dims <= 2 && type == CV_32F && K > 0 in function cv::kmeans


原因:kmeans需要数据的float32类型,


解决:数据强转一下float32类型:

lines=np.float32(np.array(m)

 类似资料: