Skip to content

Commit b9796e3

Browse files
committed
Changes
1 parent cc50b19 commit b9796e3

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __str__(self):
2121
import pybind11
2222
return pybind11.get_include(self.user)
2323

24+
import cv2
2425

2526
ext_modules = [
2627
Extension(
@@ -33,7 +34,10 @@ def __str__(self):
3334
"include",
3435
"/home/virtuald/src/frc/ext/opencv-python/opencv/build/prefix/include",
3536
],
36-
language='c++'
37+
library_dirs=[cv2.distutils.get_lib_path()],
38+
libraries=['opencv_core', 'opencv_imgproc'],
39+
language='c++',
40+
runtime_library_dirs=['$ORIGIN/cv2'],
3741
),
3842
]
3943

src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#include <pybind11/pybind11.h>
2+
#include <pybind11/numpy.h>
23
namespace py = pybind11;
34

45
#include <opencv2/core.hpp>
56
#include <opencv2/imgproc.hpp>
67
#include <opencv2/python/pyapi.hpp>
78

8-
PyObject * draw_rect(PyObject * in) {
9+
PyObject * draw_rect(py::array in) {
910

1011
cv::Mat mat;
1112

12-
if (!PyOpenCV_NdarrayToMat(in, mat, "in"))
13+
if (!PyOpenCV_NdarrayToMat(in.ptr(), mat, "in"))
1314
return NULL;
1415

1516
cv::Point pt1, pt2;
@@ -24,11 +25,10 @@ PyObject * draw_rect(PyObject * in) {
2425
}
2526

2627

27-
PYBIND11_PLUGIN(python_example) {
28+
PYBIND11_PLUGIN(test_package) {
2829

29-
import_opencv();
3030

31-
py::module m("python_example");
31+
py::module m("test_package");
3232

3333
m.def("draw_rect", &draw_rect);
3434

@@ -38,5 +38,6 @@ PYBIND11_PLUGIN(python_example) {
3838
m.attr("__version__") = py::str("dev");
3939
#endif
4040

41+
import_opencv();
4142
return m.ptr();
4243
}

0 commit comments

Comments
 (0)