de1a210495e16a635a67f716f4a8af2449d28f49
[opencv] / tests / swig_python / highgui / size_test.py
1 """
2 This script will test HighGUI's cvGetCaptureProperty functionality
3 for correct returnvalues of width and height information for different video formats
4 """
5
6 # import the necessary things for OpenCV and comparson routine
7 import os
8 from cv import *
9 from highgui import *
10 #import python
11 #from python.highgui import *
12
13
14 # path to images and videos  we need
15 PREFIX          =os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/")
16
17
18 # this is the folder with the videos and images
19 # and name of output window
20 IMAGES          = PREFIX+"images/"
21 VIDEOS          = PREFIX+"videos/"
22
23
24 # testing routine, seeks through file and compares read images with frames in COMPARISON
25 def size_ok(FILENAME):
26   # create a video reader using the tiny videofile VIDEOS+FILENAME
27   video=cvCreateFileCapture(VIDEOS+FILENAME)
28
29   if video is None:
30     # couldn't open video (FAIL)
31     return 1
32
33   # get width and height information via HighGUI's cvGetCaptureProperty function
34   w=cvGetCaptureProperty(video,CV_CAP_PROP_FRAME_WIDTH)
35   h=cvGetCaptureProperty(video,CV_CAP_PROP_FRAME_HEIGHT)
36
37   # get an image to compare
38   image=cvQueryFrame(video)
39   
40   if image is None:
41     return 1
42   
43   image = cvCloneImage (image)
44   
45   if (w!=image.width) or (h!=image.height):
46     # dimensions don't match parameters (FAIL)
47     return 1
48
49   del video
50   del image
51   # everything is fine (PASS)
52   return 0
53
54