From 134df77b710ce940aca59a524a9137d5beb2740d Mon Sep 17 00:00:00 2001 From: berak Date: Fri, 4 Sep 2020 15:00:31 +0200 Subject: [PATCH] ximgproc: add python wrappers for disparity functions --- .../opencv2/ximgproc/disparity_filter.hpp | 8 +++---- .../misc/python/test/test_disparity.py | 24 +++++++++++++++++++ modules/ximgproc/src/disparity_filters.cpp | 3 --- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 modules/ximgproc/misc/python/test/test_disparity.py diff --git a/modules/ximgproc/include/opencv2/ximgproc/disparity_filter.hpp b/modules/ximgproc/include/opencv2/ximgproc/disparity_filter.hpp index b73843684..c6436e604 100644 --- a/modules/ximgproc/include/opencv2/ximgproc/disparity_filter.hpp +++ b/modules/ximgproc/include/opencv2/ximgproc/disparity_filter.hpp @@ -160,7 +160,7 @@ and MPI-Sintel formats. Note that the resulting disparity map is scaled by 16. @result returns zero if successfully read the ground truth */ -CV_EXPORTS +CV_EXPORTS_W int readGT(String src_path,OutputArray dst); /** @brief Function for computing mean square error for disparity maps @@ -173,7 +173,7 @@ int readGT(String src_path,OutputArray dst); @result returns mean square error between GT and src */ -CV_EXPORTS +CV_EXPORTS_W double computeMSE(InputArray GT, InputArray src, Rect ROI); /** @brief Function for computing the percent of "bad" pixels in the disparity map @@ -189,7 +189,7 @@ double computeMSE(InputArray GT, InputArray src, Rect ROI); @result returns mean square error between GT and src */ -CV_EXPORTS +CV_EXPORTS_W double computeBadPixelPercent(InputArray GT, InputArray src, Rect ROI, int thresh=24/*1.5 pixels*/); /** @brief Function for creating a disparity map visualization (clamped CV_8U image) @@ -200,7 +200,7 @@ double computeBadPixelPercent(InputArray GT, InputArray src, Rect ROI, int thres @param scale disparity map will be multiplied by this value for visualization */ -CV_EXPORTS +CV_EXPORTS_W void getDisparityVis(InputArray src,OutputArray dst,double scale=1.0); //! @} diff --git a/modules/ximgproc/misc/python/test/test_disparity.py b/modules/ximgproc/misc/python/test/test_disparity.py new file mode 100644 index 000000000..d797e2524 --- /dev/null +++ b/modules/ximgproc/misc/python/test/test_disparity.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +import cv2 as cv +import numpy as np + +from tests_common import NewOpenCVTests + +class disparity_test(NewOpenCVTests): + def test_disp(self): + # readGT + ret,GT = cv.ximgproc.readGT(self.find_file("cv/disparityfilter/GT.png")) + self.assertEqual(ret, 0) # returns 0 on success! + self.assertFalse(np.shape(GT) == ()) + + # computeMSE + left = cv.imread(self.find_file("cv/disparityfilter/disparity_left_raw.png"), cv.IMREAD_UNCHANGED) + self.assertFalse(np.shape(left) == ()) + left = np.asarray(left, dtype=np.int16) + mse = cv.ximgproc.computeMSE(GT, left, (0, 0, GT.shape[1], GT.shape[0])) + + # computeBadPixelPercent + bad = cv.ximgproc.computeBadPixelPercent(GT, left, (0, 0, GT.shape[1], GT.shape[0]), 24) + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/ximgproc/src/disparity_filters.cpp b/modules/ximgproc/src/disparity_filters.cpp index b384eaefc..03a2691df 100644 --- a/modules/ximgproc/src/disparity_filters.cpp +++ b/modules/ximgproc/src/disparity_filters.cpp @@ -420,7 +420,6 @@ void DisparityWLSFilterImpl::ParallelMatOp_ParBody::operator() (const Range& ran (wls->*ops[i])(*src[i],*dst[i]); } -CV_EXPORTS_W Ptr createDisparityWLSFilter(Ptr matcher_left) { Ptr wls; @@ -451,7 +450,6 @@ Ptr createDisparityWLSFilter(Ptr matcher_left return wls; } -CV_EXPORTS_W Ptr createRightMatcher(Ptr matcher_left) { int min_disp = matcher_left->getMinDisparity(); @@ -485,7 +483,6 @@ Ptr createRightMatcher(Ptr matcher_left) } } -CV_EXPORTS_W Ptr createDisparityWLSFilterGeneric(bool use_confidence) { return Ptr(DisparityWLSFilterImpl::create(use_confidence));