Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Cython to wrap a C++ class that uses OpenCV types as parameters
    primarykey
    data
    text
    <p>I'm trying to use Cython to wrap a C++ class that uses some OpenCV types as parameters, then I intend to use this wrapped class from Python. A simplified version of the C++ class looks like:</p> <p>"transform.h"</p> <pre><code>#include "opencv2/core/core.hpp" namespace geom { class Transform { public: Transform(cv::Vec3d &amp;euler, cv::Vec3d &amp;t); void set_euler(cv::Vec3d &amp;euler); cv::Vec3d get_euler(); } } </code></pre> <p>Vec3d is defined in OpenCV as:</p> <pre><code>template&lt;typename _Tp, int n&gt; class Vec : public Matx&lt;_Tp, n, 1&gt; {...}; typedef Vec&lt;double, 3&gt; Vec3d; </code></pre> <p>and Matx is defined as:</p> <pre><code>template&lt;typename _Tp, int m, int n&gt; class Matx {...}; </code></pre> <p>My first attempt to the cython wrapper looks like this:</p> <p>"geom_gateway.pyx"</p> <pre><code>cdef extern from "opencv2/core/core.hpp" namespace "cv": cdef cppclass Matx[_Tp, int m, int n]: Matx() Matx(_Tp v0, _Tp v1, _Tp v2) cdef extern from "opencv2/core/core.hpp" namespace "cv": cdef cppclass Vec[_Tp, int n](Matx[_Tp, n, 1]): Vec() Vec(_Tp v0, _Tp v1, _Tp v2) ctypedef Vec&lt;double, 3&gt; Vec3d cdef extern from "transform.h" namespace "geom": cdef cppclass Transform: Transform(cv::Vec3d &amp;euler, cv::Vec3d &amp;t) void set_euler(cv::Vec3d &amp;euler) cv::Vec3d get_euler() </code></pre> <p>This wrapper is unfinished but I just wanted to build it and check that I get the syntax right. Unfortunately, when I build it I don't get too far, I get:</p> <pre><code>cdef extern from "opencv2/core/core.hpp" namespace "cv": cdef cppclass Matx[_Tp, int m, int n]: ^ ------------------------------------------------------------ ../basics/geom_gateway:3:29: Expected ']', found 'm' </code></pre> <p>what's wrong? I imagine that it's possible to have multiple value templates in Cython? otherwise how could I wrap in Cython a C++ class that uses these templated types from OpenCV? I suspect I may have other problems in this piece of code, please feel free to point out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload