cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘circle‘报错

这里我对图像做与运算

import cv2
import numpy as np
img=cv2.imread('a.jpg',cv2.IMREAD_GRAYSCALE)
row,col=img.shape[:2]
print(row,col)
circle=np.zeros((row,col),dtype='uint8')
cv2.circle(circle,(row/2,col/2),100,255,-1)
result=cv2.bitwise_and(img,circle)
cv2.imshow('a',img)
cv2.imshow('circle',circle)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()

运行时发现报错,如下图 

cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘circle‘报错_第1张图片

 报错为类型错误,导致无法分析出圆心坐标。主要是因为我们圆心坐标是用图片的宽高除以二得到,为float类型,其他均为int类型,我们将圆心坐标类型转换为int类型即可

cv2.circle(circle,(row//2,col//2),50,255,-1)

运行后结果如下图所示

cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘circle‘报错_第2张图片

 

你可能感兴趣的:(python图像处理,python)