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 *
15 # path to videos and images we need
16 PREFIX=os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/")
18 # this is the folder with the videos and images
19 # and name of output window
20 IMAGES = PREFIX+"images/"
21 VIDEOS = PREFIX+"videos/"
27 # testing routine, seeks through file and compares read images with frames in frames.QCIF[]
28 def seek_frame_ok(FILENAME,ERRORS):
29 # create a video reader using the tiny videofile VIDEOS+FILENAME
30 video=cvCreateFileCapture(VIDEOS+FILENAME)
33 # couldn't open video (FAIL)
37 cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
39 # skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
40 for k in [0,3,6,9,12,15,18,21,24,27]:
41 cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
44 image=cvQueryFrame(video)
47 # returned image is NULL (FAIL)
50 compresult = match.match(image,k,ERRORS[k])
55 cvShowImage("test",image)
58 # same as above, just backwards...
59 for k in [27,24,21,18,15,12,9,6,3,0]:
61 cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
64 image=cvQueryFrame(video)
67 # returned image is NULL (FAIL)
70 compresult = match.match(image,k,ERRORS[k])
75 cvShowImage("test",image)
78 # ATTENTION: We do not release the video reader, window or any image.
79 # This is bad manners, but Python and OpenCV don't care,
80 # the whole memory segment will be freed on finish anyway...
83 # everything is fine (PASS)
87 # testing routine, seeks through file and compares read images with frames in frames.QCIF[]
88 def seek_time_ok(FILENAME,ERRORS):
90 # create a video reader using the tiny videofile VIDEOS+FILENAME
91 video=cvCreateFileCapture(VIDEOS+FILENAME)
94 # couldn't open video (FAIL)
98 cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
100 # skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
101 for k in [0,3,6,9,12,15,18,21,24,27]:
103 cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
106 image=cvQueryFrame(video)
109 # returned image is NULL (FAIL)
112 compresult = match.match(image,k,ERRORS[k])
117 cvShowImage("test",image)
120 # same as above, just backwards...
121 for k in [27,24,21,18,15,12,9,6,3,0]:
123 cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
126 image=cvQueryFrame(video)
129 # returned image is NULL (FAIL)
132 compresult = match.match(image,k,ERRORS[k])
137 cvShowImage("test",image)
140 # ATTENTION: We do not release the video reader, window or any image.
141 # This is bad manners, but Python and OpenCV don't care,
142 # the whole memory segment will be freed on finish anyway...
145 # everything is fine (PASS)