removed warnings clip tab warning fixed fixed tab size warning added a new sample the new sample fixed spacing problem added a testing for the penalties fixed sample warning fixed last warnings added tests and modified a bit the sources added the tests fixed warning removed redundant samples Rename Sample3.cpp to sample.cpp renamed from Sample3 to sample refactored sample repaired descriptor test added test data usless info erased from test block matching added last tests did some modifications to the files whitespace removal did some modifications to the testing files fixed test descriptor issue Revert "whitespace removal" This reverts commit 76d4aa530fee8f7444de6c80ecb4fc9c80ec0677. corrected part of the comments made modifications so the sources build successfully fixed some issue for sub pixel refactored sample fixed small issue at testing added some performance files performance tests and other corrections corrected the paths and added some images fixed a bug Delete imgKitty.bmp Delete imgKittyl.bmp performance tests again.... added larger images fixed issues did some last changes added the copyright notice fixed some linux errorspull/326/head
@ -0,0 +1,118 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::stereo; |
||||
using namespace perf; |
||||
|
||||
typedef std::tr1::tuple<Size, MatType, MatDepth> s_bm_test_t; |
||||
typedef perf::TestBaseWithParam<s_bm_test_t> s_bm; |
||||
|
||||
PERF_TEST_P( s_bm, sgm_perf, |
||||
testing::Combine( |
||||
testing::Values( cv::Size(512, 283), cv::Size(320, 240)), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_8UC1,CV_8U,CV_16S ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
|
||||
Mat left(sz, matType); |
||||
Mat right(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
Ptr<StereoBinarySGBM> sgbm = StereoBinarySGBM::create(0, 16, 5); |
||||
sgbm->setBinaryKernelType(CV_DENSE_CENSUS); |
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.1) |
||||
.iterations(20); |
||||
TEST_CYCLE() |
||||
{ |
||||
sgbm->compute(left, right, out1); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
||||
PERF_TEST_P( s_bm, bm_perf, |
||||
testing::Combine( |
||||
testing::Values( cv::Size(512, 383), cv::Size(320, 240) ), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_8UC1,CV_8U ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
|
||||
Mat left(sz, matType); |
||||
Mat right(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
Ptr<StereoBinaryBM> sbm = StereoBinaryBM::create(16, 9); |
||||
// we set the corresponding parameters
|
||||
sbm->setPreFilterCap(31); |
||||
sbm->setMinDisparity(0); |
||||
sbm->setTextureThreshold(10); |
||||
sbm->setUniquenessRatio(0); |
||||
sbm->setSpeckleWindowSize(400); |
||||
sbm->setDisp12MaxDiff(0); |
||||
sbm->setAgregationWindowSize(11); |
||||
// the user can choose between the average speckle removal algorithm or
|
||||
// the classical version that was implemented in OpenCV
|
||||
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); |
||||
sbm->setUsePrefilter(false); |
||||
|
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.1) |
||||
.iterations(20); |
||||
TEST_CYCLE() |
||||
{ |
||||
sbm->compute(left, right, out1); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
@ -0,0 +1,143 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::stereo; |
||||
using namespace perf; |
||||
|
||||
typedef std::tr1::tuple<Size, MatType, MatDepth> descript_params_t; |
||||
typedef perf::TestBaseWithParam<descript_params_t> descript_params; |
||||
|
||||
PERF_TEST_P( descript_params, census_sparse_descriptor, |
||||
testing::Combine( |
||||
testing::Values( TYPICAL_MAT_SIZES ), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_32SC4,CV_32S ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
Mat left(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.01); |
||||
TEST_CYCLE() |
||||
{ |
||||
censusTransform(left,9,out1,CV_SPARSE_CENSUS); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
||||
PERF_TEST_P( descript_params, star_census_transform, |
||||
testing::Combine( |
||||
testing::Values( TYPICAL_MAT_SIZES ), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_32SC4,CV_32S ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
Mat left(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.01); |
||||
TEST_CYCLE() |
||||
{ |
||||
starCensusTransform(left,9,out1); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
||||
PERF_TEST_P( descript_params, modified_census_transform, |
||||
testing::Combine( |
||||
testing::Values( TYPICAL_MAT_SIZES ), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_32SC4,CV_32S ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
|
||||
Mat left(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
|
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.01); |
||||
TEST_CYCLE() |
||||
{ |
||||
modifiedCensusTransform(left,9,out1,CV_MODIFIED_CENSUS_TRANSFORM); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
||||
PERF_TEST_P( descript_params, center_symetric_census, |
||||
testing::Combine( |
||||
testing::Values( TYPICAL_MAT_SIZES ), |
||||
testing::Values( CV_8UC1,CV_8U ), |
||||
testing::Values( CV_32SC4,CV_32S ) |
||||
) |
||||
) |
||||
{ |
||||
Size sz = std::tr1::get<0>(GetParam()); |
||||
int matType = std::tr1::get<1>(GetParam()); |
||||
int sdepth = std::tr1::get<2>(GetParam()); |
||||
|
||||
Mat left(sz, matType); |
||||
Mat out1(sz, sdepth); |
||||
|
||||
declare.in(left, WARMUP_RNG) |
||||
.out(out1) |
||||
.time(0.01); |
||||
TEST_CYCLE() |
||||
{ |
||||
symetricCensusTransform(left,7,out1,CV_CS_CENSUS); |
||||
} |
||||
SANITY_CHECK(out1); |
||||
} |
@ -0,0 +1,44 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
#include "perf_precomp.hpp" |
||||
|
||||
CV_PERF_TEST_MAIN(stereo) |
@ -0,0 +1,32 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__ |
||||
#define __OPENCV_PERF_PRECOMP_HPP__ |
||||
|
||||
#include <iostream> |
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/stereo.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/features2d.hpp" |
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
#include "opencv2/core/cvdef.h" |
||||
#include "opencv2/core.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include "opencv2/calib3d.hpp" |
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY |
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined |
||||
#endif |
||||
|
||||
#endif |
@ -1,78 +0,0 @@ |
||||
#include <iostream> |
||||
#include "opencv2/stereo.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace stereo; |
||||
using namespace std; |
||||
|
||||
//in this example we will load a sequence of images from a file process them and display the result on the screen
|
||||
//the descriptor used is the modified_census transform
|
||||
|
||||
int main(int, char**) |
||||
{ |
||||
//begin the program
|
||||
cout << " Running Main function \n"; |
||||
//declare 2 images
|
||||
Mat image1, image2; |
||||
|
||||
// -- 1. Call the constructor for StereoBinaryBM
|
||||
int ndisparities = 32; /**< Range of disparity */ |
||||
int kernelSize = 9; /**< Size of the block window. Must be odd */ |
||||
|
||||
Ptr<StereoBinaryBM> sbm = StereoBinaryBM::create(ndisparities, kernelSize); |
||||
|
||||
// -- 2. Set parameters
|
||||
sbm->setPreFilterCap(31); |
||||
sbm->setMinDisparity(0); |
||||
sbm->setTextureThreshold(10); |
||||
sbm->setUniquenessRatio(0); |
||||
sbm->setSpeckleWindowSize(400);//speckle size
|
||||
sbm->setSpeckleRange(200); |
||||
sbm->setDisp12MaxDiff(0); |
||||
sbm->setScalleFactor(4);//the scalling factor
|
||||
sbm->setBinaryKernelType(CV_MODIFIED_CENSUS_TRANSFORM);//binary descriptor kernel
|
||||
sbm->setAgregationWindowSize(9); |
||||
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM);//speckle removal algorithm
|
||||
sbm->setUsePrefilter(false);//prefilter or not the images prior to making the transformations
|
||||
|
||||
for(int i = 0 ; i < 200; i++) |
||||
{ |
||||
string path = "D:\\WorkingSec"; |
||||
string left = "l.bmp"; |
||||
string right = ".bmp"; |
||||
|
||||
std::string s; |
||||
std::stringstream out; |
||||
out << i; |
||||
s = out.str(); |
||||
|
||||
string finLeft = path + "\\rezult" + s + left; |
||||
string finRigth = path + "\\rezult" + s + right; |
||||
|
||||
image1 = imread(finLeft, CV_8UC1); |
||||
image2 = imread(finRigth, CV_8UC1); |
||||
//set a certain region of interest
|
||||
Rect region_of_interest = Rect(0, 20, image1.cols, (image1.rows - 20 - 110)); |
||||
|
||||
Mat imgLeft = image1(region_of_interest); |
||||
Mat imgRight = image2(region_of_interest); |
||||
|
||||
Mat imgDisparity8U = Mat(imgLeft.rows, imgLeft.cols, CV_8UC1); |
||||
if (imgLeft.empty() || imgRight.empty()) |
||||
{ |
||||
std::cout << " --(!) Error reading images \n" ; return -1; |
||||
} |
||||
////-- 3. Calculate the disparity image
|
||||
sbm->compute(imgLeft, imgRight, imgDisparity8U); |
||||
|
||||
imshow("RealImage", image1); |
||||
imshow("Disparity", imgDisparity8U); |
||||
waitKey(1); |
||||
} |
||||
|
||||
waitKey(0); |
||||
return 0; |
||||
} |
@ -1,61 +0,0 @@ |
||||
#include <iostream> |
||||
#include "opencv2/stereo.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace stereo; |
||||
using namespace std; |
||||
|
||||
|
||||
int main(int, char**) |
||||
{ |
||||
//begin the program
|
||||
cout << " Running Main function \n"; |
||||
//declare 2 images
|
||||
Mat image1, image2; |
||||
|
||||
// -- 1. Call the constructor for StereoBinaryBM
|
||||
int ndisparities = 32; /**< Range of disparity */ |
||||
int kernelSize = 9; /**< Size of the block window. Must be odd */ |
||||
|
||||
Ptr<StereoBinaryBM> sbm = StereoBinaryBM::create(ndisparities, kernelSize); |
||||
|
||||
// -- 2. Set parameters
|
||||
sbm->setPreFilterCap(31); |
||||
sbm->setMinDisparity(0); |
||||
sbm->setTextureThreshold(10); |
||||
sbm->setUniquenessRatio(0); |
||||
sbm->setSpeckleWindowSize(400);//speckle size
|
||||
sbm->setSpeckleRange(200); |
||||
sbm->setDisp12MaxDiff(0); |
||||
sbm->setScalleFactor(4);//the scalling factor
|
||||
sbm->setBinaryKernelType(CV_MEAN_VARIATION);//binary descriptor kernel
|
||||
sbm->setAgregationWindowSize(9); |
||||
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM);//speckle removal algorithm
|
||||
sbm->setUsePrefilter(false);//prefilter or not the images prior to making the transformations
|
||||
|
||||
//load 2 images from disc
|
||||
image1 = imread("D:\\rezult0l.bmp", CV_8UC1); |
||||
image2 = imread("D:\\rezult0.bmp", CV_8UC1); |
||||
//set a certain region of interest
|
||||
Rect region_of_interest = Rect(0, 20, image1.cols, (image1.rows - 20 - 110)); |
||||
|
||||
Mat imgLeft = image1(region_of_interest); |
||||
Mat imgRight = image2(region_of_interest); |
||||
|
||||
Mat imgDisparity8U = Mat(imgLeft.rows, imgLeft.cols, CV_8UC1); |
||||
if (imgLeft.empty() || imgRight.empty()) |
||||
{ |
||||
std::cout << " --(!) Error reading images \n" ; return -1; |
||||
} |
||||
////-- 3. Calculate the disparity image
|
||||
sbm->compute(imgLeft, imgRight, imgDisparity8U); |
||||
|
||||
imshow("RealImage", image1); |
||||
imshow("Disparity", imgDisparity8U); |
||||
|
||||
waitKey(0); |
||||
return 0; |
||||
} |
@ -0,0 +1,185 @@ |
||||
#include "opencv2/stereo.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <iostream> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::stereo; |
||||
|
||||
enum { STEREO_BINARY_BM, STEREO_BINARY_SGM }; |
||||
static cv::CommandLineParser parse_argument_values(int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities, |
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type); |
||||
int main(int argc, char** argv) |
||||
{ |
||||
string left, right; |
||||
int kernel_size = 0, number_of_disparities = 0, aggregation_window = 0, P1 = 0, P2 = 0; |
||||
float scale = 4; |
||||
int algo = STEREO_BINARY_BM; |
||||
int binary_descriptor_type = 0; |
||||
// here we extract the values that were added as arguments
|
||||
// we also test to see if they are provided correcly
|
||||
cv::CommandLineParser parser = |
||||
parse_argument_values(argc, argv, left, right, |
||||
kernel_size, |
||||
number_of_disparities, |
||||
aggregation_window, |
||||
P1, P2, |
||||
scale, |
||||
algo, binary_descriptor_type); |
||||
|
||||
if (!parser.check()) |
||||
{ |
||||
parser.printMessage(); |
||||
return 1; |
||||
} |
||||
int fail = 0; |
||||
//TEST if the provided parameters are correct
|
||||
if(binary_descriptor_type == CV_DENSE_CENSUS && kernel_size > 5) |
||||
{ |
||||
cout << "For the dense census transform the maximum kernel size should be 5\n"; |
||||
fail = 1; |
||||
} |
||||
if((binary_descriptor_type == CV_MEAN_VARIATION || binary_descriptor_type == CV_MODIFIED_CENSUS_TRANSFORM || binary_descriptor_type == CV_STAR_KERNEL) && kernel_size != 9) |
||||
{ |
||||
cout <<" For Mean variation and the modified census transform the kernel size should be equal to 9\n"; |
||||
fail = 1; |
||||
} |
||||
if((binary_descriptor_type == CV_CS_CENSUS || binary_descriptor_type == CV_MODIFIED_CS_CENSUS) && kernel_size > 7) |
||||
{ |
||||
cout << " The kernel size should be smaller or equal to 7 for the CS census and modified center symetric census\n"; |
||||
fail = 1; |
||||
} |
||||
if(binary_descriptor_type == CV_SPARSE_CENSUS && kernel_size > 11) |
||||
{ |
||||
cout << "The kernel size for the sparse census must be smaller or equal to 11\n"; |
||||
fail = 1; |
||||
} |
||||
|
||||
if(number_of_disparities < 10) |
||||
{ |
||||
cout << "Number of disparities should be greater than 10\n"; |
||||
fail = 1; |
||||
} |
||||
if(P2 / P1 < 2) |
||||
{ |
||||
cout << "You should probabilly choose a greater P2 penalty\n"; |
||||
fail = 1; |
||||
} |
||||
if(fail == 1) |
||||
{ |
||||
return 1; |
||||
} |
||||
// verify if the user inputs the correct number of parameters
|
||||
Mat image1, image2; |
||||
// we read a pair of images from the disk
|
||||
image1 = imread(left, CV_8UC1); |
||||
image2 = imread(right, CV_8UC1); |
||||
// verify if they are loaded correctly
|
||||
if (image1.empty() || image2.empty()) |
||||
{ |
||||
cout << " --(!) Error reading images \n"; |
||||
|
||||
parser.printMessage(); |
||||
return 1; |
||||
} |
||||
|
||||
// we display the parsed parameters
|
||||
const char *b[7] = { "CV_DENSE_CENSUS", "CV_SPARSE_CENSUS", "CV_CS_CENSUS", "CV_MODIFIED_CS_CENSUS", |
||||
"CV_MODIFIED_CENSUS_TRANSFORM", "CV_MEAN_VARIATION", "CV_STAR_KERNEL" }; |
||||
cout << "Program Name: " << argv[0]; |
||||
cout << "\nPath to left image " << left << " \n" << "Path to right image " << right << "\n"; |
||||
cout << "\nkernel size " << kernel_size << "\n" |
||||
<< "numberOfDisparities " << number_of_disparities << "\n" |
||||
<< "aggregationWindow " << aggregation_window << "\n" |
||||
<< "scallingFactor " << scale << "\n" << "Descriptor name : " << b[binary_descriptor_type] << "\n"; |
||||
|
||||
Mat imgDisparity16S2 = Mat(image1.rows, image1.cols, CV_16S); |
||||
Mat imgDisparity8U2 = Mat(image1.rows, image1.cols, CV_8UC1); |
||||
imshow("Original Left image", image1); |
||||
|
||||
if (algo == STEREO_BINARY_BM) |
||||
{ |
||||
Ptr<StereoBinaryBM> sbm = StereoBinaryBM::create(number_of_disparities, kernel_size); |
||||
// we set the corresponding parameters
|
||||
sbm->setPreFilterCap(31); |
||||
sbm->setMinDisparity(0); |
||||
sbm->setTextureThreshold(10); |
||||
sbm->setUniquenessRatio(0); |
||||
sbm->setSpeckleWindowSize(400); // speckle size
|
||||
sbm->setSpeckleRange(200); |
||||
sbm->setDisp12MaxDiff(0); |
||||
sbm->setScalleFactor((int)scale); // the scaling factor
|
||||
sbm->setBinaryKernelType(binary_descriptor_type); // binary descriptor kernel
|
||||
sbm->setAgregationWindowSize(aggregation_window); |
||||
// the user can choose between the average speckle removal algorithm or
|
||||
// the classical version that was implemented in OpenCV
|
||||
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); |
||||
sbm->setUsePrefilter(false); |
||||
//-- calculate the disparity image
|
||||
sbm->compute(image1, image2, imgDisparity8U2); |
||||
imshow("Disparity", imgDisparity8U2); |
||||
} |
||||
else if (algo == STEREO_BINARY_SGM) |
||||
{ |
||||
// we set the corresponding parameters
|
||||
Ptr<StereoBinarySGBM> sgbm = StereoBinarySGBM::create(0, number_of_disparities, kernel_size); |
||||
// setting the penalties for sgbm
|
||||
sgbm->setP1(P1); |
||||
sgbm->setP2(P2); |
||||
sgbm->setMinDisparity(0); |
||||
sgbm->setUniquenessRatio(5); |
||||
sgbm->setSpeckleWindowSize(400); |
||||
sgbm->setSpeckleRange(0); |
||||
sgbm->setDisp12MaxDiff(1); |
||||
sgbm->setBinaryKernelType(binary_descriptor_type); |
||||
sgbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); |
||||
sgbm->setSubPixelInterpolationMethod(CV_SIMETRICV_INTERPOLATION); |
||||
sgbm->compute(image1, image2, imgDisparity16S2); |
||||
/*Alternative for scalling
|
||||
imgDisparity16S2.convertTo(imgDisparity8U2, CV_8UC1, scale); |
||||
*/ |
||||
double minVal; double maxVal; |
||||
minMaxLoc(imgDisparity16S2, &minVal, &maxVal); |
||||
imgDisparity16S2.convertTo(imgDisparity8U2, CV_8UC1, 255 / (maxVal - minVal)); |
||||
//show the disparity image
|
||||
imshow("Windowsgm", imgDisparity8U2); |
||||
} |
||||
waitKey(0); |
||||
return 0; |
||||
} |
||||
static cv::CommandLineParser parse_argument_values(int argc, char **argv, string &left, string &right, int &kernel_size, int &number_of_disparities, |
||||
int &aggregation_window, int &P1, int &P2, float &scale, int &algo, int &binary_descriptor_type) |
||||
{ |
||||
static const char* keys = |
||||
"{ @left | | }" |
||||
"{ @right | | }" |
||||
"{ k kernel_size | 9 | }" |
||||
"{ d disparity | 128 | }" |
||||
"{ w aggregation_window | 9 | }" |
||||
"{ P1 | 100 | }" |
||||
"{ P2 | 1000 | }" |
||||
"{ b binary_descriptor | 4 | Index of the descriptor type:\n 0 - CV_DENSE_CENSUS,\n 1 - CV_SPARSE_CENSUS,\n 2 - CV_CS_CENSUS,\n 3 - CV_MODIFIED_CS_CENSUS,\n 4 - CV_MODIFIED_CENSUS_TRANSFORM,\n 5 - CV_MEAN_VARIATION,\n 6 - CV_STAR_KERNEL}" |
||||
"{ s scale | 1.01593 | }" |
||||
"{ a algorithm | sgm | }" |
||||
; |
||||
|
||||
cv::CommandLineParser parser( argc, argv, keys ); |
||||
|
||||
left = parser.get<string>(0); |
||||
right = parser.get<string>(1); |
||||
kernel_size = parser.get<int>("kernel_size"); |
||||
number_of_disparities = parser.get<int>("disparity"); |
||||
aggregation_window = parser.get<int>("aggregation_window"); |
||||
P1 = parser.get<int>("P1"); |
||||
P2 = parser.get<int>("P2"); |
||||
binary_descriptor_type = parser.get<int>("binary_descriptor"); |
||||
scale = parser.get<float>("scale"); |
||||
algo = parser.get<string>("algorithm") == "sgm" ? STEREO_BINARY_SGM : STEREO_BINARY_BM; |
||||
|
||||
parser.about("\nDemo stereo matching converting L and R images into disparity images using BM and SGBM\n"); |
||||
|
||||
return parser; |
||||
} |
@ -0,0 +1,238 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include <limits.h> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::stereo; |
||||
using namespace std; |
||||
|
||||
class CV_BlockMatchingTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_BlockMatchingTest(); |
||||
~CV_BlockMatchingTest(); |
||||
protected: |
||||
void run(int /* idx */); |
||||
}; |
||||
|
||||
CV_BlockMatchingTest::CV_BlockMatchingTest(){} |
||||
CV_BlockMatchingTest::~CV_BlockMatchingTest(){} |
||||
|
||||
static double errorLevel(const Mat &ideal, Mat &actual) |
||||
{ |
||||
uint8_t *date, *harta; |
||||
harta = actual.data; |
||||
date = ideal.data; |
||||
int stride, h; |
||||
stride = (int)ideal.step; |
||||
h = ideal.rows; |
||||
int error = 0; |
||||
for (int i = 0; i < ideal.rows; i++) |
||||
{ |
||||
for (int j = 0; j < ideal.cols; j++) |
||||
{ |
||||
if (date[i * stride + j] != 0) |
||||
if (abs(date[i * stride + j] - harta[i * stride + j]) > 2 * 16) |
||||
{ |
||||
error += 1; |
||||
} |
||||
} |
||||
} |
||||
return ((double)((error * 100) * 1.0) / (stride * h)); |
||||
} |
||||
void CV_BlockMatchingTest::run(int ) |
||||
{ |
||||
Mat image1, image2, gt; |
||||
//some test images can be found in the test data folder
|
||||
image1 = imread(ts->get_data_path() + "testdata/imL2l.bmp", CV_8UC1); |
||||
image2 = imread(ts->get_data_path() + "testdata/imL2.bmp", CV_8UC1); |
||||
gt = imread(ts->get_data_path() + "testdata/groundtruth.bmp", CV_8UC1); |
||||
|
||||
if(image1.empty() || image2.empty() || gt.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(image1.rows != image2.rows || image1.cols != image2.cols || gt.cols != gt.cols || gt.rows != gt.rows) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output dimension \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
RNG range; |
||||
//set the parameters
|
||||
int binary_descriptor_type = range.uniform(0,8); |
||||
int kernel_size, aggregation_window; |
||||
if(binary_descriptor_type == 0) |
||||
kernel_size = 5; |
||||
else if(binary_descriptor_type == 2 || binary_descriptor_type == 3) |
||||
kernel_size = 7; |
||||
else if(binary_descriptor_type == 1) |
||||
kernel_size = 11; |
||||
else |
||||
kernel_size = 9; |
||||
if(binary_descriptor_type == 3) |
||||
aggregation_window = 13; |
||||
else |
||||
aggregation_window = 11; |
||||
Mat test = Mat(image1.rows, image1.cols, CV_8UC1); |
||||
Ptr<StereoBinaryBM> sbm = StereoBinaryBM::create(16, kernel_size); |
||||
//we set the corresponding parameters
|
||||
sbm->setPreFilterCap(31); |
||||
sbm->setMinDisparity(0); |
||||
sbm->setTextureThreshold(10); |
||||
sbm->setUniquenessRatio(0); |
||||
sbm->setSpeckleWindowSize(400);//speckle size
|
||||
sbm->setSpeckleRange(200); |
||||
sbm->setDisp12MaxDiff(0); |
||||
sbm->setScalleFactor(16);//the scaling factor
|
||||
sbm->setBinaryKernelType(binary_descriptor_type);//binary descriptor kernel
|
||||
sbm->setAgregationWindowSize(aggregation_window); |
||||
//speckle removal algorithm the user can choose between the average speckle removal algorithm
|
||||
//or the classical version that was implemented in open cv
|
||||
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); |
||||
sbm->setUsePrefilter(false);//pre-filter or not the images prior to making the transformations
|
||||
//-- calculate the disparity image
|
||||
sbm->compute(image1, image2, test); |
||||
if(test.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output dimension \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
if(errorLevel(gt,test) > 20) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, |
||||
"Too big error\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
class CV_SGBlockMatchingTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_SGBlockMatchingTest(); |
||||
~CV_SGBlockMatchingTest(); |
||||
protected: |
||||
void run(int /* idx */); |
||||
}; |
||||
|
||||
CV_SGBlockMatchingTest::CV_SGBlockMatchingTest(){} |
||||
CV_SGBlockMatchingTest::~CV_SGBlockMatchingTest(){} |
||||
|
||||
void CV_SGBlockMatchingTest::run(int ) |
||||
{ |
||||
Mat image1, image2, gt; |
||||
//some test images can be found in the test data folder
|
||||
image1 = imread(ts->get_data_path() + "testdata/imL2l.bmp", CV_8UC1); |
||||
image2 = imread(ts->get_data_path() + "testdata/imL2.bmp", CV_8UC1); |
||||
gt = imread(ts->get_data_path() + "testdata/groundtruth.bmp", CV_8UC1); |
||||
|
||||
|
||||
if(image1.empty() || image2.empty() || gt.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(image1.rows != image2.rows || image1.cols != image2.cols || gt.cols != gt.cols || gt.rows != gt.rows) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output dimension \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
RNG range; |
||||
//set the parameters
|
||||
int binary_descriptor_type = range.uniform(0,8); |
||||
int kernel_size; |
||||
if(binary_descriptor_type == 0) |
||||
kernel_size = 5; |
||||
else if(binary_descriptor_type == 2 || binary_descriptor_type == 3) |
||||
kernel_size = 7; |
||||
else if(binary_descriptor_type == 1) |
||||
kernel_size = 11; |
||||
else |
||||
kernel_size = 9; |
||||
|
||||
Mat test = Mat(image1.rows, image1.cols, CV_8UC1); |
||||
Mat imgDisparity16S2 = Mat(image1.rows, image1.cols, CV_16S); |
||||
Ptr<StereoBinarySGBM> sgbm = StereoBinarySGBM::create(0, 16, kernel_size); |
||||
//setting the penalties for sgbm
|
||||
sgbm->setP1(10); |
||||
sgbm->setP2(100); |
||||
sgbm->setMinDisparity(0); |
||||
sgbm->setNumDisparities(16);//set disparity number
|
||||
sgbm->setUniquenessRatio(1); |
||||
sgbm->setSpeckleWindowSize(400); |
||||
sgbm->setSpeckleRange(200); |
||||
sgbm->setDisp12MaxDiff(1); |
||||
sgbm->setBinaryKernelType(binary_descriptor_type);//set the binary descriptor
|
||||
sgbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); //the avg speckle removal algorithm
|
||||
sgbm->setSubPixelInterpolationMethod(CV_SIMETRICV_INTERPOLATION);// the SIMETRIC V interpolation method
|
||||
sgbm->compute(image1, image2, imgDisparity16S2); |
||||
double minVal; double maxVal; |
||||
minMaxLoc(imgDisparity16S2, &minVal, &maxVal); |
||||
|
||||
imgDisparity16S2.convertTo(test, CV_8UC1, 255 / (maxVal - minVal)); |
||||
|
||||
if(test.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output dimension \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
double error = errorLevel(gt,test); |
||||
if(error > 10) |
||||
{ |
||||
ts->printf( cvtest::TS::LOG, |
||||
"Too big error\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); |
||||
return; |
||||
} |
||||
} |
||||
TEST(block_matching_simple_test, accuracy) { CV_BlockMatchingTest test; test.safe_run(); } |
||||
TEST(SG_block_matching_simple_test, accuracy) { CV_SGBlockMatchingTest test; test.safe_run(); } |
@ -0,0 +1,466 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include <limits.h> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::stereo; |
||||
using namespace std; |
||||
|
||||
class CV_DescriptorBaseTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_DescriptorBaseTest(); |
||||
~CV_DescriptorBaseTest(); |
||||
protected: |
||||
virtual void imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2) = 0; |
||||
virtual void imageTransformation(const Mat &img1, Mat &out1) = 0; |
||||
void testROI(const Mat &img); |
||||
void testMonotonicity(const Mat &img, Mat &out); |
||||
void run(int ); |
||||
Mat censusImage[2]; |
||||
Mat censusImageSingle[2]; |
||||
Mat left; |
||||
Mat right; |
||||
int kernel_size, descriptor_type; |
||||
}; |
||||
//we test to see if the descriptor applied on a roi
|
||||
//has the same value with the descriptor from the original image
|
||||
//tested at the roi boundaries
|
||||
void CV_DescriptorBaseTest::testROI(const Mat &img) |
||||
{ |
||||
int pt, pb,w,h; |
||||
//initialize random values for the roi top and bottom
|
||||
pt = rand() % 100; |
||||
pb = rand() % 100; |
||||
//calculate the new width and height
|
||||
w = img.cols; |
||||
h = img.rows - pt - pb; |
||||
int start = pt + kernel_size / 2 + 1; |
||||
int stop = h - kernel_size/2 - 1; |
||||
//set the region of interest according to above values
|
||||
Rect region_of_interest = Rect(0, pt, w, h); |
||||
Mat image_roi1 = img(region_of_interest); |
||||
Mat p1,p2; |
||||
//create 2 images where to put our output
|
||||
p1.create(image_roi1.rows, image_roi1.cols, CV_32SC4); |
||||
p2.create(img.rows, img.cols, CV_32SC4); |
||||
imageTransformation(image_roi1,p1); |
||||
imageTransformation(img,p2); |
||||
int *roi_data = (int *)p1.data; |
||||
int *img_data = (int *)p2.data; |
||||
//verify result
|
||||
for(int i = start; i < stop; i++) |
||||
{ |
||||
for(int j = 0; j < w ; j++) |
||||
{ |
||||
if(roi_data[(i - pt) * w + j] != img_data[(i) * w + j]) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Something wrong with ROI \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
CV_DescriptorBaseTest::~CV_DescriptorBaseTest() |
||||
{ |
||||
left.release(); |
||||
right.release(); |
||||
censusImage[0].release(); |
||||
censusImage[1].release(); |
||||
censusImageSingle[0].release(); |
||||
censusImageSingle[1].release(); |
||||
} |
||||
CV_DescriptorBaseTest::CV_DescriptorBaseTest() |
||||
{ |
||||
//read 2 images from file
|
||||
//two test images can be found in the test data folder
|
||||
left = imread(ts->get_data_path() + "testdata/imL2l.bmp", CV_8UC1); |
||||
right = imread(ts->get_data_path() + "testdata/imL2.bmp", CV_8UC1); |
||||
|
||||
if(left.empty() || right.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
ts->printf(cvtest::TS::LOG, "Data loaded \n"); |
||||
} |
||||
//verify if we don't have an image with all pixels the same( except when all input pixels are equal)
|
||||
void CV_DescriptorBaseTest::testMonotonicity(const Mat &img, Mat &out) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img.rows != out.rows || img.cols != out.cols || img.empty() || out.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output dimension \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
//verify that for an input image with different pxels the values of the
|
||||
//output pixels are not the same
|
||||
int same = 0; |
||||
uint8_t *data = img.data; |
||||
uint8_t val = data[1]; |
||||
int stride = (int)img.step; |
||||
for(int i = 0 ; i < img.rows && !same; i++) |
||||
{ |
||||
for(int j = 0; j < img.cols; j++) |
||||
{ |
||||
if(val != data[i * stride + j]) |
||||
{ |
||||
same = 1; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
int value_descript = out.data[1]; |
||||
int accept = 0; |
||||
uint8_t *outData = out.data; |
||||
for(int i = 0 ; i < img.rows && !accept; i++) |
||||
{ |
||||
for(int j = 0; j < img.cols; j++) |
||||
{ |
||||
//we verify for the output image if the iage pixels are not all the same of an input
|
||||
//image with different pixels
|
||||
if(value_descript != outData[i * stride + j] && same) |
||||
{ |
||||
//if we found a value that is different we accept
|
||||
accept = 1; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
if(accept == 1 && same == 0) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
ts->printf(cvtest::TS::LOG, "The image has all values the same \n"); |
||||
return; |
||||
} |
||||
if(accept == 0 && same == 1) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
ts->printf(cvtest::TS::LOG, "For correct image we get all descriptor values the same \n"); |
||||
return; |
||||
} |
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
} |
||||
|
||||
///////////////////////////////////
|
||||
//census transform
|
||||
|
||||
class CV_CensusTransformTest: public CV_DescriptorBaseTest |
||||
{ |
||||
public: |
||||
CV_CensusTransformTest(); |
||||
protected: |
||||
void imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2); |
||||
void imageTransformation(const Mat &img1, Mat &out1); |
||||
}; |
||||
|
||||
CV_CensusTransformTest::CV_CensusTransformTest() |
||||
{ |
||||
kernel_size = 11; |
||||
descriptor_type = CV_SPARSE_CENSUS; |
||||
} |
||||
void CV_CensusTransformTest::imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty() |
||||
|| img2.rows != out2.rows || img2.cols != out2.cols || img2.empty() || out2.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
censusTransform(img1,img2,kernel_size,out1,out2,descriptor_type); |
||||
|
||||
} |
||||
void CV_CensusTransformTest::imageTransformation(const Mat &img1, Mat &out1) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
censusTransform(img1,kernel_size,out1,descriptor_type); |
||||
} |
||||
//////////////////////////////////
|
||||
//symetric census
|
||||
|
||||
class CV_SymetricCensusTest: public CV_DescriptorBaseTest |
||||
{ |
||||
public: |
||||
CV_SymetricCensusTest(); |
||||
protected: |
||||
void imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2); |
||||
void imageTransformation(const Mat &img1, Mat &out1); |
||||
}; |
||||
CV_SymetricCensusTest::CV_SymetricCensusTest() |
||||
{ |
||||
kernel_size = 7; |
||||
descriptor_type = CV_CS_CENSUS; |
||||
} |
||||
void CV_SymetricCensusTest::imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty() |
||||
|| img2.rows != out2.rows || img2.cols != out2.cols || img2.empty() || out2.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
symetricCensusTransform(img1,img2,kernel_size,out1,out2,descriptor_type); |
||||
} |
||||
void CV_SymetricCensusTest::imageTransformation(const Mat &img1, Mat &out1) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
symetricCensusTransform(img1,kernel_size,out1,descriptor_type); |
||||
} |
||||
//////////////////////////////////
|
||||
//modified census transform
|
||||
class CV_ModifiedCensusTransformTest: public CV_DescriptorBaseTest |
||||
{ |
||||
public: |
||||
CV_ModifiedCensusTransformTest(); |
||||
protected: |
||||
void imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2); |
||||
void imageTransformation(const Mat &img1, Mat &out1); |
||||
}; |
||||
CV_ModifiedCensusTransformTest::CV_ModifiedCensusTransformTest() |
||||
{ |
||||
kernel_size = 9; |
||||
descriptor_type = CV_MODIFIED_CENSUS_TRANSFORM; |
||||
} |
||||
void CV_ModifiedCensusTransformTest::imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty() |
||||
|| img2.rows != out2.rows || img2.cols != out2.cols || img2.empty() || out2.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
modifiedCensusTransform(img1,img2,kernel_size,out1,out2,descriptor_type); |
||||
} |
||||
void CV_ModifiedCensusTransformTest::imageTransformation(const Mat &img1, Mat &out1) |
||||
{ |
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
modifiedCensusTransform(img1,kernel_size,out1,descriptor_type); |
||||
} |
||||
//////////////////////////////////
|
||||
//star kernel census
|
||||
class CV_StarKernelCensusTest: public CV_DescriptorBaseTest |
||||
{ |
||||
public: |
||||
CV_StarKernelCensusTest(); |
||||
protected: |
||||
void imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2); |
||||
void imageTransformation(const Mat &img1, Mat &out1); |
||||
}; |
||||
CV_StarKernelCensusTest :: CV_StarKernelCensusTest() |
||||
{ |
||||
kernel_size = 9; |
||||
descriptor_type = CV_STAR_KERNEL; |
||||
} |
||||
void CV_StarKernelCensusTest :: imageTransformation(const Mat &img1, const Mat &img2, Mat &out1, Mat &out2) |
||||
{ |
||||
//verify if input data is correct
|
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty() |
||||
|| img2.rows != out2.rows || img2.cols != out2.cols || img2.empty() || out2.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
starCensusTransform(img1,img2,kernel_size,out1,out2); |
||||
} |
||||
void CV_StarKernelCensusTest::imageTransformation(const Mat &img1, Mat &out1) |
||||
{ |
||||
if(img1.rows != out1.rows || img1.cols != out1.cols || img1.empty() || out1.empty()) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong input / output data \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
if(kernel_size % 2 == 0) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "Wrong kernel size;Kernel should be odd \n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
starCensusTransform(img1,kernel_size,out1); |
||||
} |
||||
|
||||
void CV_DescriptorBaseTest::run(int ) |
||||
{ |
||||
if (left.empty() || right.empty()) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
ts->printf(cvtest::TS::LOG, "No input images detected\n"); |
||||
return; |
||||
} |
||||
testROI(left); |
||||
|
||||
censusImage[0].create(left.rows, left.cols, CV_32SC4); |
||||
censusImage[1].create(left.rows, left.cols, CV_32SC4); |
||||
censusImageSingle[0].create(left.rows, left.cols, CV_32SC4); |
||||
censusImageSingle[1].create(left.rows, left.cols, CV_32SC4); |
||||
censusImage[0].setTo(0); |
||||
censusImage[1].setTo(0); |
||||
censusImageSingle[0].setTo(0); |
||||
censusImageSingle[1].setTo(0); |
||||
|
||||
imageTransformation(left, right, censusImage[0], censusImage[1]); |
||||
imageTransformation(left, censusImageSingle[0]); |
||||
imageTransformation(right, censusImageSingle[1]); |
||||
testMonotonicity(left,censusImage[0]); |
||||
testMonotonicity(right,censusImage[1]); |
||||
testMonotonicity(left,censusImageSingle[0]); |
||||
testMonotonicity(right,censusImageSingle[1]); |
||||
|
||||
if (censusImage[0].empty() || censusImage[1].empty() || censusImageSingle[0].empty() || censusImageSingle[1].empty()) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
ts->printf(cvtest::TS::LOG, "The descriptor images are empty \n"); |
||||
return; |
||||
} |
||||
int *datl1 = (int *)censusImage[0].data; |
||||
int *datr1 = (int *)censusImage[1].data; |
||||
int *datl2 = (int *)censusImageSingle[0].data; |
||||
int *datr2 = (int *)censusImageSingle[1].data; |
||||
for(int i = 0; i < censusImage[0].rows - kernel_size/ 2; i++) |
||||
{ |
||||
for(int j = 0; j < censusImage[0].cols; j++) |
||||
{ |
||||
if(datl1[i * censusImage[0].cols + j] != datl2[i * censusImage[0].cols + j]) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
ts->printf(cvtest::TS::LOG, "Mismatch for left images %d \n",descriptor_type); |
||||
return; |
||||
} |
||||
if(datr1[i * censusImage[0].cols + j] != datr2[i * censusImage[0].cols + j]) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
ts->printf(cvtest::TS::LOG, "Mismatch for right images %d \n",descriptor_type); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
int min = numeric_limits<int>::min(); |
||||
int max = numeric_limits<int>::max(); |
||||
//check if all values are between int min and int max and not NAN
|
||||
if (0 != cvtest::check(censusImage[0], min, max, 0)) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
//check if all values are between int min and int max and not NAN
|
||||
if (0 != cvtest::check(censusImage[1], min, max, 0)) |
||||
{ |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return ; |
||||
} |
||||
} |
||||
|
||||
TEST(census_transform_testing, accuracy) { CV_CensusTransformTest test; test.safe_run(); } |
||||
TEST(symetric_census_testing, accuracy) { CV_SymetricCensusTest test; test.safe_run(); } |
||||
TEST(modified_census_testing, accuracy) { CV_ModifiedCensusTransformTest test; test.safe_run(); } |
||||
TEST(star_kernel_testing, accuracy) { CV_StarKernelCensusTest test; test.safe_run(); } |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 457 KiB |
After Width: | Height: | Size: 457 KiB |
After Width: | Height: | Size: 192 KiB |
After Width: | Height: | Size: 192 KiB |