bb94edbee6eee0d15a3428b9f92ad577cce531f7
[opencv] / tests / swig_python / highgui / cvWaitKey.py
1 #! /usr/bin/env python
2 """
3 This script will test highgui's cvWaitKey(int) function
4 """
5
6 # name of this test and it's requirements
7 TESTNAME = "cvWaitKey"
8 REQUIRED = ["cvShowImage"]
9
10 # needed for sys.exit(int) and .works file handling
11 import os
12 import sys
13 import works
14
15 # path to imagefiles we need
16 PREFIX=os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/images/")
17
18 # check requirements and delete old flag file, if it exists
19 if not works.check_files(REQUIRED, TESTNAME):
20         sys.exit(77)
21
22
23 # import the necessary things for OpenCV
24 from highgui import *
25
26 # request some user input
27 print "(INFO) Press anykey within the next 20 seconds to 'PASS' this test." 
28
29 # create a dummy window which reacts on cvWaitKey()
30 cvNamedWindow(TESTNAME, CV_WINDOW_AUTOSIZE)
31
32 # display an image
33 cvShowImage(TESTNAME, cvLoadImage(PREFIX+"cvWaitKey.jpg"))
34
35 # wait 20 seconds using cvWaitKey(20000),
36 # return 'FAIL' if no key has been pressed.
37 if cvWaitKey(20000) == -1:
38         print "(ERROR) No key pressed, remarking as 'FAIL'."
39         sys.exit(1)
40
41 #create flag file for the following tests
42 works.set_file(TESTNAME)
43
44 # return 0 ('PASS')
45 sys.exit(0)