add test
author赵楚洋 <zcy201420752@gmail.com>
Sun, 2 Oct 2022 09:06:07 +0000 (17:06 +0800)
committerVadim Levin <vadim.levin@xperience.ai>
Wed, 30 Nov 2022 15:31:03 +0000 (18:31 +0300)
modules/imgproc/include/opencv2/imgproc.hpp
modules/imgproc/misc/python/test/test_matx_converter.py [new file with mode: 0644]
modules/imgproc/src/test_matx_converter.cpp [new file with mode: 0644]
modules/python/src2/cv2_convert.hpp

index afc2742..073833e 100644 (file)
@@ -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 (file)
index 0000000..8a39031
--- /dev/null
@@ -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 (file)
index 0000000..96e0eca
--- /dev/null
@@ -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);
+    }
+}
index 563f538..7dc0ffb 100644 (file)
@@ -62,6 +62,9 @@ PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src);
 template<typename _Tp, int m, int n>
 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;