Path: blob/master/modules/calib3d/perf/perf_stereosgbm.cpp
16337 views
/*1* By downloading, copying, installing or using the software you agree to this license.2* If you do not agree to this license, do not download, install,3* copy or use the software.4*5*6* License Agreement7* For Open Source Computer Vision Library8* (3 - clause BSD License)9*10* Redistribution and use in source and binary forms, with or without modification,11* are permitted provided that the following conditions are met :12*13* * Redistributions of source code must retain the above copyright notice,14* this list of conditions and the following disclaimer.15*16* * Redistributions in binary form must reproduce the above copyright notice,17* this list of conditions and the following disclaimer in the documentation18* and / or other materials provided with the distribution.19*20* * Neither the names of the copyright holders nor the names of the contributors21* may be used to endorse or promote products derived from this software22* without specific prior written permission.23*24* This software is provided by the copyright holders and contributors "as is" and25* any express or implied warranties, including, but not limited to, the implied26* warranties of merchantability and fitness for a particular purpose are disclaimed.27* In no event shall copyright holders or contributors be liable for any direct,28* indirect, incidental, special, exemplary, or consequential damages29* (including, but not limited to, procurement of substitute goods or services;30* loss of use, data, or profits; or business interruption) however caused31* and on any theory of liability, whether in contract, strict liability,32* or tort(including negligence or otherwise) arising in any way out of33* the use of this software, even if advised of the possibility of such damage.34*/3536#include "perf_precomp.hpp"3738namespace opencv_test39{40using namespace perf;41using namespace testing;4243static void MakeArtificialExample(RNG rng, Mat& dst_left_view, Mat& dst_view);4445CV_ENUM(SGBMModes, StereoSGBM::MODE_SGBM, StereoSGBM::MODE_SGBM_3WAY, StereoSGBM::MODE_HH4);46typedef tuple<Size, int, SGBMModes> SGBMParams;47typedef TestBaseWithParam<SGBMParams> TestStereoCorresp;4849#ifndef _DEBUG50PERF_TEST_P( TestStereoCorresp, SGBM, Combine(Values(Size(1280,720),Size(640,480)), Values(256,128), SGBMModes::all()) )51#else52PERF_TEST_P( TestStereoCorresp, DISABLED_TooLongInDebug_SGBM, Combine(Values(Size(1280,720),Size(640,480)), Values(256,128), SGBMModes::all()) )53#endif54{55RNG rng(0);5657SGBMParams params = GetParam();5859Size sz = get<0>(params);60int num_disparities = get<1>(params);61int mode = get<2>(params);6263Mat src_left(sz, CV_8UC3);64Mat src_right(sz, CV_8UC3);65Mat dst(sz, CV_16S);6667MakeArtificialExample(rng,src_left,src_right);6869int wsize = 3;70int P1 = 8*src_left.channels()*wsize*wsize;71TEST_CYCLE()72{73Ptr<StereoSGBM> sgbm = StereoSGBM::create(0,num_disparities,wsize,P1,4*P1,1,63,25,0,0,mode);74sgbm->compute(src_left,src_right,dst);75}7677SANITY_CHECK(dst, .01, ERROR_RELATIVE);78}7980void MakeArtificialExample(RNG rng, Mat& dst_left_view, Mat& dst_right_view)81{82int w = dst_left_view.cols;83int h = dst_left_view.rows;8485//params:86unsigned char bg_level = (unsigned char)rng.uniform(0.0,255.0);87unsigned char fg_level = (unsigned char)rng.uniform(0.0,255.0);88int rect_width = (int)rng.uniform(w/16,w/2);89int rect_height = (int)rng.uniform(h/16,h/2);90int rect_disparity = (int)(0.15*w);91double sigma = 3.0;9293int rect_x_offset = (w-rect_width) /2;94int rect_y_offset = (h-rect_height)/2;9596if(dst_left_view.channels()==3)97{98dst_left_view = Scalar(Vec3b(bg_level,bg_level,bg_level));99dst_right_view = Scalar(Vec3b(bg_level,bg_level,bg_level));100}101else102{103dst_left_view = Scalar(bg_level);104dst_right_view = Scalar(bg_level);105}106107Mat dst_left_view_rect = Mat(dst_left_view, Rect(rect_x_offset,rect_y_offset,rect_width,rect_height));108if(dst_left_view.channels()==3)109dst_left_view_rect = Scalar(Vec3b(fg_level,fg_level,fg_level));110else111dst_left_view_rect = Scalar(fg_level);112113rect_x_offset-=rect_disparity;114115Mat dst_right_view_rect = Mat(dst_right_view, Rect(rect_x_offset,rect_y_offset,rect_width,rect_height));116if(dst_right_view.channels()==3)117dst_right_view_rect = Scalar(Vec3b(fg_level,fg_level,fg_level));118else119dst_right_view_rect = Scalar(fg_level);120121//add some gaussian noise:122unsigned char *l, *r;123for(int i=0;i<h;i++)124{125l = dst_left_view.ptr(i);126r = dst_right_view.ptr(i);127128if(dst_left_view.channels()==3)129{130for(int j=0;j<w;j++)131{132l[0] = saturate_cast<unsigned char>(l[0] + rng.gaussian(sigma));133l[1] = saturate_cast<unsigned char>(l[1] + rng.gaussian(sigma));134l[2] = saturate_cast<unsigned char>(l[2] + rng.gaussian(sigma));135l+=3;136137r[0] = saturate_cast<unsigned char>(r[0] + rng.gaussian(sigma));138r[1] = saturate_cast<unsigned char>(r[1] + rng.gaussian(sigma));139r[2] = saturate_cast<unsigned char>(r[2] + rng.gaussian(sigma));140r+=3;141}142}143else144{145for(int j=0;j<w;j++)146{147l[0] = saturate_cast<unsigned char>(l[0] + rng.gaussian(sigma));148l++;149150r[0] = saturate_cast<unsigned char>(r[0] + rng.gaussian(sigma));151r++;152}153}154}155}156157}158159160