Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Created August 14, 2012 07:07
Show Gist options
  • Save jayrambhia/3347099 to your computer and use it in GitHub Desktop.
Save jayrambhia/3347099 to your computer and use it in GitHub Desktop.
Utilities for capture in OpenCV
import cv2
import cv2.cv as cv
"""
Got the idea from http://newpathprep.wordpress.com/2012/08/13/opencv-forward-and-rewind-avi/
He has done it in C++.
"""
def start(capture, n):
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, n-1)
def rewind(capture):
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, 0)
def getFrame(capture, frame):
number_frame = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES))
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, frame-1)
img = cv.QueryFrame(capture)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, number_frame)
return img
def skipFrames(capture, n):
number_frame = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES))
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, number_frame + n - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment