Update to 2.0.0 tree from current Fremantle build
[opencv] / tests / swig_python / highgui / query_test.py
diff --git a/tests/swig_python/highgui/query_test.py b/tests/swig_python/highgui/query_test.py
new file mode 100755 (executable)
index 0000000..f00de80
--- /dev/null
@@ -0,0 +1,44 @@
+"""
+This script will test highgui's cvQueryFrame() function
+for different video formats
+"""
+
+# import the necessary things for OpenCV and comparson routine
+import os
+from highgui import *
+from cv import *
+import match
+
+# 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/"
+
+# testing routine, called for each entry in FILENAMES
+# and compares each frame with corresponding frame in COMPARISON
+def query_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
+
+    # call cvQueryFrame for 29 frames and check if the returned image is ok
+    for k in range(29):
+       image=cvQueryFrame(video)
+
+       if image is None:
+       # returned image is NULL (FAIL)
+               return 1
+
+       if not match.match(image,k,ERRORS[k]):
+               return 1
+       
+    cvReleaseCapture(video)
+    # everything is fine (PASS)
+    return 0