Update to 2.0.0 tree from current Fremantle build
[opencv] / interfaces / swig / python / pyhelpers.h
1 #ifndef PYHELPERS_H
2 #define PYHELPERS_H
3
4 #include <Python.h>
5 #include <cxcore.h>
6 #include <cv.h>
7
8 /** convert python index object (tuple, integer, or slice) to CvRect for subsequent cvGetSubMat call */
9 CvRect PySlice_to_CvRect(CvArr * src, PyObject * idx_object);
10
11 /** 1 if rectangle is a subrectangle of [0,0,w,h], 0 otherwise */
12 int CheckSliceBounds(CvRect * rect, int w, int h );
13
14 /// convert object that supports the array protocol to CvMat *
15 CvArr * PyArray_to_CvArr (PyObject * obj);
16
17 /// convert nested sequences to CvMat *
18 CvArr * PySequence_to_CvArr (PyObject * obj);
19
20 /** prints array to stdout 
21  *  TODO: python __str__ and __repr__ return strings, so this should write to a string 
22  */
23 void cvArrPrint (CvArr * mat);
24
25 /** Convert an integer array to python tuple */
26 PyObject * PyTuple_FromIntArray(int * arr, int len);
27         
28 /** If result is not NULL or PyNone, release object and replace it with obj */
29 PyObject * SWIG_SetResult(PyObject * result, PyObject * obj);
30         
31 /** helper function to append one or more objects to the swig $result array */
32 PyObject * SWIG_AppendResult(PyObject * result, PyObject ** to_add, int num);
33
34 /** helper function to convert python scalar or sequence to int, float or double arrays */
35 double PyObject_AsDouble(PyObject * obj);
36 long PyObject_AsLong(PyObject * obj);
37
38 int PyObject_AsDoubleArray(PyObject * obj, double * array, int len);
39 int PyObject_AsLongArray(  PyObject * obj, int * array, int len);
40 int PyObject_AsFloatArray(PyObject * obj, float * array, int len);
41
42 static inline int cvCvToIplDepth(int type) { return cvIplDepth(type); }
43
44 #endif //PYHELPERS_H