cv2.rectangle has two ways of calling:
source:https://docs.opencv.org/4.1.2/d6/d6e/group__imgproc__draw.html#ga07d2f74cadcf8e305e810ce8eed13bc9
I call rectangle as following:
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA)
Error Message:
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA) TypeError: rectangle() missing required argument 'rec' (pos 2)
I do not understand why the application tries to call the overloaded version of the method. U explicitly define version 1 call. I tried changing the variable a with (x,y) etc. but it doesn't work. The correct method call only works the first time I call the retangle() afterwards it expects me to use the overloaded version of it.
opencv-contrib-python 4.1.2.30
imgname='fly_1.jpg'
im = Image.open(imgname)
cv2_im = np.array(im)
#x,y,w,h aus Image Labeler
box= [505.54, 398.334, 1334.43, 2513.223]
x,y,w,h = box
a = (x, y)
b = (x+w, y+h)
#First rectanglecall
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA)
#calls two cv2 methods which shouldn't influence rectangle
rects = getRegionProposals(im,'f',normalized=True)
for i,rect in enumerate(rects):
x, x_max, y, y_max = rect
a = (x*width,y*height)
b = (x_max*width, y_max*height)
if (IoU is not False and IoU > 0.5):
#second and further calls
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA)
In between the second call I used cv2 selective search and set the following: cv2.setUseOptimized(True) cv2.setNumThreads(4)
Hope u guys see what I'm doin wrong.
cv2. rectangle(img, pt1, pt2, color, thickness, lineType, shift) Draws a simple, thick, or filled up-right rectangle. The function rectangle draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2. Parameters img Image.
cv2. rectangle() method is used to draw a rectangle on any image. Parameters: image: It is the image on which rectangle is to be drawn.
To fill the rectangle we use the thickness = -1 in the cv2. rectangle() function.
okay this is sad that I just found out now, after being on this problem yesterday for hours ...
The Values in the tuples were floats.
> a = (x*width,y*height) b = (x_max*width, y_max*height)
After changing them to int, and losing the after comma values it works.
a = (int(x*width),int(y*height))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With