-
Notifications
You must be signed in to change notification settings - Fork 3
/
hello_worldmodule.cpp
40 lines (30 loc) · 1.02 KB
/
hello_worldmodule.cpp
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
#include <Python.h>
#include <opencv2/highgui/highgui.hpp>
#include "pyboostcvconverter/pyboostcvconverter.hpp"
using namespace cv;
void mirror(Mat img) {
flip(img, img, 1);
}
/* Python wrapper for the mirror() function. */
static PyObject * pyMirror(PyObject *self, PyObject *args) {
PyObject *ndArray;
if (!PyArg_ParseTuple(args, "O", &ndArray))
return NULL;
Mat mat = pbcvt::fromNDArrayToMat(ndArray);
mirror(mat);
return pbcvt::fromMatToNDArray(mat);
}
static PyMethodDef HelloWorldMethods[] = {
{"mirror", pyMirror, METH_VARARGS, "Mirrors an OpenCV image."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef helloWorldModule = {
PyModuleDef_HEAD_INIT,
"helloWorld", /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
HelloWorldMethods
};
PyMODINIT_FUNC PyInit_helloWorld(void) {
return PyModule_Create(&helloWorldModule);
}