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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.