3 This script will test highgui's trackbar functionality
6 # name if this test and it's requirements
7 TESTNAME = "cvCreateTrackbar"
8 REQUIRED = ["cvShowImage"]
10 # needed for sys.exit(int) and .works file handling
15 # check requirements and delete old flag file, if it exists
16 if not works.check_files(REQUIRED,TESTNAME):
19 # import the necessary things for OpenCV
21 from python.highgui import *
22 from python.cv import *
25 win_name = "testing..."
26 bar_name = "brightness"
30 # position of imagefiles we need
31 PREFIX=os.environ["top_srcdir"]+"/tests/python/testdata/images/"
33 # 'moved' indicates if trackbar has been moved
36 # 'range' indicates if trackbar was outside range [0..bar_count]
40 # function to call on a trackbar event
42 # Trackbar position must be in [0..bar_count]
43 if (p > bar_count or p < 0):
44 globals()["range"] = True
46 cvConvertScale( image, image2,float(p)/float(bar_count) )
47 cvShowImage( win_name, image2 );
48 globals()["moved"] = True
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)
57 # create the trackbar and save return value
58 res = cvCreateTrackbar( bar_name, win_name, 0, bar_count, trackcall )
62 # something went wrong, so return an error code
63 print "(ERROR) Couldn't create trackbar."
66 # init. window with image
67 trackcall(bar_count/2)
68 # reset 'moved' indicator
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'."
76 key = cvWaitKey(20000)
79 # trackbar position value was outside allowed range [0..bar_count]
80 print "(ERROR) Trackbar position was outside range."
83 if not moved and (key==-1):
84 # trackbar has not been moved
85 print "(ERROR) No user input detected."
87 elif not moved and (key>0):
88 # 20sec. passed, trackbar has been moved
89 print "(INFO) No trackbar movement detected (but key pressed)."
92 # create flag file for following tests
93 works.set_file(TESTNAME)