Algomorph/pyboostcvconverter

Passing cv::Mat returned from pbcvt to my .so

Closed this issue · 2 comments

I was able to build the pbcvt.so shared library and I added a method:

cv::Mat toCvMat(PyObject *ndArrayObj) {
return pbcvt::fromNDArrayToMat(ndArrayObj);
}

I invoke the method from my python script using:

           testMat = pbcvt.toCvMat(orig_frame_gray_img)

When I pass this to my test_library.so, it is passed as PyObject*, how do I access cv::Mat in my C++ library?:

bool TestLibrary::Process( PyObject* pTestImg)
{
// How to get cv::Mat from pTestImg?
}

At present, my test_library doesn't link with pbcvt since I don't use CMAKE in my test_library.

Thanks.

I'm confused about what you're trying to do here.
Why did you add an extra toCvMat function which is just a wrapper around the pbcvt::fromNDArrayToMat function?

What does testMat = pbcvt.toCvMat(orig_frame_gray_img) give? In python, cv::Mat is already represented as the numpy ndarray class, you don't need to convert anything.

You have to either link pbcvt with your test_library or just use the source files & header directly in your library. You don't really need CMake to do either one, but the CMake example may help you if you want to quickly learn CMake basics. If what you're trying to do is to use the sources directly, simply use cv::Mat testImg = pbcvt::fromNDArrayToMat(pTestImg); to explicitly convert the C++ cv::Mat object from a PyObject pointer. You're aware that you don't need to do explicit conversions and could just change the signature to TestLibrary::Process(cv::Mat testImg), so long as you properly expose TestLibrary::Process via the BOOST_PYTHON_MODULE macro, right?

Thanks for the reply. It made the usage of library clear. I should be statically linking to pbcvt. I will close this issue.