HiPipe  0.7.0
C++17 data pipeline with Python bindings.
pyboost_cv_mat_converter.hpp
1 /****************************************************************************
2  * hipipe library
3  * Copyright (c) 2014, Gregory Kramida
4  * Modified by Filip Matzner, Adam Blazek
5  *
6  * This file is distributed under the MIT License.
7  * See the accompanying file LICENSE.txt for the complete license agreement.
8  ****************************************************************************/
9 
10 #pragma once
11 #if defined HIPIPE_BUILD_PYTHON && defined HIPIPE_BUILD_PYTHON_OPENCV
12 
13 // this header has to be included before the numpy header
14 #include <hipipe/core/python/initialize.hpp>
15 
16 #include <Python.h>
17 #include <boost/python.hpp>
18 #include <numpy/ndarrayobject.h>
19 #include <opencv2/core/core.hpp>
20 
21 #include <cstdio>
22 
23 namespace hipipe::python::utility {
24 
25 struct matToNDArrayBoostConverter {
26  static PyObject* convert(cv::Mat const& m);
27 };
28 
29 struct matFromNDArrayBoostConverter {
30 
31  matFromNDArrayBoostConverter();
32 
33  // check if PyObject is an array and can be converted to OpenCV matrix
34  static void* convertible(PyObject* object);
35 
36  // construct a Mat from an NDArray object
37  static void construct(PyObject* object,
38  boost::python::converter::rvalue_from_python_stage1_data* data);
39 };
40 
41 } // namespace hipipe::python::utility
42 
43 #endif // defined HIPIPE_BUILD_PYTHON && defined HIPIPE_BUILD_PYTHON_OPENCV