Update to 2.0.0 tree from current Fremantle build
[opencv] / interfaces / swig / python / cvshadow.i
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41
42 /* This file contains custom python shadow class code for certain troublesome functions */
43
44 %{
45 #include "cvshadow.h"
46 %}
47
48 // source %myshadow, %myrelease macros
49 %include "cvswigmacros.i"
50
51 %include "stl.i"
52
53 // %ignore, %rename must come before %include
54 %myshadow(cvCvtSeqToArray);
55 %myshadow(cvHaarDetectObjects);
56 %myshadow(cvSegmentMotion);
57 %myshadow(cvApproxPoly);
58 %myshadow(cvConvexHull2);
59 %newobject cvConvexHull2_Shadow; // shadowed functioned always returns new object
60
61 /* cvSnakeImage shadow uses a vector<CvPoint> and vector<float> */ 
62 %template(FloatVector)   std::vector<float>;
63 %template(CvPointVector) std::vector<CvPoint>;
64 %myshadow(cvSnakeImage);
65
66 // must come after %ignore, %rename
67 %include "cvshadow.h"
68
69 /* return a typed CvSeq instead of generic for CvSubdiv2D edges -- see cvseq.i */
70 %rename (untyped_edges) CvSubdiv2D::edges;
71 %ignore CvSubdiv2D::edges;
72 %rename (edges) CvSubdiv2D::typed_edges;
73
74 /* Python doesn't know what to do with these */
75 %rename (asIplImage) operator IplImage*;
76 %rename (asCvMat) operator CvMat*;
77 %ignore operator const IplImage*;
78 %ignore operator const CvMat*;
79
80 /* Define sequence type for functions returning sequences */
81 %define %cast_seq( cvfunc, type )
82 %rename (cvfunc##Untyped) cvfunc;
83 %pythoncode %{
84 def cvfunc(*args):
85         seq = cvfunc##Untyped( *args )
86         return type.cast(seq)
87 %}
88 %enddef
89
90 %cast_seq( cvHoughCircles, CvSeq_float_3 );
91 %cast_seq( cvPyrSegmentation, CvSeq_CvConnectedComp );
92 %cast_seq( cvApproxChains, CvSeq_CvPoint);
93 %cast_seq( cvContourFromContourTree, CvSeq_CvPoint );
94 %cast_seq( cvConvexityDefects, CvSeq_CvConvexityDefect );
95
96 /* Special cases ... */
97 %rename(cvFindContoursUntyped) cvFindContours;
98 %pythoncode %{
99 def cvFindContours( *args ):
100         count, seq = cvFindContoursUntyped( *args )
101         return count, CvSeq_CvPoint.cast(seq)
102 %}
103
104 /* cvHoughLines2 returns a different type of sequence depending on its args */
105 %rename (cvHoughLinesUntyped) cvHoughLines2;
106 %pythoncode %{
107 def cvHoughLines2( *args ):
108         seq = cvHoughLinesUntyped( *args )
109         type = CV_SEQ_ELTYPE(seq) 
110         if type == CV_32SC4:
111                 return CvSeq_CvPoint_2.cast(seq)
112         return CvSeq_float_2.cast(seq)
113 %}
114
115 // cvPointSeqFromMat
116 // cvSeqPartition
117 // cvSeqSlice
118 // cvTreeToNodeSeq
119
120 // Fix cvRelease* function to play nice w/ Python
121 // TODO some of these objects lack the delete method -- why???
122 %myrelease(cv, cvReleaseImage, CvMat);  // IplImage is CvMat in Python
123 %myrelease(cv, cvReleaseMat, CvMat);
124 %myrelease(cv, cvReleaseStructuringElement, IplConvKernel);
125 %myrelease(cv, cvReleaseConDensation, CvConDensation);
126 %myrelease(cv, cvReleaseKalman, CvKalman);
127 %myrelease(cv, cvReleaseHist, CvHistogram);
128 %myrelease(cv, cvReleaseHaarClassifierCascade, CvHaarClassifierCascade);
129 //%myrelease(cvReleasePOSITObject, CvPOSITObject);
130 %myrelease(cv, cvReleaseImageHeader, CvMat); // IplImage is CvMat
131 %myrelease(cv, cvReleaseMatND, CvMatND);
132 %myrelease(cv, cvReleaseSparseMat, CvSparseMat);
133 %myrelease(cv, cvReleaseMemStorage, CvMemStorage);
134 %myrelease(cv, cvReleaseGraphScanner, CvGraphScanner);
135 //%myrelease(cvReleaseFileStorage, CvFileStorage);
136
137 // TODO implement this
138 %ignore cvRelease;