1/*M/////////////////////////////////////////////////////////////////////////////////////// 2// 3// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4// 5// By downloading, copying, installing or using the software you agree to this license. 6// If you do not agree to this license, do not download, install, 7// copy or use the software. 8// 9// 10// License Agreement 11// For Open Source Computer Vision Library 12// 13// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14// Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15// Third party copyrights are property of their respective owners. 16// 17// Redistribution and use in source and binary forms, with or without modification, 18// are permitted provided that the following conditions are met: 19// 20// * Redistribution's of source code must retain the above copyright notice, 21// this list of conditions and the following disclaimer. 22// 23// * Redistribution's in binary form must reproduce the above copyright notice, 24// this list of conditions and the following disclaimer in the documentation 25// and/or other materials provided with the distribution. 26// 27// * The name of the copyright holders may not be used to endorse or promote products 28// derived from this software without specific prior written permission. 29// 30// This software is provided by the copyright holders and contributors "as is" and 31// any express or implied warranties, including, but not limited to, the implied 32// warranties of merchantability and fitness for a particular purpose are disclaimed. 33// In no event shall the Intel Corporation or contributors be liable for any direct, 34// indirect, incidental, special, exemplary, or consequential damages 35// (including, but not limited to, procurement of substitute goods or services; 36// loss of use, data, or profits; or business interruption) however caused 37// and on any theory of liability, whether in contract, strict liability, 38// or tort (including negligence or otherwise) arising in any way out of 39// the use of this software, even if advised of the possibility of such damage. 40// 41//M*/ 42 43#include "test_precomp.hpp" 44 45#ifdef HAVE_CUDA 46 47using namespace cvtest; 48 49////////////////////////////////////////////////////////////////////////// 50// StereoBM 51 52struct StereoBM : testing::TestWithParam<cv::cuda::DeviceInfo> 53{ 54 cv::cuda::DeviceInfo devInfo; 55 56 virtual void SetUp() 57 { 58 devInfo = GetParam(); 59 60 cv::cuda::setDevice(devInfo.deviceID()); 61 } 62}; 63 64CUDA_TEST_P(StereoBM, Regression) 65{ 66 cv::Mat left_image = readImage("stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); 67 cv::Mat right_image = readImage("stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE); 68 cv::Mat disp_gold = readImage("stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE); 69 70 ASSERT_FALSE(left_image.empty()); 71 ASSERT_FALSE(right_image.empty()); 72 ASSERT_FALSE(disp_gold.empty()); 73 74 cv::Ptr<cv::StereoBM> bm = cv::cuda::createStereoBM(128, 19); 75 cv::cuda::GpuMat disp; 76 77 bm->compute(loadMat(left_image), loadMat(right_image), disp); 78 79 EXPECT_MAT_NEAR(disp_gold, disp, 0.0); 80} 81 82INSTANTIATE_TEST_CASE_P(CUDA_Stereo, StereoBM, ALL_DEVICES); 83 84////////////////////////////////////////////////////////////////////////// 85// StereoBeliefPropagation 86 87struct StereoBeliefPropagation : testing::TestWithParam<cv::cuda::DeviceInfo> 88{ 89 cv::cuda::DeviceInfo devInfo; 90 91 virtual void SetUp() 92 { 93 devInfo = GetParam(); 94 95 cv::cuda::setDevice(devInfo.deviceID()); 96 } 97}; 98 99CUDA_TEST_P(StereoBeliefPropagation, Regression) 100{ 101 cv::Mat left_image = readImage("stereobp/aloe-L.png"); 102 cv::Mat right_image = readImage("stereobp/aloe-R.png"); 103 cv::Mat disp_gold = readImage("stereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE); 104 105 ASSERT_FALSE(left_image.empty()); 106 ASSERT_FALSE(right_image.empty()); 107 ASSERT_FALSE(disp_gold.empty()); 108 109 cv::Ptr<cv::cuda::StereoBeliefPropagation> bp = cv::cuda::createStereoBeliefPropagation(64, 8, 2, CV_16S); 110 bp->setMaxDataTerm(25.0); 111 bp->setDataWeight(0.1); 112 bp->setMaxDiscTerm(15.0); 113 bp->setDiscSingleJump(1.0); 114 115 cv::cuda::GpuMat disp; 116 117 bp->compute(loadMat(left_image), loadMat(right_image), disp); 118 119 cv::Mat h_disp(disp); 120 h_disp.convertTo(h_disp, disp_gold.depth()); 121 122 EXPECT_MAT_NEAR(disp_gold, h_disp, 0.0); 123} 124 125INSTANTIATE_TEST_CASE_P(CUDA_Stereo, StereoBeliefPropagation, ALL_DEVICES); 126 127////////////////////////////////////////////////////////////////////////// 128// StereoConstantSpaceBP 129 130struct StereoConstantSpaceBP : testing::TestWithParam<cv::cuda::DeviceInfo> 131{ 132 cv::cuda::DeviceInfo devInfo; 133 134 virtual void SetUp() 135 { 136 devInfo = GetParam(); 137 138 cv::cuda::setDevice(devInfo.deviceID()); 139 } 140}; 141 142CUDA_TEST_P(StereoConstantSpaceBP, Regression) 143{ 144 cv::Mat left_image = readImage("csstereobp/aloe-L.png"); 145 cv::Mat right_image = readImage("csstereobp/aloe-R.png"); 146 147 cv::Mat disp_gold; 148 149 if (supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_20)) 150 disp_gold = readImage("csstereobp/aloe-disp.png", cv::IMREAD_GRAYSCALE); 151 else 152 disp_gold = readImage("csstereobp/aloe-disp_CC1X.png", cv::IMREAD_GRAYSCALE); 153 154 ASSERT_FALSE(left_image.empty()); 155 ASSERT_FALSE(right_image.empty()); 156 ASSERT_FALSE(disp_gold.empty()); 157 158 cv::Ptr<cv::cuda::StereoConstantSpaceBP> csbp = cv::cuda::createStereoConstantSpaceBP(128, 16, 4, 4); 159 cv::cuda::GpuMat disp; 160 161 csbp->compute(loadMat(left_image), loadMat(right_image), disp); 162 163 cv::Mat h_disp(disp); 164 h_disp.convertTo(h_disp, disp_gold.depth()); 165 166 EXPECT_MAT_NEAR(disp_gold, h_disp, 1.0); 167} 168 169INSTANTIATE_TEST_CASE_P(CUDA_Stereo, StereoConstantSpaceBP, ALL_DEVICES); 170 171//////////////////////////////////////////////////////////////////////////////// 172// reprojectImageTo3D 173 174PARAM_TEST_CASE(ReprojectImageTo3D, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) 175{ 176 cv::cuda::DeviceInfo devInfo; 177 cv::Size size; 178 int depth; 179 bool useRoi; 180 181 virtual void SetUp() 182 { 183 devInfo = GET_PARAM(0); 184 size = GET_PARAM(1); 185 depth = GET_PARAM(2); 186 useRoi = GET_PARAM(3); 187 188 cv::cuda::setDevice(devInfo.deviceID()); 189 } 190}; 191 192CUDA_TEST_P(ReprojectImageTo3D, Accuracy) 193{ 194 cv::Mat disp = randomMat(size, depth, 5.0, 30.0); 195 cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0); 196 197 cv::cuda::GpuMat dst; 198 cv::cuda::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3); 199 200 cv::Mat dst_gold; 201 cv::reprojectImageTo3D(disp, dst_gold, Q, false); 202 203 EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); 204} 205 206INSTANTIATE_TEST_CASE_P(CUDA_Stereo, ReprojectImageTo3D, testing::Combine( 207 ALL_DEVICES, 208 DIFFERENT_SIZES, 209 testing::Values(MatDepth(CV_8U), MatDepth(CV_16S)), 210 WHOLE_SUBMAT)); 211 212#endif // HAVE_CUDA 213