cv2画多边形报错Overload resolution failed:> - Can‘t parse ‘pts‘. Sequence item with index 0 has a wrong t

cv2画多边形报错Overload resolution failed:> - Can‘t parse ‘pts‘. Sequence item with index 0 has a wrong t,第1张

报错:

cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'polylines'
> Overload resolution failed:
>  - Can't parse 'pts'. Sequence item with index 0 has a wrong type
>  - Can't parse 'pts'. Sequence item with index 0 has a wrong type

代码:

pts = [[1,2],[3,4]]
isClosed, color,thickness = True,(0,255,0),1
cv2.polylines(img, pts, isClosed, color,thickness)

原因:不是没有从浮点转换为整数,而是在此之外,还需要再转为numpy,int32, 加括号
解决:

# 正确的写法
pts = np.array(pts,np.int32)
cv2.polylines(img, [pts], isClosed, color,thickness)

参考1

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/715324.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存