Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.VideoWriter: Asks for a tuple as Size argument, then rejects it

I'm using OpenCV 4.0 and Python 3.7 to create a timelapse video.

When constructing a VideoWriter object, the documentation says the Size argument should be a tuple.

When I give it a tuple it rejects it. When I try to replace it with something else, it won't accept it because it says the argument isn't a tuple.

When Size not a tuple:

out = cv2.VideoWriter('project.avi', 1482049860, 30, height, width)
SystemError: new style getargs format but argument is not a tuple

When I changed Size to a tuple:

out = cv2.VideoWriter('project.avi', 1482049860, 30, (height, width))
TypeError: must be real number, not tuple

I just want to create a simple cv2.VideoWriter object.

like image 609
Travis Williams Avatar asked Feb 04 '23 18:02

Travis Williams


1 Answers

I was trying to take the height and width from an uploaded video using:

width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

I changed it to:

width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

Now I don't get that error. It doesn't work yet as a whole, but that particular error isn't there anymore.

like image 144
Travis Williams Avatar answered Feb 06 '23 08:02

Travis Williams