Updated cv2.cpp to support Python 3 API.
Added a header with defines to enable the module to compile with either python 2 or 3 without changes.
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
# include "opencv2/nonfree.hpp"
|
||||
#endif
|
||||
|
||||
#include "pycompat.hpp"
|
||||
|
||||
using cv::flann::IndexParams;
|
||||
using cv::flann::SearchParams;
|
||||
|
||||
@@ -1176,7 +1178,11 @@ static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name")
|
||||
}
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define MKTYPE2(NAME) pyopencv_##NAME##_specials(); if (!to_ok(&pyopencv_##NAME##_Type)) return NULL;
|
||||
#else
|
||||
#define MKTYPE2(NAME) pyopencv_##NAME##_specials(); if (!to_ok(&pyopencv_##NAME##_Type)) return
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
@@ -1205,15 +1211,35 @@ static int to_ok(PyTypeObject *to)
|
||||
return (PyType_Ready(to) == 0);
|
||||
}
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
extern "C" CV_EXPORTS PyObject* PyInit_cv2();
|
||||
static struct PyModuleDef cv2_moduledef =
|
||||
{
|
||||
PyModuleDef_HEAD_INIT,
|
||||
MODULESTR,
|
||||
"Python wrapper for OpenCV.",
|
||||
-1, /* size of per-interpreter state of the module,
|
||||
or -1 if the module keeps state in global variables. */
|
||||
methods
|
||||
};
|
||||
|
||||
PyObject* PyInit_cv2()
|
||||
#else
|
||||
extern "C" CV_EXPORTS void initcv2();
|
||||
|
||||
void initcv2()
|
||||
#endif
|
||||
{
|
||||
import_array();
|
||||
|
||||
#include "pyopencv_generated_type_reg.h"
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject* m = PyModule_Create(&cv2_moduledef);
|
||||
#else
|
||||
PyObject* m = Py_InitModule(MODULESTR, methods);
|
||||
#endif
|
||||
PyObject* d = PyModule_GetDict(m);
|
||||
|
||||
PyDict_SetItemString(d, "__version__", PyString_FromString(CV_VERSION));
|
||||
@@ -1262,5 +1288,7 @@ void initcv2()
|
||||
PUBLISH(CV_64FC4);
|
||||
|
||||
#include "pyopencv_generated_const_reg.h"
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user