NumPy ndarray ⇋ OpenCV Mat conversion, that just works.
class NDArrayConverter: The converter class
cv::Mat NDArrayConverter::toMat(const PyObject* o): Convert a NumPy ndarray to a
o is the object representing the Python representation of the ndarray.
cv::Matwhich is the OpenCV representation of o.
PyObject* NDArrayConverter::toNDArray(const cv::Mat& mat): Convert a
cv::Matto a NumPy ndarray.
mat is the cv::Mat to convert.
PyObject*that is the Python representation of an ndarray.
An implementation of matrix multiplication
mul()that takes two
ndarrayobjects, converts them to
cv::Mat, multiplies them and returns the result as an
An image binarization function
binarize()that takes an
ndarraycontaining a grayscale image and a threshold value, converts the image to a
cv::Matand thresholds(binarizes) it. It then returns the result as a
An image display function
display(ndarray)that just takes any image as an
ndarrayobject and displays it.
All of these functions are callable from Python.
The plumbing(passing of values to and from Python) is handled by Boost::Python.
test.py contains some testcases that call the aforementioned C++ functions
Building and testing
$ make $ make test
This builds and tests the project. Specifically, it builds the core converter
conversion.o and a set of examples in
examples.so, which is a Python
module containing a few examples of using the converter.
a test-suite to test (and demonstrate) the converter.