Cython access to opencv features2d module

515 Views Asked by At

I really need your help. I try to get access to the opencv descriptors AKAZE and FREAK with Python using Cython (until now I just tried it with FREAK). But everytime I try to compile it I get an error message about 730 lines because Cython says it does not know the vector<...> type and some lines are not in the official C++ syntax in the hpp file. But I don't understand this because it is the official opencv header which should work.

This is a part of my error message:

    /usr/include/opencv2/features2d/features2d.hpp:1515:35: error: ISO C++ forbids declaration of ‘parameter’ with no type [-fpermissive]
    /usr/include/opencv2/features2d/features2d.hpp:1515:41: error: expected ‘,’ or ‘...’ before ‘<’ token
    CV_EXPORTS float getRecall( const vector<Point2f>& recallPrecisionCurve, float l_precision );
                                     ^
    /usr/include/opencv2/features2d/features2d.hpp:1516:39: error: ‘vector’ does not name a type
    CV_EXPORTS int getNearestPoint( const vector<Point2f>& recallPrecisionCurve, float l_precision );

This is my .pxd - file:

cdef extern from "opencv2/core/core.hpp":
  cdef int  CV_WINDOW_AUTOSIZE
  cdef int CV_8UC3

# -------------------------------------Bool Header-------------------------

cdef extern from "stdbool.h":
    ctypedef struct bool:
        pass
# ------------------------------------Vector Header------------------------

cdef extern from "vector" namespace "std":
    cdef cppclass vector [T]:
        pass


# -----------------------------------Features2d Header----------------------

cdef extern from "/usr/include/opencv2/features2d/features2d.hpp" namespace "cv":
    cdef cppclass FREAK:
        FREAK* FREAK( bool orientationNormalized=true, bool scaleNormalized=true, float patternScale=22.0, int nOctaves=4, const vector& selectedPairs=vector<int>()) except *
        FREAK* FREAK( const FREAK& rhs )
        int descriptorSize()
        int descriptorType()

This is my setup.py file:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

libdir = ["/usr/include/", "/usr/local/lib"]
incdir = ["/usr/local/lib/", "/usr/include", "/usr/include/opencv2/core"]

ext_modules = [Extension("description",
                     ["description.pyx"],
                     language="c++",
                     library_dirs=libdir,
                     include_dirs=incdir,
                     libraries=["opencv_features2d", "opencv_core"])]

setup(name="description", ext_modules=cythonize(ext_modules))

The error message throws errors for nearly every function (and I just want to access the FREAK constructor). Hopefully you may help me.

Thanks a lot, Leo

0

There are 0 best solutions below