Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yati-sagade/opencv-ndarray-conversion
NumPy ndarray ⇋ OpenCV Mat conversion, that just works.
https://github.com/yati-sagade/opencv-ndarray-conversion
numpy opencv opencv-ndarray-conversion
Last synced: about 2 months ago
JSON representation
NumPy ndarray ⇋ OpenCV Mat conversion, that just works.
- Host: GitHub
- URL: https://github.com/yati-sagade/opencv-ndarray-conversion
- Owner: yati-sagade
- License: mit
- Created: 2013-05-10T09:45:27.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-05-17T16:12:29.000Z (over 3 years ago)
- Last Synced: 2024-10-11T21:44:12.921Z (2 months ago)
- Topics: numpy, opencv, opencv-ndarray-conversion
- Language: C++
- Size: 232 KB
- Stars: 117
- Watchers: 10
- Forks: 41
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
NumPy ndarray ⇋ OpenCV Mat conversion, that just works.
===========================================================API
------ `class NDArrayConverter`: The converter class
- `NDArrayConverter::NDArrayConverter()`: Constructor- `cv::Mat NDArrayConverter::toMat(const PyObject* o)`: Convert a NumPy ndarray
to a `cv::Mat`.- o is the object representing the Python representation of the ndarray.
- **Returns** a `cv::Mat` which is the OpenCV representation of o.
- `PyObject* NDArrayConverter::toNDArray(const cv::Mat& mat)`: Convert a `cv::Mat` to a NumPy ndarray.
- mat is the cv::Mat to convert.- **Returns** a `PyObject*` that is the Python representation of an ndarray.
Examples
--------`examples.cpp` contains
- An implementation of matrix multiplication `mul()` that takes two
`ndarray` objects, converts them to `cv::Mat`, multiplies them and returns
the result as an `ndarray`.- An image binarization function `binarize()` that takes an `ndarray`
containing a grayscale image and a threshold value, converts the image to
a `cv::Mat` and thresholds(binarizes) it. It then returns the result as
a `ndarray`.- An image display function `display(ndarray)` that just takes any image
as an `ndarray` object 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
from Python.Building and testing
---------------------After installing [Boost::Python][1] and [NumPy][2](maybe the devel package),
$ make
$ make testThis builds and tests the project. Specifically, it builds the core converter
in `conversion.o` and a set of examples in `examples.so`, which is a Python
module containing a few examples of using the converter. `test.py` contains
a test-suite to test (and demonstrate) the converter.[1]: http://www.boost.org/doc/libs/1_53_0/libs/python/doc/index.html
[2]: http://www.numpy.org/