I want to query frames from the the middle of a video, beginning from some starting frame. Following OpenCV Seek Function/Rewind, I use CV_CAP_PROP_POS_FRAMES
.
To verify that it works as I expect, I seek to Frame 10 and print a slice from the image. Then I seek to Frame 10 again and print the same slice.
In [1]: import cv
In [2]: capture = cv.CaptureFromFile('T35V1.MOV')
In [3]: cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, 10)
Out[3]: 1
In [4]: np.asarray(cv.GetMat(cv.QueryFrame(capture)))[100] # an arbitrary slice
Out[4]:
array([[ 36, 104, 120],
[ 36, 104, 120],
[ 36, 107, 123],
...,
[ 50, 114, 136],
[ 54, 115, 136],
[ 55, 116, 137]], dtype=uint8)
In [5]: cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_POS_FRAMES, 10)
Out[5]: 1
In [6]: np.asarray(cv.GetMat(cv.QueryFrame(capture)))[100]
Out[6]:
array([[ 32, 107, 119],
[ 32, 107, 119],
[ 35, 109, 124],
...,
[ 42, 114, 135],
[ 47, 118, 139],
[ 50, 121, 142]], dtype=uint8)
The data do not agree. Am I misusing this?
Related: http://code.opencv.org/issues/481
This user of OpenCV in C++ finds that setting and getting the property twice works around this problem. For me, in whether I use cv
or cv2
, the problem persists.