diff --git a/modules/core/misc/python/pyopencv_core.hpp b/modules/core/misc/python/pyopencv_core.hpp new file mode 100644 index 0000000000..782dd5a73b --- /dev/null +++ b/modules/core/misc/python/pyopencv_core.hpp @@ -0,0 +1,21 @@ +#ifndef OPENCV_CORE_PYOPENCV_CORE_HPP +#define OPENCV_CORE_PYOPENCV_CORE_HPP + +#ifdef HAVE_OPENCV_CORE + +static PyObject* pycvMakeType(PyObject* , PyObject* args, PyObject* kw) { + const char *keywords[] = { "depth", "channels", NULL }; + + int depth, channels; + if (!PyArg_ParseTupleAndKeywords(args, kw, "ii", (char**)keywords, &depth, &channels)) + return NULL; + + int type = CV_MAKETYPE(depth, channels); + return PyInt_FromLong(type); +} + +#define PYOPENCV_EXTRA_METHODS_CV \ + {"CV_MAKETYPE", CV_PY_FN_WITH_KW(pycvMakeType), "CV_MAKETYPE(depth, channels) -> retval"}, + +#endif // HAVE_OPENCV_CORE +#endif // OPENCV_CORE_PYOPENCV_CORE_HPP diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index 0e5f5bc018..2bd6d0890f 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -142,6 +142,15 @@ class Bindings(NewOpenCVTests): with self.assertRaises(AttributeError): obj.except_ = 32 + def test_maketype(self): + data = { + cv.CV_8UC3: [cv.CV_8U, 3], + cv.CV_16SC1: [cv.CV_16S, 1], + cv.CV_32FC4: [cv.CV_32F, 4], + cv.CV_64FC2: [cv.CV_64F, 2], + } + for ref, (depth, channels) in data.items(): + self.assertEqual(ref, cv.CV_MAKETYPE(depth, channels)) class Arguments(NewOpenCVTests):