1

I'm using the pyopencv bindings. This python lib uses boost::python to connect to OopenCV. Now I'm trying to use the SURF class but don't know how to handle the class operator in my python code.

The C++ class is defined as:

void SURF::operator()(const Mat& img, const Mat& mask,
                  vector<KeyPoint>& keypoints) const
{...}

How can I pass my arguments to that class?

Update: Thanks to interjay I can call the method but now I getting type errors. What would be the python boost::python::tuple ?

import pyopencv as cv
img = cv.imread('myImage.jpg')

surf = cv.SURF();
key = []
mask = cv.Mat()
print surf(img, mask, key, False)

Gives me that:

Traceback (most recent call last):
   File "client.py", line 18, in <module>
       print surf(img, mask, key, False)
       Boost.Python.ArgumentError: Python argument types in
       SURF.__call__(SURF, Mat, Mat, list, bool)
       did not match C++ signature:
            __call__(cv::SURF inst, cv::Mat img, cv::Mat mask,
                     boost::python::tuple keypoints,
                     bool useProvidedKeypoints=False)
            __call__(cv::SURF inst, cv::Mat img, cv::Mat mask)
4

1 回答 1

1

你只是把它当作一个函数来调用。如果surf_instSURF该类的一个实例,您将调用:

newKeyPoints = surf_inst(img, mask, keypoints)

该参数keypoints应该是一个元组,img并且mask应该是Mat该类的一个实例。C++ 函数修改其keypoints参数。Python 版本改为返回修改后的关键点。

C++operator()类似于 Python 的__call__:它使用与函数调用相同的语法使对象可调用。

编辑:对于你的第二个问题:正如你在错误中看到的,keypoints应该是一个元组,你给了它一个列表。试着把它变成一个元组。

于 2010-02-05T20:30:06.390 回答