Ask Your Question
1

After setting capture property, reading the property returns 0.0

asked 2012-07-31 12:50:49 -0500

Cpp gravatar image

Helpful openCVers-

If I set the capture property like this:

cv.SetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES,40)

then read it like this:

cv.GetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES)

I get 0.0, not 40. The next time I query it, the frame is 37 or 49!

Here is my test script:

#testify.py  import cv

VideoName= "target.avi"  TempName= "temp.tiff"  Capture= cv.CaptureFromFile(VideoName)
MaxFrames= cv.GetCaptureProperty(Capture,cv.CV_CAP_PROP_FRAME_COUNT)

for x in range(10):
    print cv.GetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES)
    CurrentFrame = cv.QueryFrame(Capture)

cv.SetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES,40)

for x in range(10):     
    print cv.GetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES)  
    CurrentFrame = cv.QueryFrame(Capture)

cv.SetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES,40)

for x in range(10):
     print cv.GetCaptureProperty(Capture,cv.CV_CAP_PROP_POS_FRAMES)
     CurrentFrame = cv.QueryFrame(Capture)

my output is:

0.0
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
0.0
49.0
50.0
51.0
52.0
53.0
54.0
55.0
56.0
57.0
0.0
37.0
38.0
39.0
40.0
41.0
42.0
43.0
44.0
45.0

So my question is: why is the first frame always 0.0? and after setting the frame to 40, why does it jump to 49 and 37?

Thanks!

--Cpp

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-07-31 13:06:21 -0500

sammy gravatar image

I think here is a good explanation of what happens inside OpenCV. The first comments illustrate the inner works of video decoding, and why such behaviour occurs

Problem with CV_CAP_PROP_POS_FRAMES setting next frame number

edit flag offensive delete link more

Comments

Thanks! That was really helpful.

Cpp gravatar imageCpp ( 2012-07-31 13:39:00 -0500 )edit
1

Welcome. Don't forget to upvote/accept if you consider it's worth. It will help others users to find best info.

sammy gravatar imagesammy ( 2012-07-31 13:51:59 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-07-31 12:50:49 -0500

Seen: 1,492 times

Last updated: Jul 31 '12