Python OpenCV - Error while using drawing function

0

I've been able to run this code before, but now it does not work. He 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 executed code:

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

    
asked by anonymous 20.06.2016 / 18:44

1 answer

0

The call of the cv2.rectangle() function 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 have helped.

    
22.07.2016 / 22:20