Example 2

From Devipedia

Jump to: navigation, search

<websiteFrame> website=http://www.youtube.com/embed/rz8RSUZNo9A height=349 width=425 border=0 scroll=auto </websiteFrame>


I was slightly more impressed when I ran this example. I fed it a random avi from my disk and it played to the end flawlessly. After showing each frame, cvWaitKey(33) causes the program to wait for a keypress for 33 ms. If the keypress is the ESC key, the program exits. In the real world, never use constant integers in your code like this or I will slap you.



from opencv.highgui import *
from opencv.cv import *


if __name__ == '__main__':

    cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE)
    capture = cvCreateFileCapture(sys.argv[1])
   
    while True:
        frame = cvQueryFrame( capture )
        if frame == None:
            break

        cvShowImage("Example2", frame)
        c = cvWaitKey(33)
        if c == chr(27):
            break        

    cvReleaseCapture(capture)
    cvDestroyWindow("Example2")
Personal tools