points.checkVector(2, CV_32S) >= 0 in function ‘cv::fillConvexPoly‘

x33g5p2x  于2022-02-07 转载在 其他  
字(0.6k)|赞(0)|评价(0)|浏览(270)

points.checkVector(2, CV_32S) >= 0 in function 'cv::fillConvexPoly'

错误代码:

import cv2
import numpy as np

image =np.zeros((500, 500, 3), dtype=np.uint8)

roi_as = []

data=np.array([[172.0, 82], [194.0, 86], [182, 151.0], [194, 86]])

roi_as.append(data.astype(np.uint8))

cv2.polylines(image, roi_as, True, (255, 0, 255))  # 画任意多边形

cv2.imshow("image", image)
cv2.waitKey()

解决方法,需要把数据转为np.int类型。

正确代码:

import cv2
import numpy as np

image =np.zeros((500, 500, 3), dtype=np.uint8)

roi_as = []

data=np.array([[172.0, 82], [194.0, 86], [182, 151.0], [194, 86]])

roi_as.append(data.astype(np.int))

cv2.polylines(image, roi_as, True, (255, 0, 255))  # 画任意多边形

cv2.imshow("image", image)
cv2.waitKey()

相关文章