Move the sources to trunk
[opencv] / tests / 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.environ["top_srcdir"]+"/tests/python/testdata/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 import python
24 from python.highgui import *
25 from python.cv import *
26
27 # our temporary test file
28 file_name = "./highgui_testfile.bmp"
29
30 # try to load an image from a file
31 image = cvLoadImage(PREFIX+"baboon.jpg")
32
33 # if the returned object is not Null, loading was successful.
34 if image==0:
35         print "(INFO) Couldn't load test image. Skipping rest of this test."
36         sys.exit(77)
37
38 res = cvSaveImage("./highgui_testfile.bmp", image)
39
40 if res == 0:
41         print "(ERROR) Couldn't save image to '"+file_name+"'."
42         sys.exit(1)
43
44 # remove temporary file
45 os.remove(file_name)
46
47 # create flag file
48 works.set_file(TESTNAME)
49
50 # return 0 ('PASS')
51 sys.exit(0)