Python Opencv - Error using drawing function

Asked

Viewed 338 times

0

I’ve been able to run this code before, but now it doesn’t work. It needs to draw a square on the video screen.

Error:

Traceback (Most recent call last): File "/home/ggoulart/Pycharmprojects/Intpyt_handtracker/Main.py", line 13, in cv2.Rectangle(Gray, 100, 100, (0,255,0), 3) Systemerror: new style getargs format but argument is not a tuple

And the code executed:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

# Loop
while (1):

    _, frame = cap.read()

    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    cv2.rectangle(gray, 100, 100, (0,255,0), 3)

    cv2.imshow('Test',gray)

    k = cv2.waitKey(100)
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

Additional information:

Opencv version: 3.x

Host OS: Linux (Fedora 23)

Compiler & Cmake: GCC 5.3 & Cmake 3.5

1 answer

1


The call of the function cv2.rectangle() is incorrect.

The second and third parameters are tuples that represent the coordinates of the opposite vertices of the rectangle that will be drawn in the image.

The call below draws a rectangle of 100x100 pixels in the coordinate 0,0 in the image:

cv2.rectangle(gray, (0,0), (100,100), (0,255,0), 3)

Reference:

cv. Rectangle( img, pt1, pt2, color, Thickness=1, lineType=8, shift=0 ) None

img - Image.

pt1 - Vertex of the Rectangle.

pt2 - Vertex of the Rectangle Opposite to pt1

rec - Alternative Specification of the Drawn Rectangle.

color - Rectangle color or Brightness (Grayscale image).

Thickness - Thickness of Lines that make up the Rectangle. Negative values, like CV_FILLED , Mean that the Function has to draw a filled Rectangle.

lineType - Type of the line. See the line() Description.

shift - Number of fractional bits in the point coordinates.

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.