From 5ce78496a0b0de8e301e7f303747656e67cc59b0 Mon Sep 17 00:00:00 2001 From: "Christian S. Perone" Date: Fri, 20 Jun 2014 00:52:22 -0300 Subject: [PATCH 1/3] Fixing typo in the getting started part of the contours tutorial. --- .../py_contours/py_contours_begin/py_contours_begin.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst b/source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst index ae28199..5c1b769 100644 --- a/source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst +++ b/source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst @@ -43,7 +43,7 @@ To draw the contours, ``cv2.drawContours`` function is used. It can also be used To draw all the contours in an image: :: - img = cv2.drawContour(img, contours, -1, (0,255,0), 3) + img = cv2.drawContours(img, contours, -1, (0,255,0), 3) To draw an individual contour, say 4th contour: :: From ab6dcc5094699fe5013c688dca5a15389b83e148 Mon Sep 17 00:00:00 2001 From: abidrahmank Date: Thu, 24 Jul 2014 23:14:27 +0530 Subject: [PATCH 2/3] pybindings --- .../.py_bindings_basics.rst.swp | Bin 0 -> 20480 bytes .../py_bindings_basics/py_bindings_basics.rst | 112 ++++++++++++++++++ .../images/inpainticon.jpg | Bin 0 -> 5020 bytes .../images/nlm_icon.jpg | Bin 0 -> 3735 bytes .../py_table_of_contents_bindings.rst | 36 ++++++ source/py_tutorials/py_tutorials.rst | 18 ++- 6 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp create mode 100644 source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst create mode 100644 source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/inpainticon.jpg create mode 100644 source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/nlm_icon.jpg create mode 100644 source/py_tutorials/py_bindings/py_table_of_contents_bindings/py_table_of_contents_bindings.rst diff --git a/source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp b/source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp new file mode 100644 index 0000000000000000000000000000000000000000..96597f450e4848c194a2b2f4100debc670df067b GIT binary patch literal 20480 zcmeHOOKc=Z8Sb#aZUWgw2`40^N&*|(nVqq{Q5GDc$Z@=}VZFB2-d&!Wsp+nnY22^v zhsOg%NN_;n!X@GnDH4QBB9ORnLm)sx;s8Q{1aaa32Ovl}aYf?$|ElWgnH_r#;vtkC z?eCfHuKKI$tN&fS-NhT5TjEmlQ3s!QInHm^U)g=_XLmWTUUD4S^}SRMLK*GT(<47J zJ^s1v*h-726)Mk{tqSYb`bT$GukLPcUu|tCDq6d-d|_vl58~*;UXjPCFN3U=#YO6> zRx)bm;X(6#*VOkZbG>1{ zADVjpR&)J!^PNmRH<$HSjX;e+jX;e+jX;e+jX;e+jX;e+jX;e+jX;gS{{R8$IS&3g zXDH#v`M=Ho|9Z}GUI+ag^li|Kpcg=21AP_r70{PK9|z5W9tQpWEZ!dg{TlTAI~?a5 zpx_?I*$3T!#&PZgT}Odn5A-Yw3ZDag3*&whbOUr9v+i z$YY@na}{|aQbQ5OUJ!_V?LKkP3x@Mn3x(-D4Tmfk>P_h4mZOXj$pvH|-I17_?%c;%Xd;@eN0JWVGcC02c|}SRTa{9vN<(%!-NFyNmQf$P!9%b7v}iBm zfDi##olY_W-jRFIE;XXP&>T=B67Bh>c&f;W9dssys6t}07;tNS(+Va$nag~XKneqY zUkS)&L)=jAqkco|LY$joZ=gm{Wo!_{04%g};}S1ELF5BS!)1V_4rQ1G3erG41hFLf zC;~`Pr4x8m1WAu^L^~<+0vu^`^I=S4sQR!GLgg+5&<~;5X)tQcSRer!s6(S-<83Q9 zQuENNfBe!`A=Fs`3!zs#LsG~hC4qE-2sW?NncA`}b(gVyuqw?#l5{$dYuc4bN%3Np zMGxm%l8%-;8i1suB1BEG8D%-N#N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MWTv+fwj zU}`*hlyk<>FN6&>^&!~>GDJv!Cw7JFt!%<7h0KhOmtgi#1ma?bEr!_B0DBfun#;=R z1L7eZteF!;Z8NwWh+{+?j__v4h^jjJ09Ui*f*Ku6qOLblX3@={ShTmP3K4EoiNy|# zUACIZ62R=ISabgW+p~^y4|09V|B*`b=Lfic4zvy006hbuHtV4JQzK9#P$N(yP$N(y zP$N(yP$N(yP$N(yP$TgFi$M7v7bV(MwhZN`QTO1(2!3zdCiu26NkvC}v~O#M6ScqT zqsgeCo#QmuwNqg!W;Z10M{Ti>ORt|uv(1q&C^jIN} W74ldij}`J*xKD?l1)qNMSpNW%h@z|j literal 0 HcmV?d00001 diff --git a/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst b/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst new file mode 100644 index 0000000..7334123 --- /dev/null +++ b/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst @@ -0,0 +1,112 @@ +.. _Bindings_Basics: + +How OpenCV-Python Bindings Works? +************************************ + +Goal +===== + +Learn: + + * How OpenCV-Python bindings are generated? + * How to extend new OpenCV modules to Python? + +How OpenCV-Python bindings are generated? +========================================= + +In OpenCV, all algorithms are implemented in C++. But these algorithms can be used from different languages like Python, Java etc. This is made possible by the bindings generator files. These files form a bridge between C++ and Python which enable users to call C++ functions from Python. To get a complete picture of what is happening background, a good knowledge of Python/C API is required. A simple example on extending C++ functions to Python can be found in official Python documentation[1]. So extending every function in OpenCV to Python by writing its wrapper function is a time-consuming task. So OpenCV does it more intelligent way. OpenCV generates these wrapper functions automatically from the C++ headers using some Python scripts which are located in ``modules/python/src2``. We will look into what they do. + +First, ``modules/python/CMakeFiles.txt`` is a cmake script which checks the modules to be extended to Python. It will automatically check all the modules to be extended and grab their header files. These header files contain list of all classes, functions, constants etc. for that particular modules. + +Second, these header files are passed to a Python script, ``modules/python/src2/gen2.py``. He is the Python bindings generator script. It calls another Python script ``modules/python/src2/hdr_parser.py``. This is the header parser file. This guy splits the complete header file into small Python lists. So these lists contain all details about a particular function, class etc. For example, a function will be parsed to get a list containing function name, return type, input arguments, argument types etc. Final list contains details of all the functions, structs, classes etc. in that header file. + +But header parser doesn't parse all the functions/classes in the header file. Instead, there are certain macros added to the beginning of these declarations which enables the header parser to identify functions to be parsed. These macros are added by the developer who programs the particular function. So the developer decides which functions should be extended to Python and which are not. Details of the macros will be given in next session. + +So header parser returns a final big list of parsed functions. Our generator script (gen2.py) will create wrapper functions for all the functions/classes/enums/structs parsed by header parser (You can find these header files during compilation in the ``build/modules/python/`` folder as ``pyopencv_generated_*.h`` files). But there may be some basic OpenCV datatypes like Mat, Vec4i, Size. They need to be extended manually. For example, a Mat type should be extended to Numpy array, Size should be extended to a tuple of two integers etc. Similarly, there may be some complex structs/classes/functions etc. which need to be extended manually. All such manual wrapper functions are placed in ``modules/python/src2/pycv2.hpp``. + +So now only thing left is the compilation of these wrapper files which gives us **cv2** module. So when you call a function, say ``res = equalizeHist(img1,img2)`` in Python, ``cv::Mat`` structures corresponding to ``img1``, ``img2`` and ``res`` will be formed and calls the ``equalizeHist()`` function in C++. Final result, ``res`` will be converted back into a Numpy array. So in short, almost all operations are done in C++ which gives us almost same speed as that of C++. + +So this is the basic version of how OpenCV-Python bindings are generated. + + +How to extend new modules to Python? +===================================== + +Header parser parse the header files based on some wrapper macros added to function declaration. Enumeration constants don't need any wrapper macros. They are automatically wrapped. But remaining functions, classes etc. need wrapper macros. + +Functions are extended using ``CV_EXPORTS_W`` macro. An example is shown below. + +.. code-block:: cpp + + CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); + +Header parser can understand the input and output arguments from keywords like ``InputArray, OutputArray`` etc. But sometimes, we may need to hard-code inputs and outputs. For that, macros like ``CV_OUT, CV_IN_OUT`` etc. are used. + +.. code-block:: cpp + + CV_EXPORTS_W void minEnclosingCircle( InputArray points, + CV_OUT Point2f& center, CV_OUT float& radius ); + +For large classes also, ``CV_EXPORTS_W`` is used. To extend class methods, ``CV_WRAP`` is used. Similarly, ``CV_PROP`` is used for class fields. + +.. code-block:: cpp + + class CV_EXPORTS_W CLAHE : public Algorithm + { + public: + CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0; + + CV_WRAP virtual void setClipLimit(double clipLimit) = 0; + CV_WRAP virtual double getClipLimit() const = 0; + } + +Overloaded functions can be extended using ``CV_EXPORTS_AS``. But we need to pass a new name so that each function will be called by that name in Python. Take the case of integral function below. Three functions are available, so each one is named with a suffix in Python. Similarly ``CV_WRAP_AS`` can be used to wrap overloaded methods. + +.. code-block:: cpp + + //! computes the integral image + CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 ); + + //! computes the integral image and integral for the squared image + CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, + OutputArray sqsum, int sdepth = -1, int sqdepth = -1 ); + + //! computes the integral image, integral for the squared image and the tilted integral image + CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum, + OutputArray sqsum, OutputArray tilted, + int sdepth = -1, int sqdepth = -1 ); + +Small classes/structs are extended using ``CV_EXPORTS_W_SIMPLE``. These structs are passed by value to C++ functions. Examples are KeyPoint, Match etc. Their methods are extended by ``CV_WRAP`` and fields are extended by ``CV_PROP_RW``. + +.. code-block:: cpp + + class CV_EXPORTS_W_SIMPLE DMatch + { + public: + CV_WRAP DMatch(); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance); + + CV_PROP_RW int queryIdx; // query descriptor index + CV_PROP_RW int trainIdx; // train descriptor index + CV_PROP_RW int imgIdx; // train image index + + CV_PROP_RW float distance; + }; + +Some other small classes/structs can be exported using ``CV_EXPORTS_W_MAP`` where it is exported to a Python native dictionary. Moments() is an example of it. + +.. code-block:: cpp + + class CV_EXPORTS_W_MAP Moments + { + public: + //! spatial moments + CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; + //! central moments + CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03; + //! central normalized moments + CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; + }; + +So these are the major extension macros available in OpenCV. diff --git a/source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/inpainticon.jpg b/source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/inpainticon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..dc22cf0377a5600a2f6ecd6fe51767f555cb05db GIT binary patch literal 5020 zcmbW3XHe5!o5ueTkPe0>(jpQ?Kpvz@35m)>SE(^l3@R!D(vc1kP(Y+>KvY1GP$dx} zO^Wo6)DS6B5~{RNrG&6N@4K@*v!8bNI&FX;KP4b2Dg*|LNQsC_ zNI)PEfm3IpXC|tl$`{anLr@sWBInh! zdu(St1(m~+ve>1sl{5%h^wXd!_r1b7IE7D%oEANIUgmIEmtRm= zO8i<@UQt=~t+A=OrM0cSqjO+zh%`+8IWjs;q0Y?C%`YteUf|u|G&uo3+%tSMgeXR({XqpFn|EI)?!07)eG;1Kjf_6 zT+r+wB*TzT5iu|qmq*R7p)t6GCsYL0c0a1wknV8*Trz@a${bl0n;{l&eDJ84@dGZN z*?a`>3-8>HupQHUcP;Q~z0izhEMQ zJaq2Aer2Pq=PD{T_`5Uaw@WTxim=9`bmLTQSv=AV;haNmKWNt&HPpo4JOY{>mOZjW z&M!*;2m-_qx$^MIJ26gk@-h=1N*OKR_qSsUeYEcBnv_Bk_Epj6cTFe~nu#^9oXM8} z<>2Aj_>AXvgF0AUNXQ?!}*2Afv@Q@YqDj?_rO^e ziT*B)m{Tyg?IG{*hU|*L-Q)u4El&7Hl4bhfD*gxniS`lEfuS-w>zG!uz(f!Kb>E$~ z;2nb4ZcuIq1rzOA#OyH>L6(6b*P>CqJMW|Z3d(VqsFm33_-lzhM#$vq|+k3pWi$s(46SR84Wt!*ubV&6H=@c!7?s zdxtzezs@;yn|otNs`8zU0IvWkE(bU^-827FtURb%L#SaX^!y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z(Scc8u<_Qa;t*? literal 0 HcmV?d00001 diff --git a/source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/nlm_icon.jpg b/source/py_tutorials/py_bindings/py_table_of_contents_bindings/images/nlm_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0861964b9cd7fd2fff6fc1dffc62f725b3900505 GIT binary patch literal 3735 zcmbW1cTm%7v&Vm-7*HgJCOy)nDoBwc5s+#@5CRGc3IfuO^bUejMY{A*MWsesfJl)d z0R*InUJ`mJ2}nos;yHKjow+l2=DzQDXZN4oXJY|73ADGdIl(ji3tjULYdjPFEX=mvO=NkeC(V&JTMrH z`69m{Kd&G+FO2t36VT~X@EI^89UUVt3zUWT-xlQ?0Hp)00c&ayKR^WqQA0tLHUM@y zCoSl20skcs6*bN2lyvlG&z%-jUjV2;)YMd`^Pd8oRtKEs0U9VR6Q8u&8D@j0V15@C znc(&*~lHj#xt|9bi*)Fnka0&^FTox6Rm6KPvuBfDOOH)f*M_2EGkuk!= z^x-2b>*qGMb}#JR+&w(KynTFMzX=TskBE#)NKAU4oRXTBo|pfj;Nz#yg+&#WRn_R4 z+B!^2YuopBY)5C;z~IpE2yS$2d=5{TUszmPURfn?ZU5TY-P=Dn{KEwTsQcY$~6HLdV9-mv@OfPWFki`1Twf`)e zpzNFw`48IPWdA>~kpGD6zrp^8YaC#p2AwXC8VbOHBeAHzE%WK)c46FagNf%1w=k)+aQ!e~|+>YcyE+=>-h z7=^!%(yWmDUD2MN;T%jy^?$(yJEqk8U5sfai)(2V6S0M_}z79 zK1@vve%dIR!$`&X6JJtv2&6y}X`(0)Mc#bfC{&lxoa`ylEm$2bkl=>Pg8%eg`!uXa zWu1a*@cmNI!|RagAu+@E5jQaW0g+07 zPHWT>(llpr<)qK|PUBUw&0FRtU7=;_x^A*LVz-Q*hv}2nSDwf@+JB04FWo5cJTfb2 zdeEQy1M&W#VPmFnH@r2L%PvrbwB|b!DJ`9dHq8zXr2v=~jN#2y2SV&9!Mv{j7p^MV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@gCuS@8CsXjlUk0W|oE#M3+%}%qZMPV5Oba6zbdo3V)W3 Date: Sun, 10 Aug 2014 11:53:46 +0530 Subject: [PATCH 3/3] updated bindings section --- .../.py_bindings_basics.rst.swp | Bin 20480 -> 0 bytes .../py_bindings_basics/py_bindings_basics.rst | 14 +++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp diff --git a/source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp b/source/py_tutorials/py_bindings/py_bindings_basics/.py_bindings_basics.rst.swp deleted file mode 100644 index 96597f450e4848c194a2b2f4100debc670df067b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeHOOKc=Z8Sb#aZUWgw2`40^N&*|(nVqq{Q5GDc$Z@=}VZFB2-d&!Wsp+nnY22^v zhsOg%NN_;n!X@GnDH4QBB9ORnLm)sx;s8Q{1aaa32Ovl}aYf?$|ElWgnH_r#;vtkC z?eCfHuKKI$tN&fS-NhT5TjEmlQ3s!QInHm^U)g=_XLmWTUUD4S^}SRMLK*GT(<47J zJ^s1v*h-726)Mk{tqSYb`bT$GukLPcUu|tCDq6d-d|_vl58~*;UXjPCFN3U=#YO6> zRx)bm;X(6#*VOkZbG>1{ zADVjpR&)J!^PNmRH<$HSjX;e+jX;e+jX;e+jX;e+jX;e+jX;e+jX;gS{{R8$IS&3g zXDH#v`M=Ho|9Z}GUI+ag^li|Kpcg=21AP_r70{PK9|z5W9tQpWEZ!dg{TlTAI~?a5 zpx_?I*$3T!#&PZgT}Odn5A-Yw3ZDag3*&whbOUr9v+i z$YY@na}{|aQbQ5OUJ!_V?LKkP3x@Mn3x(-D4Tmfk>P_h4mZOXj$pvH|-I17_?%c;%Xd;@eN0JWVGcC02c|}SRTa{9vN<(%!-NFyNmQf$P!9%b7v}iBm zfDi##olY_W-jRFIE;XXP&>T=B67Bh>c&f;W9dssys6t}07;tNS(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Ul@JiE>jYIvXscykmLn)Z19Q#?;Uc&P zEWQqakp@!!PJ-l0m<@6?Mvljvx~P*4DPc@irK-RQE|O5xKM{tY#()DCngG|@Gakpo zB%r7grAwq$hhSX}TNX~owxdmp#Wcp5FbowXF(MwLXDpEQg{6#RtJ%6A_-T%Eunmq- zfmsXu(d(F4xtRk5NZU?2O6BDcW1DSfL5}?e(!@>xZ zISx2{}6$#Rj~KdQWbLZsG**Shog2rX83aRbMWTv+fwj zU}`*hlyk<>FN6&>^&!~>GDJv!Cw7JFt!%<7h0KhOmtgi#1ma?bEr!_B0DBfun#;=R z1L7eZteF!;Z8NwWh+{+?j__v4h^jjJ09Ui*f*Ku6qOLblX3@={ShTmP3K4EoiNy|# zUACIZ62R=ISabgW+p~^y4|09V|B*`b=Lfic4zvy006hbuHtV4JQzK9#P$N(yP$N(y zP$N(yP$N(yP$N(yP$TgFi$M7v7bV(MwhZN`QTO1(2!3zdCiu26NkvC}v~O#M6ScqT zqsgeCo#QmuwNqg!W;Z10M{Ti>ORt|uv(1q&C^jIN} W74ldij}`J*xKD?l1)qNMSpNW%h@z|j diff --git a/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst b/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst index 7334123..7e48930 100644 --- a/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst +++ b/source/py_tutorials/py_bindings/py_bindings_basics/py_bindings_basics.rst @@ -14,17 +14,17 @@ Learn: How OpenCV-Python bindings are generated? ========================================= -In OpenCV, all algorithms are implemented in C++. But these algorithms can be used from different languages like Python, Java etc. This is made possible by the bindings generator files. These files form a bridge between C++ and Python which enable users to call C++ functions from Python. To get a complete picture of what is happening background, a good knowledge of Python/C API is required. A simple example on extending C++ functions to Python can be found in official Python documentation[1]. So extending every function in OpenCV to Python by writing its wrapper function is a time-consuming task. So OpenCV does it more intelligent way. OpenCV generates these wrapper functions automatically from the C++ headers using some Python scripts which are located in ``modules/python/src2``. We will look into what they do. +In OpenCV, all algorithms are implemented in C++. But these algorithms can be used from different languages like Python, Java etc. This is made possible by the bindings generators. These generators create a bridge between C++ and Python which enables users to call C++ functions from Python. To get a complete picture of what is happening in background, a good knowledge of Python/C API is required. A simple example on extending C++ functions to Python can be found in official Python documentation[1]. So extending all functions in OpenCV to Python by writing their wrapper functions manually is a time-consuming task. So OpenCV does it in a more intelligent way. OpenCV generates these wrapper functions automatically from the C++ headers using some Python scripts which are located in ``modules/python/src2``. We will look into what they do. -First, ``modules/python/CMakeFiles.txt`` is a cmake script which checks the modules to be extended to Python. It will automatically check all the modules to be extended and grab their header files. These header files contain list of all classes, functions, constants etc. for that particular modules. +First, ``modules/python/CMakeFiles.txt`` is a CMake script which checks the modules to be extended to Python. It will automatically check all the modules to be extended and grab their header files. These header files contain list of all classes, functions, constants etc. for that particular modules. -Second, these header files are passed to a Python script, ``modules/python/src2/gen2.py``. He is the Python bindings generator script. It calls another Python script ``modules/python/src2/hdr_parser.py``. This is the header parser file. This guy splits the complete header file into small Python lists. So these lists contain all details about a particular function, class etc. For example, a function will be parsed to get a list containing function name, return type, input arguments, argument types etc. Final list contains details of all the functions, structs, classes etc. in that header file. +Second, these header files are passed to a Python script, ``modules/python/src2/gen2.py``. This is the Python bindings generator script. It calls another Python script ``modules/python/src2/hdr_parser.py``. This is the header parser script. This header parser splits the complete header file into small Python lists. So these lists contain all details about a particular function, class etc. For example, a function will be parsed to get a list containing function name, return type, input arguments, argument types etc. Final list contains details of all the functions, structs, classes etc. in that header file. -But header parser doesn't parse all the functions/classes in the header file. Instead, there are certain macros added to the beginning of these declarations which enables the header parser to identify functions to be parsed. These macros are added by the developer who programs the particular function. So the developer decides which functions should be extended to Python and which are not. Details of the macros will be given in next session. +But header parser doesn't parse all the functions/classes in the header file. The developer has to specify which functions should be exported to Python. For that, there are certain macros added to the beginning of these declarations which enables the header parser to identify functions to be parsed. These macros are added by the developer who programs the particular function. In short, the developer decides which functions should be extended to Python and which are not. Details of those macros will be given in next session. So header parser returns a final big list of parsed functions. Our generator script (gen2.py) will create wrapper functions for all the functions/classes/enums/structs parsed by header parser (You can find these header files during compilation in the ``build/modules/python/`` folder as ``pyopencv_generated_*.h`` files). But there may be some basic OpenCV datatypes like Mat, Vec4i, Size. They need to be extended manually. For example, a Mat type should be extended to Numpy array, Size should be extended to a tuple of two integers etc. Similarly, there may be some complex structs/classes/functions etc. which need to be extended manually. All such manual wrapper functions are placed in ``modules/python/src2/pycv2.hpp``. -So now only thing left is the compilation of these wrapper files which gives us **cv2** module. So when you call a function, say ``res = equalizeHist(img1,img2)`` in Python, ``cv::Mat`` structures corresponding to ``img1``, ``img2`` and ``res`` will be formed and calls the ``equalizeHist()`` function in C++. Final result, ``res`` will be converted back into a Numpy array. So in short, almost all operations are done in C++ which gives us almost same speed as that of C++. +So now only thing left is the compilation of these wrapper files which gives us **cv2** module. So when you call a function, say ``res = equalizeHist(img1,img2)`` in Python, you pass two numpy arrays and you expect another numpy array as the output. So these numpy arrays are converted to ``cv::Mat`` and then calls the ``equalizeHist()`` function in C++. Final result, ``res`` will be converted back into a Numpy array. So in short, almost all operations are done in C++ which gives us almost same speed as that of C++. So this is the basic version of how OpenCV-Python bindings are generated. @@ -40,7 +40,7 @@ Functions are extended using ``CV_EXPORTS_W`` macro. An example is shown below. CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); -Header parser can understand the input and output arguments from keywords like ``InputArray, OutputArray`` etc. But sometimes, we may need to hard-code inputs and outputs. For that, macros like ``CV_OUT, CV_IN_OUT`` etc. are used. +Header parser can understand the input and output arguments from keywords like ``InputArray, OutputArray`` etc. But sometimes, we may need to hardcode inputs and outputs. For that, macros like ``CV_OUT, CV_IN_OUT`` etc. are used. .. code-block:: cpp @@ -109,4 +109,4 @@ Some other small classes/structs can be exported using ``CV_EXPORTS_W_MAP`` wher CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; }; -So these are the major extension macros available in OpenCV. +So these are the major extension macros available in OpenCV. Typically, a developer has to put proper macros in their appropriate positions. Rest is done by generator scripts. Sometimes, there may be an exceptional cases where generator scripts cannot create the wrappers. Such functions need to be handled manually. But most of the time, a code written according to OpenCV coding guidelines will be automatically wrapped by generator scripts.