Coder Social home page Coder Social logo

suszw / opencv-ndarray-conversion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yati-sagade/opencv-ndarray-conversion

0.0 1.0 0.0 238 KB

NumPy ndarray ⇋ OpenCV Mat conversion, that just works.

License: MIT License

Makefile 10.37% C++ 74.74% Python 14.89%

opencv-ndarray-conversion's Introduction

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 and NumPy(maybe the devel package),

$ make
$ make test

This 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.

opencv-ndarray-conversion's People

Contributors

yati-sagade avatar dthpham avatar

Watchers

suzhiwei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.