From f1055a7e91372448a53fb2ecd4f56f5cd75fbc11 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=B5=B5=E6=A5=9A=E6=B4=8B?= Date: Sun, 2 Oct 2022 17:06:07 +0800 Subject: [PATCH] add test --- modules/imgproc/include/opencv2/imgproc.hpp | 1 + .../imgproc/misc/python/test/test_matx_converter.py | 19 +++++++++++++++++++ modules/imgproc/src/test_matx_converter.cpp | 9 +++++++++ modules/python/src2/cv2_convert.hpp | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 modules/imgproc/misc/python/test/test_matx_converter.py create mode 100644 modules/imgproc/src/test_matx_converter.cpp diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index afc2742..073833e 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -4973,6 +4973,7 @@ public: }; //! @cond IGNORED +CV_EXPORTS_W void testMatxPythonConverter(InputArray src, OutputArray dst, const Vec2d& defaultParam = Vec2d(-5, 5)); // === LineIterator implementation === diff --git a/modules/imgproc/misc/python/test/test_matx_converter.py b/modules/imgproc/misc/python/test/test_matx_converter.py new file mode 100644 index 0000000..8a39031 --- /dev/null +++ b/modules/imgproc/misc/python/test/test_matx_converter.py @@ -0,0 +1,19 @@ +from __future__ import print_function +import cv2 as cv +from cv2 import testMatxPythonConverter +from tests_common import NewOpenCVTests + + +class MatxConverterTest(NewOpenCVTests): + def test_matxconverter(self): + samples = ['samples/data/lena.jpg', 'cv/cascadeandhog/images/mona-lisa.png'] + + for sample in samples: + img = self.get_sample(sample) + out = testMatxPythonConverter(img) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() + + diff --git a/modules/imgproc/src/test_matx_converter.cpp b/modules/imgproc/src/test_matx_converter.cpp new file mode 100644 index 0000000..96e0eca --- /dev/null +++ b/modules/imgproc/src/test_matx_converter.cpp @@ -0,0 +1,9 @@ +#include "precomp.hpp" + +namespace cv{ + void testMatxPythonConverter(InputArray _src, OutputArray _dst, const Vec2d& defaultParam){ + printf("%f %f\n", defaultParam[0], defaultParam[1]); + Mat src = _src.getMat(); + src.copyTo(_dst); + } +} diff --git a/modules/python/src2/cv2_convert.hpp b/modules/python/src2/cv2_convert.hpp index 563f538..7dc0ffb 100644 --- a/modules/python/src2/cv2_convert.hpp +++ b/modules/python/src2/cv2_convert.hpp @@ -62,6 +62,9 @@ PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter::from(src); template bool pyopencv_to(PyObject* o, cv::Matx<_Tp, m, n>& mx, const ArgInfo& info) { + if (!o || o == Py_None) + return true; + cv::Mat tmp; if (!pyopencv_to(o, tmp, info)) { return false; -- 2.7.4