2

我真的需要你的帮助。我尝试使用 Cython 通过 Python 访问 opencv 描述符 AKAZE 和 FREAK(直到现在我才尝试使用 FREAK)。但是每次我尝试编译它时,我都会收到一条关于 730 行的错误消息,因为 Cython 说它不知道 vector<...> 类型,并且有些行不在 hpp 文件中的官方 C++ 语法中。但我不明白这一点,因为它应该是官方的 opencv 标头。

这是我的错误消息的一部分:

    /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 ‘&lt;’ 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 );

这是我的 .pxd - 文件:

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()

这是我的 setup.py 文件:

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))

几乎每个函数的错误消息都会引发错误(我只想访问 FREAK 构造函数)。希望你能帮助我。

非常感谢,狮子座

4

0 回答 0