Update the changelog
[opencv] / tests / python / highgui / cvCreateTrackbar.py
1 #! /usr/bin/env python
2 """
3 This script will test highgui's trackbar functionality
4 """
5
6 # name if this test and it's requirements
7 TESTNAME = "cvCreateTrackbar"
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 # check requirements and delete old flag file, if it exists
16 if not works.check_files(REQUIRED,TESTNAME):
17         sys.exit(77)
18
19 # import the necessary things for OpenCV
20 import python
21 from python.highgui import *
22 from python.cv      import *
23
24 # some definitions
25 win_name = "testing..."
26 bar_name = "brightness"
27 bar_count= 100
28
29
30 # position of imagefiles we need
31 PREFIX=os.environ["top_srcdir"]+"/tests/python/testdata/images/"
32
33 # 'moved' indicates if trackbar has been moved
34 moved = False
35
36 # 'range' indicates if trackbar was outside range [0..bar_count]
37 range = False
38
39
40 # function to call on a trackbar event
41 def trackcall( p ):
42         # Trackbar position must be in [0..bar_count]
43         if (p > bar_count or p < 0):
44                 globals()["range"] = True
45
46         cvConvertScale( image, image2,float(p)/float(bar_count) )
47         cvShowImage( win_name, image2 );
48         globals()["moved"] = True
49
50
51 # create output window
52 cvNamedWindow(win_name,CV_WINDOW_AUTOSIZE)
53 image  = cvLoadImage(PREFIX+"cvCreateTrackbar.jpg")
54 image2 = cvLoadImage(PREFIX+"cvCreateTrackbar.jpg")
55 cvShowImage(win_name,image)
56
57 # create the trackbar and save return value
58 res = cvCreateTrackbar( bar_name, win_name, 0, bar_count, trackcall )
59
60 # check return value
61 if res == 0:
62         # something went wrong, so return an error code
63         print "(ERROR) Couldn't create trackbar."
64         sys.exit(1)
65         
66 # init. window with image
67 trackcall(bar_count/2)
68 # reset 'moved' indicator
69 moved = False
70
71 # now give the user 20 seconds to do some input
72 print "(INFO) Please move trackbar within the next 20 SECONDS to 'PASS' this test."
73 print "(HINT) You can complete this test prematurely by pressing any key."
74 print "(INFO) In the case of no user input, the test will be remarked as 'FAIL'."
75
76 key = cvWaitKey(20000)
77
78 if range:
79         # trackbar position value was outside allowed range [0..bar_count]
80         print "(ERROR) Trackbar position was outside range."
81         sys.exit(1)
82
83 if not moved and (key==-1):
84         # trackbar has not been moved
85         print "(ERROR) No user input detected."
86         sys.exit(1)
87 elif not moved and (key>0):
88         # 20sec. passed, trackbar has been moved
89         print "(INFO) No trackbar movement detected (but key pressed)."
90         sys.exit(77)
91
92 # create flag file for following tests
93 works.set_file(TESTNAME)
94
95 # return 0 ('PASS')
96 sys.exit(0)