出现背景:
拟合圆,得到拟合的圆心和半径后,使用opencv画圆时出现报错
报错信息:
- 圆心半径画圆时,圆心坐标没转换成int
cv2.circle(im,(x,y),r,(0,0,255),2)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
- 圆心半径画圆时,半径没转换成int
cv2.circle(im,(x_int, y_int),r,(0,0,255),2)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Argument 'radius' is required to be an integer
> - Argument 'radius' is required to be an integer
- 画圆心时,圆心坐标没转换成int
cv2.circle(im,(x,y),2,(0,255,0),3)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
- 在图上写文字时,定位坐标没转换成int
cv2.putText(im, '(' + str(round(x))+',' + str(round(y)) + '),r:' + str(round(r)), (0,y) , cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),1)
cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'putText'
> Overload resolution failed:
> - Can't parse 'org'. Sequence item with index 1 has a wrong type
> - Can't parse 'org'. Sequence item with index 1 has a wrong type
总结:
- 在图片上画图时要保证相关坐标信息转换成像素对应的int整数,包括半径这样的参数