OpenCV错误(-215:Assertion failed) npoints > 0 in function

在使用OpenCV绘图函数时容易遇到 (-215:Assertion failed) npoints > 0 错误。代码如下:

import numpy
import cv2

mask = numpy.zeros([4000, 4000, 3])
cnt=[[ 1626.   360.]
 [ 1776.  3108.]
 [  126.  3048.]
 [  330.   486.]]
cv2.drawContours(mask, [cnt], 0, (0, 255, 0), -1)

出错:(-215:Assertion failed) npoints > 0 in function cv::drawContours

更新代码:

ctr = numpy.array(cnt).reshape((-1,1,2)).astype(numpy.int32)
cv2.drawContours(mask, [ctr], 0, (0, 255, 0), -1)

猜你喜欢

转载自blog.csdn.net/dou3516/article/details/113560877
今日推荐