3 # This module is meant to aid writing and running Python-based tests
4 # within the OpenCV tree.
6 # 2009-01-23, Roman Stanchak <rstanchak@gmail.com>
9 # Upon importing, this module adds the following python module
10 # directories from the dev tree to sys.path (i.e. PYTHON_PATH):
11 # opencv/interfaces/swig/python and opencv/lib
13 # Using it in a test case is simple, just be sure to import
14 # cvtestutils before cv, highgui, etc
26 Return a string containing the top-level source directory in the OpenCV tree
28 dir = os.path.dirname(os.path.realpath(__file__))
30 # top level dir should be two levels up from this file
31 return os.path.realpath( os.path.join( dir, '..', '..' ) )
35 Return a string containing the top-level build directory in the OpenCV tree.
36 Either returns realpath(argv[1]) or top_srcdir();
38 if len(sys.argv)>1: return os.path.realpath( sys.argv[1] );
39 else: return top_srcdir();
43 Prepend the python module directories from the dev tree to sys.path
47 # add path for OpenCV source directory (for adapters.py)
48 moduledir = os.path.join(top_srcdir(), 'interfaces','swig','python')
49 moduledir = os.path.realpath(moduledir)
50 sys.path.insert(0, moduledir)
52 # add path for OpenCV build directory
53 moduledir = os.path.join(top_builddir(), 'interfaces','swig','python')
54 moduledir = os.path.realpath(moduledir)
55 sys.path.insert(0, moduledir)
57 libdir = os.path.join(top_builddir(), 'lib' )
58 libdir = os.path.realpath(libdir)
59 sys.path.insert(0, libdir)
63 Print the directory containing cv.py
66 print "Using OpenCV Python in: " + os.path.dirname(cv.__file__)
70 Return a string containing the full path to the python testdata directory
72 return os.path.sep.join([top_srcdir(), '..', 'opencv_extra', 'testdata', 'python'])
74 ### Module Initialization