2 This script will test highgui's seek functionality
3 for different video formats
6 # import the necessary things for OpenCV and comparson routine
9 from python.highgui import *
10 from python.cv import *
14 # path to videos and images we need
15 PREFIX=os.environ["top_srcdir"]+"/tests/python/testdata/"
17 # this is the folder with the videos and images
18 # and name of output window
19 IMAGES = PREFIX+"images/"
20 VIDEOS = PREFIX+"videos/"
26 # testing routine, seeks through file and compares read images with frames in frames.QCIF[]
27 def seek_frame_ok(FILENAME,ERRORS):
28 # create a video reader using the tiny videofile VIDEOS+FILENAME
29 video=cvCreateFileCapture(VIDEOS+FILENAME)
32 # couldn't open video (FAIL)
36 cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
38 # skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
39 for k in [0,3,6,9,12,15,18,21,24,27]:
40 cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
43 image=cvQueryFrame(video)
46 # returned image is NULL (FAIL)
49 compresult = match.match(image,k,ERRORS[k])
54 cvShowImage("test",image)
57 # same as above, just backwards...
58 for k in [27,24,21,18,15,12,9,6,3,0]:
60 cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
63 image=cvQueryFrame(video)
66 # returned image is NULL (FAIL)
69 compresult = match.match(image,k,ERRORS[k])
74 cvShowImage("test",image)
77 # ATTENTION: We do not release the video reader, window or any image.
78 # This is bad manners, but Python and OpenCV don't care,
79 # the whole memory segment will be freed on finish anyway...
82 # everything is fine (PASS)
86 # testing routine, seeks through file and compares read images with frames in frames.QCIF[]
87 def seek_time_ok(FILENAME,ERRORS):
89 # create a video reader using the tiny videofile VIDEOS+FILENAME
90 video=cvCreateFileCapture(VIDEOS+FILENAME)
93 # couldn't open video (FAIL)
97 cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
99 # skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
100 for k in [0,3,6,9,12,15,18,21,24,27]:
102 cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
105 image=cvQueryFrame(video)
108 # returned image is NULL (FAIL)
111 compresult = match.match(image,k,ERRORS[k])
116 cvShowImage("test",image)
119 # same as above, just backwards...
120 for k in [27,24,21,18,15,12,9,6,3,0]:
122 cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
125 image=cvQueryFrame(video)
128 # returned image is NULL (FAIL)
131 compresult = match.match(image,k,ERRORS[k])
136 cvShowImage("test",image)
139 # ATTENTION: We do not release the video reader, window or any image.
140 # This is bad manners, but Python and OpenCV don't care,
141 # the whole memory segment will be freed on finish anyway...
144 # everything is fine (PASS)