how to resize frame from video and then retrieve the final size?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping
--
Chapters
00:00 How To Resize Frame From Video And Then Retrieve The Final Size?
00:42 Answer 1 Score 1
01:13 Accepted Answer Score 5
01:51 Thank you
--
Full question
https://stackoverflow.com/questions/5417...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #opencv #video #imageresizing #cv2
#avk47
ACCEPTED ANSWER
Score 5
The read method returns two variables, first is the success variables which is a boolean (True if a frame is captured else False) and the second is the frame. You're likely reading a video with 3 channel frames and the frame is usually a numpy array so you can use the shape attribute.
I would suggest using cv2.resize for resizing.
vs = cv2.VideoCapture(args["video"])
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
_, frame = vs.read()
(w, h, c) = frame.shape
#syntax: cv2.resize(img, (width, height))
img = cv2.resize(frame,(400, h))
print(w, h)
print(img.shape)
>> 480 640
(640, 400, 3) #rows(height), columns(width), channels(BGR)
w and h store the original width and height of your video frame and img.shape has the resized width and height
ANSWER 2
Score 1
I think the frame variable you are passing is not a numpy array, it is a tuple. Hence the error. Check if the video is being read correctly. do a print(type(frame)) and check if it is numpy to verify your image is being read correctly. imutils.resize() is a class using cv2.resize function. This is how it works
vs = cv2.VideoCapture(args["video"])
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
ret, frame = vs.read()
#inside of imutils.resize()
w,h,c=frame.shape
r = 400 / float(w)
dim = (400, int(h * r))
new_frame=cv2.resize(image,dim)