forked from pybind/python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (29 loc) · 810 Bytes
/
main.cpp
File metadata and controls
43 lines (29 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
namespace py = pybind11;
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/python/pyapi.hpp>
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);
}
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);
#else
m.attr("__version__") = py::str("dev");
#endif
import_opencv();
return m.ptr();
}