1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
41 %include "exception.i"
42 %include "./pyhelpers.i"
44 %typemap(in) (CvArr *) (bool freearg=false){
45 $1 = PyObject_to_CvArr($input, &freearg);
47 %typemap(freearg) (CvArr *) {
48 if($1!=NULL && freearg$argnum){
53 %typecheck(SWIG_TYPECHECK_POINTER) CvArr * {
55 if(PyList_Check($input) || PyTuple_Check($input)) {
58 else if (SWIG_ConvertPtr($input, &ptr, 0, 0) == -1) {
67 // for cvReshape, cvGetRow, where header is passed, then filled in
68 %typemap(in, numinputs=0) CvMat * OUTPUT (CvMat * header) {
69 header = (CvMat *)cvAlloc(sizeof(CvMat));
77 %newobject cvGetSubRect;
80 %apply CvMat *OUTPUT {CvMat * header};
81 %apply CvMat *OUTPUT {CvMat * submat};
84 * In C, these functions assume input will always be around at least as long as header,
85 * presumably because the most common usage is to pass in a reference to a stack object.
88 * cvGetRow(A, &row, 0);
90 * As a result, the header is not refcounted (see the C source for cvGetRow, Reshape, in cxarray.cpp)
91 * However, in python, the header parameter is implicitly created so it is easier to create
92 * situations where the sub-array outlives the original header. A simple example is:
93 * A = cvReshape(A, -1, A.rows*A.cols)
95 * since python doesn't have an assignment operator, the new header simply replaces the original,
96 * the refcount of the original goes to zero, and cvReleaseMat is called on the original, freeing both
97 * the header and data. The new header is left pointing to invalid data. To avoid this, need to add
98 * refcount field to the returned header.
100 %typemap(argout) (const CvArr* arr, CvMat* header) {
101 $2->hdr_refcount = ((CvMat *)$1)->hdr_refcount;
102 $2->refcount = ((CvMat *)$1)->refcount;
105 %typemap(argout) (const CvArr* arr, CvMat* submat) {
106 $2->hdr_refcount = ((CvMat *)$1)->hdr_refcount;
107 $2->refcount = ((CvMat *)$1)->refcount;
111 /* map scalar or sequence to CvScalar, CvPoint2D32f, CvPoint */
112 %typemap(in) (CvScalar) {
113 $1 = PyObject_to_CvScalar( $input );
115 %typemap(in) (CvPoint) {
116 $1 = PyObject_to_CvPoint($input);
118 %typemap(in) (CvPoint2D32f) {
119 $1 = PyObject_to_CvPoint2D32f($input);
123 /* typemap for cvGetDims */
124 %typemap(in) (const CvArr * arr, int * sizes = NULL) (void * myarr, int mysizes[CV_MAX_DIM]){
125 SWIG_Python_ConvertPtr($input, &myarr, 0, SWIG_POINTER_EXCEPTION);
130 %typemap(argout) (const CvArr * arr, int * sizes = NULL) {
131 int len = PyInt_AsLong( $result );
132 PyObject * obj = PyTuple_FromIntArray( $2, len );
133 Py_DECREF( $result );
137 /* map one list of integer to the two parameters dimension/sizes */
138 %typemap(in) (int dims, int* sizes) {
141 /* get the size of the dimention array */
142 $1 = PyList_Size ($input);
144 /* allocate the needed memory */
145 $2 = (int *)malloc ($1 * sizeof (int));
147 /* extract all the integer values from the list */
148 for (i = 0; i < $1; i++) {
149 PyObject *item = PyList_GetItem ($input, i);
150 $2 [i] = (int)PyInt_AsLong (item);
154 /* map one list of integer to the parameter idx of
155 cvGetND, cvSetND, cvClearND, cvGetRealND, cvSetRealND and cvClearRealND */
156 %typemap(in) (int* idx) {
160 /* get the size of the dimention array */
161 size = PyList_Size ($input);
163 /* allocate the needed memory */
164 $1 = (int *)malloc (size * sizeof (int));
166 /* extract all the integer values from the list */
167 for (i = 0; i < size; i++) {
168 PyObject *item = PyList_GetItem ($input, i);
169 $1 [i] = (int)PyInt_AsLong (item);
173 /* map a list of list of float to an matrix of floats*/
174 %typemap(in) float** ranges {
180 /* get the number of lines of the matrix */
181 size1 = PyList_Size ($input);
183 /* allocate the correct number of lines for the destination matrix */
184 $1 = (float **)malloc (size1 * sizeof (float *));
186 for (i1 = 0; i1 < size1; i1++) {
188 /* extract all the lines of the matrix */
189 PyObject *list = PyList_GetItem ($input, i1);
192 /* size 2 wasn't computed before */
193 size2 = PyList_Size (list);
194 } else if (size2 != PyList_Size (list)) {
195 /* the current line as a different size than the previous one */
196 /* so, generate an exception */
197 SWIG_exception (SWIG_ValueError, "Lines must be the same size");
200 /* allocate the correct number of rows for the current line */
201 $1 [i1] = (float *)malloc (size2 * sizeof (float));
203 /* extract all the float values of this row */
204 for (i2 = 0; i2 < size2; i2++) {
205 PyObject *item = PyList_GetItem (list, i2);
206 $1 [i1][i2] = (float)PyFloat_AsDouble (item);
212 * map the output parameter of the cvGetMinMaxHistValue()
213 * so, we can call cvGetMinMaxHistValue() in Python like:
214 * min_value, max_value = cvGetMinMaxHistValue (hist, None, None)
216 %apply int *OUTPUT {int *min_idx};
217 %apply int *OUTPUT {int *max_idx};
218 %apply float *OUTPUT {float *min_value};
219 %apply float *OUTPUT {float *max_value};
221 * map output parameters of cvMinMaxLoc
223 %apply double *OUTPUT {double* min_val, double* max_val};
226 * the input argument of cvPolyLine "CvPoint** pts" is converted from
227 * a "list of list" (aka. an array) of CvPoint().
228 * The next parameters "int* npts" and "int contours" are computed from
231 %typemap(in) (CvPoint** pts, int* npts, int contours){
235 CvPoint **points = NULL;
236 int *nb_vertex = NULL;
238 if(!PySequence_Check($input)){
239 SWIG_exception(SWIG_TypeError, "Expected a list for argument $argnum\n");
243 /* get the number of polylines input array */
244 int size1 = PySequence_Size ($input);
248 /* create the points array */
249 points = (CvPoint **)malloc (size1 * sizeof (CvPoint *));
251 /* point to the created array for passing info to the C function */
254 /* create the array for memorizing the vertex */
255 nb_vertex = (int *)malloc (size1 * sizeof (int));
258 for (i = 0; i < size1; i++) {
260 /* get the current item */
261 PyObject *line = PySequence_GetItem ($input, i);
263 if(!PySequence_Check(line)){
264 SWIG_exception(SWIG_TypeError, "Expected a sequence of sequences of integers for argument $argnum\n");
265 // TODO: cleanup here
268 /* get the size of the current polyline */
269 size2 = PySequence_Size (line);
273 /* allocate the necessary memory to store the points */
274 points [i] = (CvPoint *)malloc (size2 * sizeof (CvPoint));
277 /* memorize the size of the polyline in the vertex list */
278 nb_vertex [i] = size2;
280 for (j = 0; j < size2; j++) {
281 /* get the current item */
282 PyObject *item = PySequence_GetItem (line, j);
283 points[i][j] = PyObject_to_CvPoint( item );
287 /** Free arguments allocated before the function call */
288 %typemap(freearg) (CvPoint **pts, int* npts, int contours){
297 /** Macro to define typemaps to convert a python list of CvPoints to a C array of CvPoints */
298 %define %typemap_CvPoint_CArr(points_arg, numpoints_arg)
300 %typemap(in, numinputs=1) (CvPoint * points_arg, int numpoints_arg){
302 if(!PySequence_Check($input)){
303 SWIG_exception(SWIG_TypeError, "Expected a list for argument $argnum\n");
306 int size = PySequence_Size($input);
307 CvPoint * points = (CvPoint *)malloc(size*sizeof(CvPoint));
308 for(i=0; i<size; i++){
309 PyObject *item = PySequence_GetItem($input, i);
310 points[i] = PyObject_to_CvPoint( item );
315 %typemap(freearg) (CvPoint *points_arg, int numpoints_arg){
320 /* apply to cvFillConvexPoly */
321 %typemap_CvPoint_CArr(pts, npts)
324 * this is mainly an "output parameter"
325 * So, just allocate the memory as input
327 %typemap (in, numinputs=0) (CvSeq ** OUTPUT) (CvSeq * seq) {
332 * return the finded contours with all the others parametres
334 %typemap(argout) (CvSeq ** OUTPUT) {
337 /* extract the pointer we want to add to the returned tuple */
338 /* sequence is allocated in CvMemStorage, so python_ownership=0 */
339 to_add = SWIG_NewPointerObj (*$1, $descriptor(CvSeq*), 0);
341 $result = SWIG_AppendResult($result, &to_add, 1);
343 %apply CvSeq **OUTPUT {CvSeq **first_contour};
344 %apply CvSeq **OUTPUT {CvSeq **comp};
347 * CvArr ** image can be either one CvArr or one array of CvArr
348 * (for example like in cvCalcHist() )
349 * From Python, the array of CvArr can be a tuple.
351 %typemap(in) (CvArr ** INPUT) (
352 CvArr * one_image=NULL,
353 bool free_one_arg=false,
354 CvArr ** many_images=NULL,
355 bool *free_many_args=NULL,
358 /* first, check if this is a tuple */
359 if PyTuple_Check ($input) {
360 /* This is a tuple, so we need to test each element and pass
361 them to the called function */
365 /* get the size of the tuple */
366 nimages = PyTuple_Size ($input);
368 /* allocate the necessary place */
369 many_images = (CvArr **)malloc (nimages * sizeof (CvArr *));
370 free_many_args = (bool *)malloc(nimages * sizeof(bool));
372 for (i = 0; i < nimages; i++) {
374 /* convert the current tuple element to a CvArr *, and
375 store to many_images [i] */
376 many_images[i] = PyObject_to_CvArr (PyTuple_GetItem ($input, i),
379 /* check that the current item is a correct type */
380 if(!many_images[i]) {
386 /* what to give to the called function */
389 } else if((one_image = PyObject_to_CvArr( $input, &free_one_arg ))){
391 /* this is just one CvArr *, so one_image will receive it */
395 /* not a CvArr *, not a tuple, this is wrong */
399 %apply CvArr ** INPUT {CvArr ** img};
400 %apply CvArr ** INPUT {CvArr ** image};
401 %apply CvArr ** INPUT {CvArr ** arr};
402 %apply CvArr ** INPUT {CvArr ** vects};
404 %typemap(freearg) (CvArr ** FREEARG) {
405 if(free_one_arg$argnum){
406 cvFree(&(one_image$argnum));
408 else if(free_many_args$argnum){
410 for (i=0; i<nimages$argnum; i++){
411 if(free_many_args$argnum[i]){
412 cvReleaseData(many_images$argnum[i]);
413 cvFree(many_images$argnum+i);
416 free(many_images$argnum);
417 free(free_many_args$argnum);
421 %apply CvArr ** FREEARG {CvArr ** img};
422 %apply CvArr ** FREEARG {CvArr ** image};
423 %apply CvArr ** FREEARG {CvArr ** arr};
424 %apply CvArr ** FREEARG {CvArr ** vects};
427 * Map the CvFont * parameter from the cvInitFont() as an output parameter
429 %typemap (in, numinputs=1) (CvFont* font, int font_face) {
430 $1 = (CvFont *)malloc (sizeof (CvFont));
431 $2 = (int)PyInt_AsLong ($input);
432 if (SWIG_arg_fail($argnum)) SWIG_fail;
434 %typemap(argout) (CvFont* font, int font_face) {
437 /* extract the pointer we want to add to the returned tuple */
438 to_add = SWIG_NewPointerObj ($1, $descriptor(CvFont *), 0);
440 $result = SWIG_AppendResult($result, &to_add, 1);
444 * these are output parameters for cvGetTextSize
446 %typemap (in, numinputs=0) (CvSize* text_size, int* baseline) {
447 CvSize *size = (CvSize *)malloc (sizeof (CvSize));
448 int *baseline = (int *)malloc (sizeof (int));
454 * return the finded parameters for cvGetTextSize
456 %typemap(argout) (CvSize* text_size, int* baseline) {
457 PyObject * to_add[2];
459 /* extract the pointers we want to add to the returned tuple */
460 to_add [0] = SWIG_NewPointerObj ($1, $descriptor(CvSize *), 0);
461 to_add [1] = PyInt_FromLong (*$2);
463 $result = SWIG_AppendResult($result, to_add, 2);
468 * curr_features is output parameter for cvCalcOpticalFlowPyrLK
470 %typemap (in, numinputs=1) (CvPoint2D32f* curr_features, int count)
472 /* as input, we only need the size of the wanted features */
474 /* memorize the size of the wanted features */
475 tmpCount = (int)PyInt_AsLong ($input);
477 /* create the array for the C call */
478 $1 = (CvPoint2D32f *) malloc(tmpCount * sizeof (CvPoint2D32f));
480 /* the size of the array for the C call */
485 * the features returned by cvCalcOpticalFlowPyrLK
487 %typemap(argout) (CvPoint2D32f* curr_features, int count) {
491 /* create the list to return */
492 to_add = PyList_New (tmpCount$argnum);
494 /* extract all the points values of the result, and add it to the
495 final resulting list */
496 for (i = 0; i < tmpCount$argnum; i++) {
497 PyList_SetItem (to_add, i,
498 SWIG_NewPointerObj (&($1 [i]),
499 $descriptor(CvPoint2D32f *), 0));
502 $result = SWIG_AppendResult($result, &to_add, 1);
506 * status is an output parameters for cvCalcOpticalFlowPyrLK
508 %typemap (in, numinputs=1) (char *status) (int tmpCountStatus){
509 /* as input, we still need the size of the status array */
511 /* memorize the size of the status array */
512 tmpCountStatus = (int)PyInt_AsLong ($input);
514 /* create the status array for the C call */
515 $1 = (char *)malloc (tmpCountStatus * sizeof (char));
519 * the status returned by cvCalcOpticalFlowPyrLK
521 %typemap(argout) (char *status) {
525 /* create the list to return */
526 to_add = PyList_New (tmpCountStatus$argnum);
528 /* extract all the integer values of the result, and add it to the
529 final resulting list */
530 for (i = 0; i < tmpCountStatus$argnum; i++) {
531 PyList_SetItem (to_add, i, PyBool_FromLong ($1 [i]));
534 $result = SWIG_AppendResult($result, &to_add, 1);
537 /* map one list of points to the two parameters dimenssion/sizes
538 for cvCalcOpticalFlowPyrLK */
539 %typemap(in) (CvPoint2D32f* prev_features) {
543 /* get the size of the input array */
544 size = PyList_Size ($input);
546 /* allocate the needed memory */
547 $1 = (CvPoint2D32f *)malloc (size * sizeof (CvPoint2D32f));
549 /* extract all the points values from the list */
550 for (i = 0; i < size; i++) {
551 PyObject *item = PyList_GetItem ($input, i);
554 SWIG_Python_ConvertPtr (item, &vptr,
555 $descriptor(CvPoint2D32f*),
556 SWIG_POINTER_EXCEPTION);
557 CvPoint2D32f *p = (CvPoint2D32f *)vptr;
564 * the corners returned by cvGoodFeaturesToTrack
566 %typemap (in, numinputs=1) (CvPoint2D32f* corners, int* corner_count)
568 /* as input, we still need the size of the corners array */
570 /* memorize the size of the status corners */
571 tmpCount = (int)PyInt_AsLong ($input);
573 /* create the corners array for the C call */
574 $1 = (CvPoint2D32f *)malloc (tmpCount * sizeof (CvPoint2D32f));
576 /* the size of the array for the C call */
581 * the corners returned by cvGoodFeaturesToTrack
583 %typemap(argout) (CvPoint2D32f* corners, int* corner_count) {
587 /* create the list to return */
588 to_add = PyList_New (tmpCount$argnum);
590 /* extract all the integer values of the result, and add it to the
591 final resulting list */
592 for (i = 0; i < tmpCount$argnum; i++) {
593 PyList_SetItem (to_add, i,
594 SWIG_NewPointerObj (&($1 [i]),
595 $descriptor(CvPoint2D32f *), 0));
598 $result = SWIG_AppendResult($result, &to_add, 1);
601 /* map one list of points to the two parameters dimension/sizes
602 for cvFindCornerSubPix */
603 %typemap(in, numinputs=1) (CvPoint2D32f* corners, int count)
604 (int cornersCount, CvPoint2D32f* corners){
607 if(!PyList_Check($input)){
608 PyErr_SetString(PyExc_TypeError, "Expected a list");
612 /* get the size of the input array */
613 cornersCount = PyList_Size ($input);
616 /* allocate the needed memory */
617 corners = (CvPoint2D32f *)malloc ($2 * sizeof (CvPoint2D32f));
620 /* the size of the array for the C call */
622 /* extract all the points values from the list */
623 for (i = 0; i < $2; i++) {
624 PyObject *item = PyList_GetItem ($input, i);
627 SWIG_Python_ConvertPtr (item, &vptr,
628 $descriptor(CvPoint2D32f*),
629 SWIG_POINTER_EXCEPTION);
630 CvPoint2D32f *p = (CvPoint2D32f *) vptr;;
638 * the corners returned by cvFindCornerSubPix
640 %typemap(argout) (CvPoint2D32f* corners, int count) {
644 /* create the list to return */
645 to_add = PyList_New (cornersCount$argnum);
647 /* extract all the corner values of the result, and add it to the
648 final resulting list */
649 for (i = 0; i < cornersCount$argnum; i++) {
650 PyList_SetItem (to_add, i,
651 SWIG_NewPointerObj (&(corners$argnum [i]),
652 $descriptor(CvPoint2D32f *), 0));
655 $result = SWIG_AppendResult( $result, &to_add, 1);
659 * return the corners for cvFindChessboardCorners
661 %typemap(in, numinputs=1) (CvSize pattern_size, CvPoint2D32f * corners, int * corner_count )
662 (CvSize * pattern_size, CvPoint2D32f * tmp_corners, int tmp_ncorners) {
664 if( SWIG_ConvertPtr($input, &vptr, $descriptor( CvSize * ), SWIG_POINTER_EXCEPTION ) == -1){
667 pattern_size=(CvSize *)vptr;
668 tmp_ncorners = pattern_size->width*pattern_size->height;
670 tmp_corners = (CvPoint2D32f *) malloc(sizeof(CvPoint2D32f)*tmp_ncorners);
676 %typemap(argout) (CvSize pattern_size, CvPoint2D32f * corners, int * corner_count){
680 /* create the list to return */
681 to_add = PyList_New ( tmp_ncorners$argnum );
683 /* extract all the corner values of the result, and add it to the
684 final resulting list */
685 for (i = 0; i < tmp_ncorners$argnum; i++) {
686 CvPoint2D32f * pt = new CvPoint2D32f;
687 pt->x = tmp_corners$argnum[i].x;
688 pt->y = tmp_corners$argnum[i].y;
690 PyList_SetItem (to_add, i,
691 SWIG_NewPointerObj( pt, $descriptor(CvPoint2D32f *), 0));
694 $result = SWIG_AppendResult( $result, &to_add, 1);
695 free(tmp_corners$argnum);
699 * return the matrices for cvCameraCalibrate
701 %typemap(in, numinputs=0) (CvMat * intrinsic_matrix, CvMat * distortion_coeffs)
703 $1 = cvCreateMat(3,3,CV_32F);
704 $2 = cvCreateMat(4,1,CV_32F);
707 %typemap(argout) (CvMat * intrinsic_matrix, CvMat * distortion_coeffs)
709 PyObject * to_add[2] = {NULL, NULL};
710 to_add[0] = SWIG_NewPointerObj($1, $descriptor(CvMat *), 1);
711 to_add[1] = SWIG_NewPointerObj($2, $descriptor(CvMat *), 1);
712 $result = SWIG_AppendResult( $result, to_add, 2 );
716 * Fix OpenCV inheritance for CvSeq, CvSet, CvGraph
717 * Otherwise, can't call CvSeq functions on CvSet or CvGraph
719 %typemap(in, numinputs=1) (CvSeq *) (void * ptr)
722 if( SWIG_ConvertPtr($input, &ptr, $descriptor(CvSeq *), 0) == -1 &&
723 SWIG_ConvertPtr($input, &ptr, $descriptor(CvSet *), 0) == -1 &&
724 SWIG_ConvertPtr($input, &ptr, $descriptor(CvGraph *), 0) == -1 &&
725 SWIG_ConvertPtr($input, &ptr, $descriptor(CvSubdiv2D *), 0) == -1 &&
726 SWIG_ConvertPtr($input, &ptr, $descriptor(CvChain *), 0) == -1 &&
727 SWIG_ConvertPtr($input, &ptr, $descriptor(CvContour *), 0) == -1 &&
728 SWIG_ConvertPtr($input, &ptr, $descriptor(CvContourTree *), 0) == -1 )
730 SWIG_exception (SWIG_TypeError, "could not convert to CvSeq");
736 %typemap(in, numinputs=1) (CvSet *) (void * ptr)
738 if( SWIG_ConvertPtr($input, &ptr, $descriptor(CvSet *), 0) == -1 &&
739 SWIG_ConvertPtr($input, &ptr, $descriptor(CvGraph *), 0) == -1 &&
740 SWIG_ConvertPtr($input, &ptr, $descriptor(CvSubdiv2D *), 0) == -1)
742 SWIG_exception (SWIG_TypeError, "could not convert to CvSet");
748 %typemap(in, numinputs=1) (CvGraph *) (void * ptr)
750 if( SWIG_ConvertPtr($input, &ptr, $descriptor(CvGraph *), 0) == -1 &&
751 SWIG_ConvertPtr($input, &ptr, $descriptor(CvSubdiv2D *), 0) == -1)
753 SWIG_exception (SWIG_TypeError, "could not convert to CvGraph");
760 * Remap output arguments to multiple return values for cvMinEnclosingCircle
762 %typemap(in, numinputs=0) (CvPoint2D32f * center, float * radius) (CvPoint2D32f * tmp_center, float tmp_radius)
764 tmp_center = (CvPoint2D32f *) malloc(sizeof(CvPoint2D32f));
768 %typemap(argout) (CvPoint2D32f * center, float * radius)
770 PyObject * to_add[2] = {NULL, NULL};
771 to_add[0] = SWIG_NewPointerObj( tmp_center$argnum, $descriptor(CvPoint2D32f *), 1);
772 to_add[1] = PyFloat_FromDouble( tmp_radius$argnum );
774 $result = SWIG_AppendResult($result, to_add, 2);
778 %typemap(in, numinputs=0) (CvPoint2D32f pt[4]) (CvPoint2D32f tmp_pts[4])
782 %typemap(argout) (CvPoint2D32f pt[4])
784 PyObject * to_add = PyList_New(4);
787 CvPoint2D32f * p = new CvPoint2D32f;
788 *p = tmp_pts$argnum[i];
789 PyList_SetItem(to_add, i, SWIG_NewPointerObj( p, $descriptor(CvPoint2D32f *), 1 ) );
791 $result = SWIG_AppendResult($result, &to_add, 1);
794 /** Macro to wrap a built-in type that is used as an object like CvRNG and CvSubdiv2DEdge */
795 %define %wrap_builtin(type)
798 class type##_Wrapper {
802 type##_Wrapper( const type & val ) :
806 type * ptr() { return &m_val; }
807 type & ref() { return m_val; }
808 bool operator==(const type##_Wrapper & x){
809 return m_val==x.m_val;
811 bool operator!=(const type##_Wrapper & x){
812 return m_val!=x.m_val;
818 type##_Wrapper * wrapper = new type##_Wrapper( $1 );
819 $result = SWIG_NewPointerObj( wrapper, $descriptor( type##_Wrapper * ), 1 );
823 type##_Wrapper * wrapper = new type##_Wrapper( *($1) );
824 $result = SWIG_NewPointerObj( wrapper, $descriptor( type##_Wrapper * ), 1 );
827 %typemap(in) (type *) (void * vptr, type##_Wrapper * wrapper){
828 if(SWIG_ConvertPtr($input, &vptr, $descriptor(type##_Wrapper *), 0)==-1){
829 SWIG_exception( SWIG_TypeError, "could not convert Python object to C value");
832 wrapper = (type##_Wrapper *) vptr;
835 %typemap(in) (type) (void * vptr, type##_Wrapper * wrapper){
836 if(SWIG_ConvertPtr($input, &vptr, $descriptor(type##_Wrapper *), 0)==-1){
837 SWIG_exception( SWIG_TypeError, "could not convert Python object to C value");
840 wrapper = (type##_Wrapper *) vptr;
845 /** Application of wrapper class to built-in types */
846 %wrap_builtin(CvRNG);
847 %wrap_builtin(CvSubdiv2DEdge);
850 * Allow CvQuadEdge2D to be interpreted as CvSubdiv2DEdge
852 %typemap(in, numinputs=1) (CvSubdiv2DEdge) (CvSubdiv2DEdge_Wrapper * wrapper, CvQuadEdge2D * qedge, void *vptr)
854 if( SWIG_ConvertPtr($input, &vptr, $descriptor(CvSubdiv2DEdge_Wrapper *), 0) != -1 ){
855 wrapper = (CvSubdiv2DEdge_Wrapper *) vptr;
858 else if( SWIG_ConvertPtr($input, &vptr, $descriptor(CvQuadEdge2D *), 0) != -1 ){
859 qedge = (CvQuadEdge2D *) vptr;
860 $1 = (CvSubdiv2DEdge)qedge;
863 SWIG_exception( SWIG_TypeError, "could not convert to CvSubdiv2DEdge");
869 * return the vertex and edge for cvSubdiv2DLocate
871 %typemap(in, numinputs=0) (CvSubdiv2DEdge * edge, CvSubdiv2DPoint ** vertex)
872 (CvSubdiv2DEdge tmpEdge, CvSubdiv2DPoint * tmpVertex)
877 %typemap(argout) (CvSubdiv2DEdge * edge, CvSubdiv2DPoint ** vertex)
879 PyObject * to_add[2] = {NULL, NULL};
880 if(result==CV_PTLOC_INSIDE || result==CV_PTLOC_ON_EDGE){
881 CvSubdiv2DEdge_Wrapper * wrapper = new CvSubdiv2DEdge_Wrapper( tmpEdge$argnum );
882 to_add[0] = SWIG_NewPointerObj( wrapper, $descriptor(CvSubdiv2DEdge_Wrapper *), 0);
885 if(result==CV_PTLOC_VERTEX){
887 to_add[1] = SWIG_NewPointerObj( tmpVertex$argnum, $descriptor(CvSubdiv2DPoint *), 0);
890 $result = SWIG_AppendResult($result, to_add, 2);
894 * int *value in cvCreateTrackbar() is only used for input in the Python wrapper.
895 * for output, use the pos in the callback
896 * TODO: remove the memory leak introducted by the malloc () (if needed).
898 %typemap(in, numinputs=1) (int *value)
900 $1 = (int *)malloc (sizeof (int));
901 *$1 = PyInt_AsLong ($input);