7a0363a01bd6beeac8c8fe59783fc6b61620fd5b
[opencv] / tests / python / highgui / cvLoadImage.py
1 """
2 This script will test highgui's image loading functionality
3 for a given parameter of a file extension.
4 """
5
6
7 # needed for sys.exit(int) and .works file handling
8 import os
9 import sys
10 import works
11 from works import *
12
13 #import the necessary things for OpenCV
14 import python
15 from python.highgui import *
16 from python.cv import *
17
18
19 # some defines
20 TESTNAME = "cvLoadImage"
21 REQUIRED = []
22
23 # path to imagefiles we need
24 PREFIX=os.environ["top_srcdir"]+"/tests/python/testdata/images/baboon_256x256"
25
26
27 # this functions tries to open an imagefile
28 # using the filename PREFIX.EXTENSION  and returns True/False 
29 # on success/fail.
30
31 def image_ok( EXTENSION ):
32         
33         # check requirements and delete old .works file
34         WORKSNAME = TESTNAME+'.'+EXTENSION
35
36         if not works.check_files( REQUIRED, WORKSNAME ):
37                 print "worksfile "+WORKSNAME+" not found."
38                 return False
39         
40         image = cvLoadImage(PREFIX+'.'+EXTENSION)
41
42         if image is None:
43                 return False
44         else:
45                 works.set_file( TESTNAME+EXTENSION )
46                 return True