1

The code

import cv    
capture = cv.CaptureFromFile("a.avi")
while True:
    frame = cv.QueryFrame(capture)
    cv.ShowImage("a',frame)

Shows the same initial frame from the video repeatedly (QueryFrame is not advancing the video and grabbing the next frame). It works fine if the video is captured from a webcam.

Any ideas?

Ben Hamner
  • 4,575
  • 4
  • 30
  • 50

1 Answers1

3

I see the same mistakes over and over again, so this is probably the last time I'll address them. Hopefully people will start using the search box in the future and dig a little deeper.

Call cv.WaitKey() after displaying the frame. If don't have a delay between displaying the frames some problems could happen. I believe this the problem.

Code defensively: if you are calling a function/method that can fail, believe in Murphy, and add the appropriate check to verify it doesn't:

import cv    
capture = cv.CaptureFromFile("a.avi")
if not capture :
    print "Error loading video file"
    # Should exit the application

while True:
    frame = cv.QueryFrame(capture)
    if not frame:
        print "Could not retrieve frame"

    cv.ShowImage("a", frame)
    k = cv.WaitKey(10)
    if k == 27:         
        break    # ESC key was pressed
karlphillip
  • 92,053
  • 36
  • 243
  • 426