Move the sources to trunk
[opencv] / tests / python / highgui / cvRetrieveFrame.py
1 #! /usr/bin/env python
2 """
3 This script will test highgui's cvRetrieveFrame function
4 """
5
6 # name of this test and it's requirements
7 TESTNAME = "cvRetrieveFrame"
8 REQUIRED = ["cvGrabFrame"]
9
10  
11 # needed for sys.exit(int) and .works file handling
12 import os
13 import sys
14 import works
15
16 # path to imagefiles we need
17 PREFIX=os.environ["top_srcdir"]+"/tests/python/testdata/videos/"
18
19 # check requirements and delete old flag file, if it exists
20 if not works.check_files(REQUIRED,TESTNAME):
21         sys.exit(77)
22
23 # import the necessary things for OpenCV
24 import python
25 from python.highgui import *
26 from python.cv import *
27
28
29 # create a video reader using the tiny video 'uncompressed.avi'
30 video = cvCreateFileCapture(PREFIX+"uncompressed.avi")
31
32 # call cvGrabFrame to grab a frame from video
33 res=cvGrabFrame(video)
34
35 if res==0:
36         print "(ERROR) Couldn't call cvGrabFrame()"
37         sys.exit(1)
38 # call cvRetrieveFrame and check if returned image is valid
39 image = cvRetrieveFrame(video)
40
41 if image is None:
42         # returned image is not a correct IplImage (pointer),
43         # so return an error code
44         sys.exit(1)
45
46
47 # ATTENTION: We do not release the video reader or image.
48 # This is bad manners, but Python and OpenCV don't care...
49         
50 # create flag file for sollowing tests
51 works.set_file(TESTNAME)
52
53 # return 0 ('PASS')
54 sys.exit(0)