views:

262

answers:

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)
+1  A: 

You just call it as if it was a function. If surf_inst is an instance of the SURF class, you would call:

newKeyPoints = surf_inst(img, mask, keypoints)

The argument keypoints is expected to be a tuple, and img and mask should be an instance of the Mat class. The C++ function modifies its keypoints parameter. The Python version instead returns the modified keypoints.

C++'s operator() is analogous to Python's __call__: It makes an object callable using the same syntax as a function call.

Edit: For your second question: As you can see in the error, keypoints is supposed to be a tuple and you gave it a list. Try making it a tuple instead.

interjay
Thanks interjay, that works. But now I'm getting a type error. I've updated my question. Do you have any advice on that?
dan
@dan see my edit
interjay