diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index c09c5ace0..3b531c49e 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -1083,7 +1083,7 @@ Reprojects a disparity image to 3D space. :param Q: :math:`4 \times 4` perspective transformation matrix that can be obtained with :ocv:func:`stereoRectify`. - :param handleMissingValues: Indicates, whether the function should handle missing values (i.e. points where the disparity was not computed). If ``handleMissingValues=true``, then pixels with the minimal disparity that corresponds to the outliers (see :ocv:funcx:`StereoBM::operator()` ) are transformed to 3D points with a very large Z value (currently set to 10000). + :param handleMissingValues: Indicates, whether the function should handle missing values (i.e. points where the disparity was not computed). If ``handleMissingValues=true``, then pixels with the minimal disparity that corresponds to the outliers (see :ocv:funcx:`StereoMatcher::compute` ) are transformed to 3D points with a very large Z value (currently set to 10000). :param ddepth: The optional output array depth. If it is ``-1``, the output image will have ``CV_32F`` depth. ``ddepth`` can also be set to ``CV_16S``, ``CV_32S`` or ``CV_32F``. @@ -1170,7 +1170,7 @@ StereoMatcher ------------- .. ocv:class:: StereoMatcher : public Algorithm -The base class for stereo correspondence algorithms. :: +The base class for stereo correspondence algorithms. StereoMatcher::compute ----------------------- diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index 45c55a59f..79fb8892a 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -731,7 +731,7 @@ public: CV_WRAP virtual void setROI2(Rect roi2) = 0; }; -CV_EXPORTS Ptr createStereoBM(int numDisparities=0, int blockSize=21); +CV_EXPORTS_W Ptr createStereoBM(int numDisparities=0, int blockSize=21); class CV_EXPORTS_W StereoSGBM : public StereoMatcher @@ -756,7 +756,7 @@ public: }; -CV_EXPORTS Ptr createStereoSGBM(int minDisparity, int numDisparities, int blockSize, +CV_EXPORTS_W Ptr createStereoSGBM(int minDisparity, int numDisparities, int blockSize, int P1=0, int P2=0, int disp12MaxDiff=0, int preFilterCap=0, int uniquenessRatio=0, int speckleWindowSize=0, int speckleRange=0, diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 40538d1c9..78cd96e4c 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -129,6 +129,10 @@ typedef Ptr Ptr_DescriptorExtractor; typedef Ptr Ptr_Feature2D; typedef Ptr Ptr_DescriptorMatcher; +typedef Ptr Ptr_StereoMatcher; +typedef Ptr Ptr_StereoBM; +typedef Ptr Ptr_StereoSGBM; + typedef Ptr Ptr_ChannelFeatureBuilder; typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 7c511e4ef..25c4c2c82 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -14,6 +14,8 @@ import getopt import operator import functools +import numpy as np +import cv2 import cv2.cv as cv from test2 import * @@ -78,6 +80,12 @@ class OpenCVTests(unittest.TestCase): cv.SetData(imagefiledata, filedata, len(filedata)) self.image_cache[filename] = cv.DecodeImageM(imagefiledata, iscolor) return self.image_cache[filename] + + def get_sample2(self, filename, iscolor = cv.CV_LOAD_IMAGE_COLOR): + if not filename in self.image_cache: + filedata = urllib.urlopen("https://raw.github.com/Itseez/opencv/master/" + filename).read() + self.image_cache[filename] = cv2.imdecode(np.fromstring(filedata, dtype=np.uint8), iscolor) + return self.image_cache[filename] def setUp(self): self.image_cache = {} @@ -987,47 +995,14 @@ class AreaTests(OpenCVTests): self.assertRaises(cv.error, lambda: l[tup2]) def test_stereo(self): - bm = cv.CreateStereoBMState() - def illegal_delete(): - bm = cv.CreateStereoBMState() - del bm.preFilterType - def illegal_assign(): - bm = cv.CreateStereoBMState() - bm.preFilterType = "foo" - - self.assertRaises(TypeError, illegal_delete) - self.assertRaises(TypeError, illegal_assign) - - left = self.get_sample("samples/c/lena.jpg", 0) - right = self.get_sample("samples/c/lena.jpg", 0) - disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - cv.FindStereoCorrespondenceBM(left, right, disparity, bm) - - gc = cv.CreateStereoGCState(16, 2) - left_disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - right_disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - - def test_stereo(self): - bm = cv.CreateStereoBMState() - def illegal_delete(): - bm = cv.CreateStereoBMState() - del bm.preFilterType - def illegal_assign(): - bm = cv.CreateStereoBMState() - bm.preFilterType = "foo" - - self.assertRaises(TypeError, illegal_delete) - self.assertRaises(TypeError, illegal_assign) - - left = self.get_sample("samples/c/lena.jpg", 0) - right = self.get_sample("samples/c/lena.jpg", 0) - disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - cv.FindStereoCorrespondenceBM(left, right, disparity, bm) - - gc = cv.CreateStereoGCState(16, 2) - left_disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - right_disparity = cv.CreateMat(512, 512, cv.CV_16SC1) - cv.FindStereoCorrespondenceGC(left, right, left_disparity, right_disparity, gc) + left = self.get_sample2("samples/cpp/tsukuba_l.png", 0) + right = self.get_sample2("samples/cpp/tsukuba_r.png", 0) + bm = cv2.createStereoBM(32, 11) + disparity = bm.compute(left, right) + self.assertEqual(left.shape, disparity.shape) + sgbm = cv2.createStereoSGBM(0, 32, 5) + disparity2 = sgbm.compute(left, right) + self.assertEqual(left.shape, disparity2.shape) def test_kalman(self): k = cv.CreateKalman(2, 1, 0)