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

created at 09-08-2022 views: 5

code

Here I am doing an AND operation on the image

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()

An error is found when running, as follows

cv2.error: OpenCV(4.5.3) :-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:

reason & solution

The error is a type error, which makes it impossible to analyze the coordinates of the center of the circle. Mainly because the coordinates of the center of the circle are obtained by dividing the width and height of the image by two, which is of type float, and the others are of type int. We can convert the type of center coordinates to type int.

cv2.circle(circle,(row//2,col//2),50,255,-1)
created at:09-08-2022
edited at: 09-08-2022: