Update to 2.0.0 tree from current Fremantle build
[opencv] / tests / swig_python / highgui / cvSaveImage.py
1 #! /usr/bin/env python
2 """
3 This script will test highgui's image saving functionality
4 """
5
6 # name if this test and it's requirements
7 TESTNAME = "cvSaveImage"
8 REQUIRED = ["cvLoadImagejpg"]
9
10 #needed for sys.exit(int), filehandling and .works file checks
11 import os
12 import sys
13 import works
14
15 # path to imagefiles we need
16 PREFIX=os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/images/")
17
18 # delete old .works file and check requirements
19 if not works.check_files(REQUIRED,TESTNAME):
20         sys.exit(77)
21
22 # import the necessary things for OpenCV
23 from highgui import *
24 from cv import *
25
26 # our temporary test file
27 file_name = "./highgui_testfile.bmp"
28
29 # try to load an image from a file
30 image = cvLoadImage(PREFIX+"baboon.jpg")
31
32 # if the returned object is not Null, loading was successful.
33 if image==0:
34         print "(INFO) Couldn't load test image. Skipping rest of this test."
35         sys.exit(77)
36
37 res = cvSaveImage("./highgui_testfile.bmp", image)
38
39 if res == 0:
40         print "(ERROR) Couldn't save image to '"+file_name+"'."
41         sys.exit(1)
42
43 # remove temporary file
44 os.remove(file_name)
45
46 # create flag file
47 works.set_file(TESTNAME)
48
49 # return 0 ('PASS')
50 sys.exit(0)