OpenCV 3 Computer Vision with Python Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Execute the following steps:

  1. Let's create an auxiliary function that will take the VideoCapture ID (either what the camera device is or the path to the video), create a VideoCapture object, and request the frame height and width, count, and rate:
import numpy
import cv2

def print_capture_properties(*args):
capture = cv2.VideoCapture(*args)
print('Created capture:', ' '.join(map(str, args)))
print('Frame count:', int(capture.get(cv2.CAP_PROP_FRAME_COUNT)))
print('Frame width:', int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)))
print('Frame height:', int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print('Frame rate:', capture.get(cv2.CAP_PROP_FPS))
  1. Let's call this function for a video file:
print_capture_properties('../data/drop.avi')
  1. Now let's request properties for the camera capture object:
print_capture_properties(0)