how to read frame width of video in cv2 1

how to read frame width of video in cv2

import cv2

vcap = cv2.VideoCapture('video.avi') # 0=camera
 
if vcap.isOpened(): 
    # get vcap property 
    width  = vcap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)   # float `width`
    height = vcap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)  # float `height`
    # or
    width  = vcap.get(3)  # float `width`
    height = vcap.get(4)  # float `height`

    # it gives me 0.0 :/
    fps = vcap.get(cv2.cv.CV_CAP_PROP_FPS)

Here is what the above code is Doing:
1. cv2.VideoCapture(0) creates a VideoCapture object for the default camera.
2. vcap.isOpened() checks if the camera is opened.
3. vcap.get(3) and vcap.get(4) return the width and height of the frame.
4. vcap.get(5) returns the frame rate.

Similar Posts