Path: blob/master/modules/calib3d/src/compat_stereo.cpp
16345 views
//M*//////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Copyright (C) 2013, OpenCV Foundation, all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "precomp.hpp"43#include "opencv2/calib3d/calib3d_c.h"4445CvStereoBMState* cvCreateStereoBMState( int /*preset*/, int numberOfDisparities )46{47CvStereoBMState* state = (CvStereoBMState*)cvAlloc( sizeof(*state) );48if( !state )49return 0;5051state->preFilterType = CV_STEREO_BM_XSOBEL; //CV_STEREO_BM_NORMALIZED_RESPONSE;52state->preFilterSize = 9;53state->preFilterCap = 31;54state->SADWindowSize = 15;55state->minDisparity = 0;56state->numberOfDisparities = numberOfDisparities > 0 ? numberOfDisparities : 64;57state->textureThreshold = 10;58state->uniquenessRatio = 15;59state->speckleRange = state->speckleWindowSize = 0;60state->trySmallerWindows = 0;61state->roi1 = state->roi2 = cvRect(0,0,0,0);62state->disp12MaxDiff = -1;6364state->preFilteredImg0 = state->preFilteredImg1 = state->slidingSumBuf =65state->disp = state->cost = 0;6667return state;68}6970void cvReleaseStereoBMState( CvStereoBMState** state )71{72if( !state )73CV_Error( CV_StsNullPtr, "" );7475if( !*state )76return;7778cvReleaseMat( &(*state)->preFilteredImg0 );79cvReleaseMat( &(*state)->preFilteredImg1 );80cvReleaseMat( &(*state)->slidingSumBuf );81cvReleaseMat( &(*state)->disp );82cvReleaseMat( &(*state)->cost );83cvFree( state );84}8586void cvFindStereoCorrespondenceBM( const CvArr* leftarr, const CvArr* rightarr,87CvArr* disparr, CvStereoBMState* state )88{89cv::Mat left = cv::cvarrToMat(leftarr), right = cv::cvarrToMat(rightarr);90const cv::Mat disp = cv::cvarrToMat(disparr);9192CV_Assert( state != 0 );9394cv::Ptr<cv::StereoBM> sm = cv::StereoBM::create(state->numberOfDisparities,95state->SADWindowSize);96sm->setPreFilterType(state->preFilterType);97sm->setPreFilterSize(state->preFilterSize);98sm->setPreFilterCap(state->preFilterCap);99sm->setBlockSize(state->SADWindowSize);100sm->setNumDisparities(state->numberOfDisparities > 0 ? state->numberOfDisparities : 64);101sm->setTextureThreshold(state->textureThreshold);102sm->setUniquenessRatio(state->uniquenessRatio);103sm->setSpeckleRange(state->speckleRange);104sm->setSpeckleWindowSize(state->speckleWindowSize);105sm->setDisp12MaxDiff(state->disp12MaxDiff);106107sm->compute(left, right, disp);108}109110CvRect cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,111int numberOfDisparities, int SADWindowSize )112{113return cvRect(cv::getValidDisparityROI( roi1, roi2, minDisparity,114numberOfDisparities, SADWindowSize));115}116117void cvValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,118int numberOfDisparities, int disp12MaxDiff )119{120cv::Mat disp = cv::cvarrToMat(_disp), cost = cv::cvarrToMat(_cost);121cv::validateDisparity( disp, cost, minDisparity, numberOfDisparities, disp12MaxDiff );122}123124125