Update to 2.0.0 tree from current Fremantle build
[opencv] / tests / swig_python / highgui / cvShowImage.py
1 #! /usr/bin/env python
2 """
3 This script will test highgui's window functionality
4 """
5
6 # name of this test and it's requirements
7 TESTNAME = "cvShowImage"
8 REQUIRED = ["cvLoadImagejpg", "cvNamedWindow"]
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.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/images/")
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
24 # import the necessary things for OpenCV
25 from highgui import *
26 from cv import *
27
28 # defined window name
29 win_name = "testing..."
30
31 # we expect a window to be createable, thanks to 'cvNamedWindow.works'
32 cvNamedWindow(win_name, CV_WINDOW_AUTOSIZE)
33
34 # we expect the image to be loadable, thanks to 'cvLoadImage.works'
35 image = cvLoadImage(PREFIX+"cvShowImage.jpg")
36
37 if image is None:
38         print "(ERROR) Couldn't load image "+PREFIX+"cvShowImage.jpg"
39         sys.exit(1)
40
41 # try to show image in window
42 res = cvShowImage( win_name, image )
43 cvWaitKey(0)
44
45
46 if res == 0:
47         cvReleaseImage(image)
48         cvDestroyWindow(win_name)
49         sys.exit(1)
50         
51 # destroy window
52 cvDestroyWindow(win_name)
53
54 # create flag file for following tests
55 works.set_file(TESTNAME)
56
57 # return 0 ('PASS')
58 sys.exit(0)
59         
60         
61