diff --git a/setup.py b/setup.py index 75392c9..ce63843 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +from os.path import basename, exists, join from setuptools import setup, Extension from setuptools.command.build_ext import build_ext import sys @@ -20,17 +21,23 @@ def __str__(self): import pybind11 return pybind11.get_include(self.user) +import cv2 ext_modules = [ Extension( - 'python_example', + 'test_package', ['src/main.cpp'], include_dirs=[ # Path to pybind11 headers get_pybind_include(), - get_pybind_include(user=True) + get_pybind_include(user=True), + "include", + "/home/virtuald/src/frc/ext/opencv-python/opencv/build/prefix/include", ], - language='c++' + library_dirs=[cv2.distutils.get_lib_path()], + libraries=['opencv_core', 'opencv_imgproc'], + language='c++', + runtime_library_dirs=['$ORIGIN/cv2'], ), ] @@ -80,6 +87,8 @@ def build_extensions(self): opts = self.c_opts.get(ct, []) if ct == 'unix': opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) + opts.append('-s') # strip + opts.append('-g0') opts.append(cpp_flag(self.compiler)) if has_flag(self.compiler, '-fvisibility=hidden'): opts.append('-fvisibility=hidden') diff --git a/src/main.cpp b/src/main.cpp index d81046d..32e2edb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,40 +1,36 @@ #include - -int add(int i, int j) { - return i + j; -} - -int subtract(int i, int j) { - return i - j; -} - +#include namespace py = pybind11; -PYBIND11_PLUGIN(python_example) { - py::module m("python_example", R"pbdoc( - Pybind11 example plugin - ----------------------- - - .. currentmodule:: python_example - - .. autosummary:: - :toctree: _generate - - add - subtract - )pbdoc"); - - m.def("add", &add, R"pbdoc( - Add two numbers - - Some other explanation about the add function. - )pbdoc"); +#include +#include +#include + +PyObject * draw_rect(py::array in) { + + cv::Mat mat; + + if (!PyOpenCV_NdarrayToMat(in.ptr(), mat, "in")) + return NULL; + + cv::Point pt1, pt2; + pt1.x = 10; + pt1.y = 10; + pt2.x = 100; + pt2.y = 100; + + rectangle(mat, pt1, pt2, cv::Scalar(255, 0, 0)); + + return PyOpenCV_MatToNdarray(mat); +} - m.def("subtract", &subtract, R"pbdoc( - Subtract two numbers - Some other explanation about the subtract function. - )pbdoc"); +PYBIND11_PLUGIN(test_package) { + + + py::module m("test_package"); + + m.def("draw_rect", &draw_rect); #ifdef VERSION_INFO m.attr("__version__") = py::str(VERSION_INFO); @@ -42,5 +38,6 @@ PYBIND11_PLUGIN(python_example) { m.attr("__version__") = py::str("dev"); #endif + import_opencv(); return m.ptr(); }