1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
"""
This script will test highgui's seek functionality
for different video formats
"""
# import the necessary things for OpenCV and comparson routine
import os
#import python
#from python.highgui import *
#from python.cv import *
import match
from highgui import *
from cv import *
# path to videos and images we need
PREFIX=os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/")
# this is the folder with the videos and images
# and name of output window
IMAGES = PREFIX+"images/"
VIDEOS = PREFIX+"videos/"
show_frames=False
# testing routine, seeks through file and compares read images with frames in frames.QCIF[]
def seek_frame_ok(FILENAME,ERRORS):
# create a video reader using the tiny videofile VIDEOS+FILENAME
video=cvCreateFileCapture(VIDEOS+FILENAME)
if video is None:
# couldn't open video (FAIL)
return 1
if show_frames:
cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
# skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
for k in [0,3,6,9,12,15,18,21,24,27]:
cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
# try to query frame
image=cvQueryFrame(video)
if image is None:
# returned image is NULL (FAIL)
return 1
compresult = match.match(image,k,ERRORS[k])
if not compresult:
return 1
if show_frames:
cvShowImage("test",image)
cvWaitKey(200)
# same as above, just backwards...
for k in [27,24,21,18,15,12,9,6,3,0]:
cvSetCaptureProperty(video, CV_CAP_PROP_POS_FRAMES, k)
# try to query frame
image=cvQueryFrame(video)
if image is None:
# returned image is NULL (FAIL)
return 1
compresult = match.match(image,k,ERRORS[k])
if not compresult:
return 1
if show_frames:
cvShowImage("test",image)
cvWaitKey(200)
# ATTENTION: We do not release the video reader, window or any image.
# This is bad manners, but Python and OpenCV don't care,
# the whole memory segment will be freed on finish anyway...
del video
# everything is fine (PASS)
return 0
# testing routine, seeks through file and compares read images with frames in frames.QCIF[]
def seek_time_ok(FILENAME,ERRORS):
# create a video reader using the tiny videofile VIDEOS+FILENAME
video=cvCreateFileCapture(VIDEOS+FILENAME)
if video is None:
# couldn't open video (FAIL)
return 1
if show_frames:
cvNamedWindow("test", CV_WINDOW_AUTOSIZE)
# skip 2 frames and read 3rd frame each until EOF and check if the read image is ok
for k in [0,3,6,9,12,15,18,21,24,27]:
cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
# try to query frame
image=cvQueryFrame(video)
if image is None:
# returned image is NULL (FAIL)
return 1
compresult = match.match(image,k,ERRORS[k])
if not compresult:
return 1
if show_frames:
cvShowImage("test",image)
cvWaitKey(200)
# same as above, just backwards...
for k in [27,24,21,18,15,12,9,6,3,0]:
cvSetCaptureProperty(video, CV_CAP_PROP_POS_MSEC, k*40)
# try to query frame
image=cvQueryFrame(video)
if image is None:
# returned image is NULL (FAIL)
return 1
compresult = match.match(image,k,ERRORS[k])
if not compresult:
return 1
if show_frames:
cvShowImage("test",image)
cvWaitKey(200)
# ATTENTION: We do not release the video reader, window or any image.
# This is bad manners, but Python and OpenCV don't care,
# the whole memory segment will be freed on finish anyway...
del video
# everything is fine (PASS)
return 0
|