Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv2.rectangle TypeError: function takes exactly 4 arguments (2 given) #17940

Closed
2 tasks done
augustopozzebon opened this issue Jul 24, 2020 · 2 comments
Closed
2 tasks done
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@augustopozzebon
Copy link

  • OpenCV => 4.3.0
  • Operating System / Platform => Windows 64 Bit
  • Compiler => PyCharm
Detailed description

Traceback (most recent call last):
File "PycharmProjects/OpenCV/retangulo_moving.py", line 27, in
frame = cv2.rectangle(frame, (x1, y1), (x1+bw, y1+bh), (0,0,0), -1)
TypeError: function takes exactly 4 arguments (2 given)
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (436) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Steps to reproduce

The error is in the rectangle function. I'm trying to display a moving rectangle in a live video from the WebCam.
When using opencv version 4.0.1 I got the error "an integer is required (got type tuple)". After the update too the 4.3.0 version this new error showed up.

import numpy as np
print(cv2.__version__)


dispW=640
dispH=480
cam=cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FPS, 21)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, dispW)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, dispH)


bw=(.15*dispW)
bh=(.15*dispH)
dx=2
dy=2
x1=10
y1=270


while True:

        ret, frame=cam.read()


        frame = cv2.rectangle(frame, (x1, y1), (x1+bw, y1+bh), (0,0,0), -1)

        cv2.moveWindow('WebCam', 0, 0)
        cv2.imshow('WebCam', frame2)
        x1+=dx
        y1+=dy
        if x1<=0 or x1+bw>=dispW:
            dx=dx*(-1)
        if y1<=0 or y1+bh>=dispH:
            dy=dy*(-1)




        if cv2.waitKey(1)==ord('q'):
            break


cam.release()
cv2.destroyAllWindows()
Issue submission checklist
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
@augustopozzebon augustopozzebon changed the title cv2.rectangle TypeError: an integer is required (got type tuple). cv2.rectangle TypeError: function takes exactly 4 arguments (2 given) Jul 24, 2020
@berak
Copy link
Contributor

berak commented Jul 25, 2020

related: #16432

@algonao, the point coords need to be integer, make it:

bw=int(.15*dispW)
bh=int(.15*dispH)

@augustopozzebon
Copy link
Author

Yeah!!! That was it! Thank you berak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

No branches or pull requests

3 participants