removed obsolete tests
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for cvtest. See root CMakeLists.txt
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
project(opencv_test)
|
||||
|
||||
file(GLOB test_srcs "src/*.cpp")
|
||||
source_group("Src" FILES ${test_srcs})
|
||||
file(GLOB test_hdrs "src/*.h*")
|
||||
source_group("Include" FILES ${test_hdrs})
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/include/opencv"
|
||||
"${CMAKE_SOURCE_DIR}/modules/core/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/imgproc/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/features2d/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/flann/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/calib3d/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/highgui/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/objdetect/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/video/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/legacy/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/contrib/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
include_directories(../cxts)
|
||||
|
||||
set(the_target "opencv_test")
|
||||
|
||||
add_executable(${the_target} ${test_srcs} ${test_hdrs})
|
||||
|
||||
if(PCHSupport_FOUND)
|
||||
set(pch_header ${CMAKE_SOURCE_DIR}/tests/cv/src/cvtest.h)
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
||||
set(${the_target}_pch "src/cvtest.cpp")
|
||||
endif()
|
||||
add_native_precompiled_header(${the_target} ${pch_header})
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
||||
add_precompiled_header(${the_target} ${pch_header})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Additional target properties
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||
)
|
||||
|
||||
|
||||
add_dependencies(${the_target} opencv_ts opencv_core opencv_imgproc opencv_calib3d opencv_features2d opencv_objdetect opencv_video opencv_highgui opencv_legacy opencv_contrib)
|
||||
|
||||
# Add the required libraries for linking:
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_ts opencv_core opencv_imgproc opencv_calib3d opencv_features2d opencv_objdetect opencv_video opencv_highgui opencv_legacy opencv_contrib)
|
||||
|
||||
enable_testing()
|
||||
get_target_property(LOC ${the_target} LOCATION)
|
||||
add_test(cvtest "${LOC}")
|
||||
|
||||
if(WIN32)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
||||
endif()
|
||||
@@ -1,307 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* accum_param_names[] = { "size", "channels", "depth", "use_mask", 0 };
|
||||
static const CvSize accum_sizes[] = {{30,30}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const CvSize accum_whole_sizes[] = {{320,240}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const int accum_depths[] = { CV_8U, CV_32F, CV_64F, -1 };
|
||||
static const int accum_channels[] = { 1, 3, -1 };
|
||||
|
||||
class CV_AccumBaseTestImpl : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_AccumBaseTestImpl( const char* test_name, const char* test_funcs );
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
double alpha;
|
||||
};
|
||||
|
||||
|
||||
CV_AccumBaseTestImpl::CV_AccumBaseTestImpl( const char* test_name, const char* test_funcs )
|
||||
: CvArrTest( test_name, test_funcs, "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[INPUT_OUTPUT].push(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push(NULL);
|
||||
test_array[TEMP].push(NULL);
|
||||
test_array[MASK].push(NULL);
|
||||
optional_mask = true;
|
||||
element_wise_relative_error = false;
|
||||
|
||||
default_timing_param_names = 0;
|
||||
depth_list = accum_depths;
|
||||
size_list = accum_sizes;
|
||||
whole_size_list = accum_whole_sizes;
|
||||
cn_list = accum_channels;
|
||||
|
||||
return;
|
||||
} // ctor
|
||||
|
||||
|
||||
void CV_AccumBaseTestImpl::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int depth = cvTsRandInt(rng) % 3, cn = cvTsRandInt(rng) & 1 ? 3 : 1;
|
||||
int accdepth = std::max((int)(cvTsRandInt(rng) % 2 + 1), depth);
|
||||
int i, input_count = test_array[INPUT].size();
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
depth = depth == 0 ? CV_8U : depth == 1 ? CV_32F : CV_64F;
|
||||
accdepth = accdepth == 1 ? CV_32F : CV_64F;
|
||||
accdepth = MAX(accdepth, depth);
|
||||
|
||||
for( i = 0; i < input_count; i++ )
|
||||
types[INPUT][i] = CV_MAKETYPE(depth,cn);
|
||||
|
||||
types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = types[TEMP][0] = CV_MAKETYPE(accdepth,cn);
|
||||
|
||||
alpha = cvTsRandReal(rng);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
double CV_AccumBaseTestImpl::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return CV_MAT_DEPTH(test_mat[INPUT_OUTPUT][0].type) < CV_64F ||
|
||||
CV_MAT_DEPTH(test_mat[INPUT][0].type) == CV_32F ? FLT_EPSILON*100 : DBL_EPSILON*1000;
|
||||
}
|
||||
|
||||
|
||||
void CV_AccumBaseTestImpl::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool* are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
types[INPUT_OUTPUT][0] = CV_MAKETYPE(MAX(CV_32F, CV_MAT_DEPTH(types[INPUT][0])),
|
||||
CV_MAT_CN(types[INPUT][0]));
|
||||
|
||||
alpha = 0.333333333333333;
|
||||
}
|
||||
|
||||
|
||||
CV_AccumBaseTestImpl accum_base( "accum", "" );
|
||||
|
||||
|
||||
class CV_AccumBaseTest : public CV_AccumBaseTestImpl
|
||||
{
|
||||
public:
|
||||
CV_AccumBaseTest( const char* test_name, const char* test_funcs );
|
||||
};
|
||||
|
||||
|
||||
CV_AccumBaseTest::CV_AccumBaseTest( const char* test_name, const char* test_funcs )
|
||||
: CV_AccumBaseTestImpl( test_name, test_funcs )
|
||||
{
|
||||
depth_list = 0;
|
||||
size_list = 0;
|
||||
whole_size_list = 0;
|
||||
cn_list = 0;
|
||||
|
||||
default_timing_param_names = accum_param_names;
|
||||
}
|
||||
|
||||
|
||||
/// acc
|
||||
class CV_AccTest : public CV_AccumBaseTest
|
||||
{
|
||||
public:
|
||||
CV_AccTest();
|
||||
protected:
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
};
|
||||
|
||||
|
||||
CV_AccTest::CV_AccTest(void)
|
||||
: CV_AccumBaseTest( "accum-acc", "cvAcc" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CV_AccTest::run_func(void)
|
||||
{
|
||||
cvAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
|
||||
}
|
||||
|
||||
|
||||
void CV_AccTest::prepare_to_validation( int )
|
||||
{
|
||||
const CvMat* src = &test_mat[INPUT][0];
|
||||
CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
|
||||
CvMat* temp = &test_mat[TEMP][0];
|
||||
const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
|
||||
|
||||
cvTsAdd( src, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
|
||||
cvTsCopy( temp, dst, mask );
|
||||
return;
|
||||
}
|
||||
|
||||
CV_AccTest acc_test;
|
||||
|
||||
|
||||
/// square acc
|
||||
class CV_SquareAccTest : public CV_AccumBaseTest
|
||||
{
|
||||
public:
|
||||
CV_SquareAccTest();
|
||||
protected:
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
};
|
||||
|
||||
|
||||
CV_SquareAccTest::CV_SquareAccTest()
|
||||
: CV_AccumBaseTest( "accum-squareacc", "cvSquareAcc" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CV_SquareAccTest::run_func()
|
||||
{
|
||||
cvSquareAcc( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
|
||||
}
|
||||
|
||||
|
||||
void CV_SquareAccTest::prepare_to_validation( int )
|
||||
{
|
||||
const CvMat* src = &test_mat[INPUT][0];
|
||||
CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
|
||||
CvMat* temp = &test_mat[TEMP][0];
|
||||
const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
|
||||
|
||||
cvTsMul( src, src, cvScalarAll(1.), temp );
|
||||
cvTsAdd( temp, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
|
||||
cvTsCopy( temp, dst, mask );
|
||||
}
|
||||
|
||||
CV_SquareAccTest squareacc_test;
|
||||
|
||||
|
||||
/// multiply acc
|
||||
class CV_MultiplyAccTest : public CV_AccumBaseTest
|
||||
{
|
||||
public:
|
||||
CV_MultiplyAccTest();
|
||||
protected:
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
};
|
||||
|
||||
|
||||
CV_MultiplyAccTest::CV_MultiplyAccTest()
|
||||
: CV_AccumBaseTest( "accum-mulacc", "cvMultiplyAcc" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
}
|
||||
|
||||
|
||||
void CV_MultiplyAccTest::run_func()
|
||||
{
|
||||
cvMultiplyAcc( test_array[INPUT][0], test_array[INPUT][1],
|
||||
test_array[INPUT_OUTPUT][0], test_array[MASK][0] );
|
||||
}
|
||||
|
||||
|
||||
void CV_MultiplyAccTest::prepare_to_validation( int )
|
||||
{
|
||||
const CvMat* src1 = &test_mat[INPUT][0];
|
||||
const CvMat* src2 = &test_mat[INPUT][1];
|
||||
CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
|
||||
CvMat* temp = &test_mat[TEMP][0];
|
||||
const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
|
||||
|
||||
cvTsMul( src1, src2, cvScalarAll(1.), temp );
|
||||
cvTsAdd( temp, cvScalarAll(1.), dst, cvScalarAll(1.), cvScalarAll(0.), temp, 0 );
|
||||
cvTsCopy( temp, dst, mask );
|
||||
}
|
||||
|
||||
CV_MultiplyAccTest mulacc_test;
|
||||
|
||||
|
||||
/// running average
|
||||
class CV_RunningAvgTest : public CV_AccumBaseTest
|
||||
{
|
||||
public:
|
||||
CV_RunningAvgTest();
|
||||
protected:
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
};
|
||||
|
||||
|
||||
CV_RunningAvgTest::CV_RunningAvgTest()
|
||||
: CV_AccumBaseTest( "accum-runavg", "cvRunningAvg" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CV_RunningAvgTest::run_func()
|
||||
{
|
||||
cvRunningAvg( test_array[INPUT][0], test_array[INPUT_OUTPUT][0],
|
||||
alpha, test_array[MASK][0] );
|
||||
}
|
||||
|
||||
|
||||
void CV_RunningAvgTest::prepare_to_validation( int )
|
||||
{
|
||||
const CvMat* src = &test_mat[INPUT][0];
|
||||
CvMat* dst = &test_mat[REF_INPUT_OUTPUT][0];
|
||||
CvMat* temp = &test_mat[TEMP][0];
|
||||
const CvMat* mask = test_array[MASK][0] ? &test_mat[MASK][0] : 0;
|
||||
double a[1], b[1];
|
||||
int accdepth = CV_MAT_DEPTH(test_mat[INPUT_OUTPUT][0].type);
|
||||
CvMat A = cvMat(1,1,accdepth,a), B = cvMat(1,1,accdepth,b);
|
||||
cvSetReal1D( &A, 0, alpha);
|
||||
cvSetReal1D( &B, 0, 1 - cvGetReal1D(&A, 0));
|
||||
|
||||
cvTsAdd( src, cvScalarAll(cvGetReal1D(&A, 0)), dst, cvScalarAll(cvGetReal1D(&B, 0)), cvScalarAll(0.), temp, 0 );
|
||||
cvTsCopy( temp, dst, mask );
|
||||
}
|
||||
|
||||
CV_RunningAvgTest runavg_test;
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
//extern "C"{
|
||||
// #include "HighGUI.h"
|
||||
//}
|
||||
|
||||
|
||||
static char cTestName[] = "Image Adaptive Thresholding";
|
||||
static char cTestClass[] = "Algorithm";
|
||||
static char cFuncName[] = "cvAdaptThreshold";
|
||||
static int aAdaptThreshold()
|
||||
{
|
||||
|
||||
CvPoint *cp;
|
||||
int parameter1 = 3;
|
||||
double parameter2 = 10;
|
||||
int width = 128;
|
||||
int height = 128;
|
||||
int kp = 5;
|
||||
int nPoints2 = 20;
|
||||
|
||||
int fi = 0;
|
||||
int a2 = 20;
|
||||
int b2 = 25,xc,yc;
|
||||
|
||||
double pi = 3.1415926;
|
||||
|
||||
double lower, upper;
|
||||
unsigned seed;
|
||||
char rand;
|
||||
AtsRandState state;
|
||||
|
||||
long diff_binary, diff_binary_inv;
|
||||
|
||||
int l,i,j;
|
||||
|
||||
IplImage *imBinary, *imBinary_inv, *imTo_zero, *imTo_zero_inv, *imInput, *imOutput;
|
||||
CvSize size;
|
||||
|
||||
int code = TRS_OK;
|
||||
|
||||
// read tests params
|
||||
if(!trsiRead( &width, "128", "image width" ))
|
||||
return TRS_UNDEF;
|
||||
if(!trsiRead( &height, "128", "image height" ))
|
||||
return TRS_UNDEF;
|
||||
|
||||
// initialized image
|
||||
l = width*height*sizeof(uchar);
|
||||
|
||||
cp = (CvPoint*) trsmAlloc(nPoints2*sizeof(CvPoint));
|
||||
|
||||
xc = (int)( width/2.);
|
||||
yc = (int)( height/2.);
|
||||
|
||||
kp = nPoints2;
|
||||
|
||||
size.width = width;
|
||||
size.height = height;
|
||||
|
||||
int xmin = width;
|
||||
int ymin = height;
|
||||
int xmax = 0;
|
||||
int ymax = 0;
|
||||
|
||||
|
||||
for(i=0;i<nPoints2;i++)
|
||||
{
|
||||
cp[i].x = (int)(a2*cos(2*pi*i/nPoints2)*cos(2*pi*fi/360.))-
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+xc;
|
||||
if(xmin> cp[i].x) xmin = cp[i].x;
|
||||
if(xmax< cp[i].x) xmax = cp[i].x;
|
||||
cp[i].y = (int)(a2*cos(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*cos(2*pi*fi/360.))+yc;
|
||||
if(ymin> cp[i].y) ymin = cp[i].y;
|
||||
if(ymax< cp[i].y) ymax = cp[i].y;
|
||||
}
|
||||
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
|
||||
|
||||
// IPL image moment calculation
|
||||
// create image
|
||||
imBinary = cvCreateImage( size, 8, 1 );
|
||||
imBinary_inv = cvCreateImage( size, 8, 1 );
|
||||
imTo_zero = cvCreateImage( size, 8, 1 );
|
||||
imTo_zero_inv = cvCreateImage( size, 8, 1 );
|
||||
imOutput = cvCreateImage( size, 8, 1 );
|
||||
imInput = cvCreateImage( size, 8, 1 );
|
||||
|
||||
int bgrn = 50;
|
||||
int signal = 150;
|
||||
|
||||
memset(imInput->imageData,bgrn,l);
|
||||
|
||||
cvFillPoly(imInput, &cp, &kp, 1, cvScalarAll(signal));
|
||||
|
||||
// do noise
|
||||
upper = 22;
|
||||
lower = -upper;
|
||||
seed = 345753;
|
||||
atsRandInit( &state, lower, upper, seed );
|
||||
|
||||
uchar *input = (uchar*)imInput->imageData;
|
||||
uchar *binary = (uchar*)imBinary->imageData;
|
||||
uchar *binary_inv = (uchar*)imBinary_inv->imageData;
|
||||
uchar *to_zero = (uchar*)imTo_zero->imageData;
|
||||
uchar *to_zero_inv = (uchar*)imTo_zero_inv->imageData;
|
||||
double *parameter = (double*)trsmAlloc(2*sizeof(double));
|
||||
|
||||
int step = imInput->widthStep;
|
||||
|
||||
for(i = 0; i<size.height; i++, input+=step, binary+=step, binary_inv+=step, to_zero+=step,to_zero_inv+=step)
|
||||
{
|
||||
for(j = 0; j<size.width; j++)
|
||||
{
|
||||
atsbRand8s( &state, &rand, 1);
|
||||
if(input[j] == bgrn)
|
||||
{
|
||||
binary[j] = to_zero[j] = (uchar)0;
|
||||
binary_inv[j] = (uchar)255;
|
||||
to_zero_inv[j] = input [j] = (uchar)(bgrn + rand);
|
||||
}
|
||||
else
|
||||
{
|
||||
binary[j] = (uchar)255;
|
||||
binary_inv[j] = to_zero_inv[j] = (uchar)0;
|
||||
to_zero[j] = input[j] = (uchar)(signal + rand);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
cvAdaptiveThreshold( imInput, imOutput, (double)255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, parameter1, parameter2 );
|
||||
diff_binary = atsCompare1Db( (uchar*)imOutput->imageData, (uchar*)imBinary->imageData, l, 5);
|
||||
|
||||
cvAdaptiveThreshold( imInput, imOutput, (double)255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, parameter1, parameter2 );
|
||||
diff_binary_inv = atsCompare1Db( (uchar*)imOutput->imageData, (uchar*)imBinary_inv->imageData, l, 5);
|
||||
|
||||
if( diff_binary > 5 || diff_binary_inv > 5 )
|
||||
code = TRS_FAIL;
|
||||
|
||||
cvReleaseImage(&imInput);
|
||||
cvReleaseImage(&imOutput);
|
||||
cvReleaseImage(&imBinary);
|
||||
cvReleaseImage(&imBinary_inv);
|
||||
cvReleaseImage(&imTo_zero);
|
||||
cvReleaseImage(&imTo_zero_inv);
|
||||
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "diff_binary =%ld \n", diff_binary);
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "diff_binary_inv =%ld \n", diff_binary_inv);
|
||||
|
||||
trsFree(parameter);
|
||||
trsFree(cp);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void InitAAdaptThreshold( void )
|
||||
{
|
||||
/* Test Registartion */
|
||||
trsReg(cFuncName,cTestName,cTestClass,aAdaptThreshold);
|
||||
} /* InitAAdaptThreshold */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,358 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <limits.h>
|
||||
|
||||
//
|
||||
// TODO!!!:
|
||||
// check_slice (and/or check) seem(s) to be broken, or this is a bug in function
|
||||
// (or its inability to handle possible self-intersections in the generated contours).
|
||||
//
|
||||
// At least, if // return TotalErrors;
|
||||
// is uncommented in check_slice, the test fails easily.
|
||||
// So, now (and it looks like since 0.9.6)
|
||||
// we only check that the set of vertices of the approximated polygon is
|
||||
// a subset of vertices of the original contour.
|
||||
//
|
||||
|
||||
class CV_ApproxPolyTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ApproxPolyTest();
|
||||
~CV_ApproxPolyTest();
|
||||
void clear();
|
||||
//int write_default_params(CvFileStorage* fs);
|
||||
|
||||
protected:
|
||||
//int read_params( CvFileStorage* fs );
|
||||
|
||||
int check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
CvSeqReader* SrcReader, float Eps,
|
||||
int* j, int Count );
|
||||
int check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps );
|
||||
|
||||
bool get_contour( int /*type*/, CvSeq** Seq, int* d,
|
||||
CvMemStorage* storage );
|
||||
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_ApproxPolyTest::CV_ApproxPolyTest():
|
||||
CvTest( "contour-approx", "cvApproxPoly" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
|
||||
CV_ApproxPolyTest::~CV_ApproxPolyTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_ApproxPolyTest::clear()
|
||||
{
|
||||
CvTest::clear();
|
||||
}
|
||||
|
||||
|
||||
/*int CV_ApproxPolyTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
CvTest::write_default_params( fs );
|
||||
if( ts->get_testing_mode() != CvTS::TIMING_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
test_case_count = cvReadInt( find_param( fs, "test_case_count" ), test_case_count );
|
||||
min_log_size = cvTsClipInt( min_log_size, 1, 10 );
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
|
||||
bool CV_ApproxPolyTest::get_contour( int /*type*/, CvSeq** Seq, int* d,
|
||||
CvMemStorage* storage )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int max_x = INT_MIN, max_y = INT_MIN, min_x = INT_MAX, min_y = INT_MAX;
|
||||
int i;
|
||||
CvSeq* seq;
|
||||
int total = cvTsRandInt(rng) % 1000 + 1;
|
||||
CvPoint center;
|
||||
int radius, angle;
|
||||
double deg_to_rad = CV_PI/180.;
|
||||
CvPoint pt;
|
||||
|
||||
center.x = cvTsRandInt( rng ) % 1000;
|
||||
center.y = cvTsRandInt( rng ) % 1000;
|
||||
radius = cvTsRandInt( rng ) % 1000;
|
||||
angle = cvTsRandInt( rng ) % 360;
|
||||
|
||||
seq = cvCreateSeq( CV_SEQ_POLYGON, sizeof(CvContour), sizeof(CvPoint), storage );
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int d_radius = cvTsRandInt( rng ) % 10 - 5;
|
||||
int d_angle = 360/total;//cvTsRandInt( rng ) % 10 - 5;
|
||||
pt.x = cvRound( center.x + radius*cos(angle*deg_to_rad));
|
||||
pt.y = cvRound( center.x - radius*sin(angle*deg_to_rad));
|
||||
radius += d_radius;
|
||||
angle += d_angle;
|
||||
cvSeqPush( seq, &pt );
|
||||
|
||||
max_x = MAX( max_x, pt.x );
|
||||
max_y = MAX( max_y, pt.y );
|
||||
|
||||
min_x = MIN( min_x, pt.x );
|
||||
min_y = MIN( min_y, pt.y );
|
||||
}
|
||||
|
||||
*d = (max_x - min_x)*(max_x - min_x) + (max_y - min_y)*(max_y - min_y);
|
||||
*Seq = seq;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
CvSeqReader* SrcReader, float Eps,
|
||||
int* _j, int Count )
|
||||
{
|
||||
///////////
|
||||
CvPoint Pt;
|
||||
///////////
|
||||
bool flag;
|
||||
double dy,dx;
|
||||
double A,B,C;
|
||||
double Sq;
|
||||
double sin_a = 0;
|
||||
double cos_a = 0;
|
||||
double d = 0;
|
||||
double dist;
|
||||
///////////
|
||||
int j, TotalErrors = 0;
|
||||
|
||||
////////////////////////////////
|
||||
if( SrcReader == NULL )
|
||||
{
|
||||
assert( false );
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////// init line ////////////
|
||||
flag = true;
|
||||
|
||||
dx = (double)StartPt.x - (double)EndPt.x;
|
||||
dy = (double)StartPt.y - (double)EndPt.y;
|
||||
|
||||
if( ( dx == 0 ) && ( dy == 0 ) ) flag = false;
|
||||
else
|
||||
{
|
||||
A = -dy;
|
||||
B = dx;
|
||||
C = dy * (double)StartPt.x - dx * (double)StartPt.y;
|
||||
Sq = sqrt( A*A + B*B );
|
||||
|
||||
sin_a = B/Sq;
|
||||
cos_a = A/Sq;
|
||||
d = C/Sq;
|
||||
}
|
||||
|
||||
/////// find start point and check distance ////////
|
||||
for( j = *_j; j < Count; j++ )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( Pt, *SrcReader );
|
||||
if( StartPt.x == Pt.x && StartPt.y == Pt.y ) break;
|
||||
else
|
||||
{
|
||||
if( flag ) dist = sin_a * Pt.y + cos_a * Pt.x - d;
|
||||
else dist = sqrt( (double)(EndPt.y - Pt.y)*(EndPt.y - Pt.y) + (EndPt.x - Pt.x)*(EndPt.x - Pt.x) );
|
||||
if( dist > Eps ) TotalErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
*_j = j;
|
||||
|
||||
//return TotalErrors;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps )
|
||||
{
|
||||
//////////
|
||||
CvSeqReader DstReader;
|
||||
CvSeqReader SrcReader;
|
||||
CvPoint StartPt, EndPt;
|
||||
///////////
|
||||
int TotalErrors = 0;
|
||||
///////////
|
||||
int Count;
|
||||
int i,j;
|
||||
|
||||
assert( SrcSeq && DstSeq );
|
||||
|
||||
////////// init ////////////////////
|
||||
Count = SrcSeq->total;
|
||||
|
||||
cvStartReadSeq( DstSeq, &DstReader, 0 );
|
||||
cvStartReadSeq( SrcSeq, &SrcReader, 0 );
|
||||
|
||||
CV_READ_SEQ_ELEM( StartPt, DstReader );
|
||||
for( i = 0 ; i < Count ; )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( EndPt, SrcReader );
|
||||
i++;
|
||||
if( StartPt.x == EndPt.x && StartPt.y == EndPt.y ) break;
|
||||
}
|
||||
|
||||
///////// start ////////////////
|
||||
for( i = 1, j = 0 ; i <= DstSeq->total ; )
|
||||
{
|
||||
///////// read slice ////////////
|
||||
EndPt.x = StartPt.x;
|
||||
EndPt.y = StartPt.y;
|
||||
CV_READ_SEQ_ELEM( StartPt, DstReader );
|
||||
i++;
|
||||
|
||||
TotalErrors += check_slice( StartPt, EndPt, &SrcReader, Eps, &j, Count );
|
||||
|
||||
if( j > Count )
|
||||
{
|
||||
TotalErrors++;
|
||||
return TotalErrors;
|
||||
} //if( !flag )
|
||||
|
||||
} // for( int i = 0 ; i < DstSeq->total ; i++ )
|
||||
|
||||
return TotalErrors;
|
||||
}
|
||||
|
||||
|
||||
//extern CvTestContourGenerator cvTsTestContours[];
|
||||
|
||||
void CV_ApproxPolyTest::run( int /*start_from*/ )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
CvMemStorage* storage = 0;
|
||||
////////////// Variables ////////////////
|
||||
int IntervalsCount = 10;
|
||||
///////////
|
||||
//CvTestContourGenerator Cont;
|
||||
CvSeq* SrcSeq = NULL;
|
||||
CvSeq* DstSeq;
|
||||
int iDiam;
|
||||
float dDiam, Eps, EpsStep;
|
||||
|
||||
for( int i = 0; i < 30; i++ )
|
||||
{
|
||||
CvMemStoragePos pos;
|
||||
|
||||
ts->update_context( this, i, false );
|
||||
|
||||
///////////////////// init contour /////////
|
||||
dDiam = 0;
|
||||
while( sqrt(dDiam) / IntervalsCount == 0 )
|
||||
{
|
||||
if( storage != 0 )
|
||||
cvReleaseMemStorage(&storage);
|
||||
|
||||
storage = cvCreateMemStorage( 0 );
|
||||
if( get_contour( 0, &SrcSeq, &iDiam, storage ) )
|
||||
dDiam = (float)iDiam;
|
||||
}
|
||||
dDiam = (float)sqrt( dDiam );
|
||||
|
||||
storage = SrcSeq->storage;
|
||||
|
||||
////////////////// test /////////////
|
||||
EpsStep = dDiam / IntervalsCount ;
|
||||
for( Eps = EpsStep ; Eps < dDiam ; Eps += EpsStep )
|
||||
{
|
||||
cvSaveMemStoragePos( storage, &pos );
|
||||
|
||||
////////// call function ////////////
|
||||
DstSeq = cvApproxPoly( SrcSeq, SrcSeq->header_size, storage,
|
||||
CV_POLY_APPROX_DP, Eps );
|
||||
|
||||
if( DstSeq == NULL )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"cvApproxPoly returned NULL for contour #%d, espilon = %g\n", i, Eps );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
} // if( DstSeq == NULL )
|
||||
|
||||
code = check( SrcSeq, DstSeq, Eps );
|
||||
if( code != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"Incorrect result for the contour #%d approximated with epsilon=%g\n", i, Eps );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
cvRestoreMemStoragePos( storage, &pos );
|
||||
} // for( Eps = EpsStep ; Eps <= Diam ; Eps += EpsStep )
|
||||
|
||||
///////////// free memory ///////////////////
|
||||
cvReleaseMemStorage(&storage);
|
||||
} // for( int i = 0; NULL != ( Cont = Contours[i] ) ; i++ )
|
||||
|
||||
_exit_:
|
||||
cvReleaseMemStorage(&storage);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
|
||||
CV_ApproxPolyTest contour_approx;
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,428 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
//template<class T> ostream& operator<<(ostream& out, const Mat_<T>& mat)
|
||||
//{
|
||||
// for(Mat_<T>::const_iterator pos = mat.begin(), end = mat.end(); pos != end; ++pos)
|
||||
// out << *pos << " ";
|
||||
// return out;
|
||||
//}
|
||||
//ostream& operator<<(ostream& out, const Mat& mat) { return out << Mat_<double>(mat); }
|
||||
|
||||
Mat calcRvec(const vector<Point3f>& points, const Size& cornerSize)
|
||||
{
|
||||
Point3f p00 = points[0];
|
||||
Point3f p10 = points[1];
|
||||
Point3f p01 = points[cornerSize.width];
|
||||
|
||||
Vec3d ex(p10.x - p00.x, p10.y - p00.y, p10.z - p00.z);
|
||||
Vec3d ey(p01.x - p00.x, p01.y - p00.y, p01.z - p00.z);
|
||||
Vec3d ez = ex.cross(ey);
|
||||
|
||||
Mat rot(3, 3, CV_64F);
|
||||
*rot.ptr<Vec3d>(0) = ex;
|
||||
*rot.ptr<Vec3d>(1) = ey;
|
||||
*rot.ptr<Vec3d>(2) = ez * (1.0/norm(ez));
|
||||
|
||||
Mat res;
|
||||
Rodrigues(rot.t(), res);
|
||||
return res.reshape(1, 1);
|
||||
}
|
||||
|
||||
class CV_CalibrateCameraArtificialTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_CalibrateCameraArtificialTest() : CvTest( "calibrate-camera-artificial", "cvCalibrateCamera2")
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
~CV_CalibrateCameraArtificialTest() {}
|
||||
protected:
|
||||
int r;
|
||||
|
||||
const static int JUST_FIND_CORNERS = 0;
|
||||
const static int USE_CORNERS_SUBPIX = 1;
|
||||
const static int USE_4QUAD_CORNERS = 2;
|
||||
const static int ARTIFICIAL_CORNERS = 4;
|
||||
|
||||
|
||||
bool checkErr(double a, double a0, double eps, double delta)
|
||||
{
|
||||
return fabs(a - a0) > eps * (fabs(a0) + delta);
|
||||
}
|
||||
|
||||
void compareCameraMatrs(const Mat_<double>& camMat, const Mat& camMat_est)
|
||||
{
|
||||
if ( camMat_est.at<double>(0, 1) != 0 || camMat_est.at<double>(1, 0) != 0 ||
|
||||
camMat_est.at<double>(2, 0) != 0 || camMat_est.at<double>(2, 1) != 0 ||
|
||||
camMat_est.at<double>(2, 2) != 1)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Bad shape of camera matrix returned \n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
}
|
||||
|
||||
double fx_e = camMat_est.at<double>(0, 0), fy_e = camMat_est.at<double>(1, 1);
|
||||
double cx_e = camMat_est.at<double>(0, 2), cy_e = camMat_est.at<double>(1, 2);
|
||||
|
||||
double fx = camMat(0, 0), fy = camMat(1, 1), cx = camMat(0, 2), cy = camMat(1, 2);
|
||||
|
||||
const double eps = 1e-2;
|
||||
const double dlt = 1e-5;
|
||||
|
||||
bool fail = checkErr(fx_e, fx, eps, dlt) || checkErr(fy_e, fy, eps, dlt) ||
|
||||
checkErr(cx_e, cx, eps, dlt) || checkErr(cy_e, cy, eps, dlt);
|
||||
|
||||
if (fail)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
ts->printf( CvTS::LOG, "%d) Expected [Fx Fy Cx Cy] = [%.3f %.3f %.3f %.3f]\n", r, fx, fy, cx, cy);
|
||||
ts->printf( CvTS::LOG, "%d) Estimated [Fx Fy Cx Cy] = [%.3f %.3f %.3f %.3f]\n", r, fx_e, fy_e, cx_e, cy_e);
|
||||
}
|
||||
|
||||
void compareDistCoeffs(const Mat_<double>& distCoeffs, const Mat& distCoeffs_est)
|
||||
{
|
||||
const double *dt_e = distCoeffs_est.ptr<double>();
|
||||
|
||||
double k1_e = dt_e[0], k2_e = dt_e[1], k3_e = dt_e[4];
|
||||
double p1_e = dt_e[2], p2_e = dt_e[3];
|
||||
|
||||
double k1 = distCoeffs(0, 0), k2 = distCoeffs(0, 1), k3 = distCoeffs(0, 4);
|
||||
double p1 = distCoeffs(0, 2), p2 = distCoeffs(0, 3);
|
||||
|
||||
const double eps = 5e-2;
|
||||
const double dlt = 1e-3;
|
||||
|
||||
const double eps_k3 = 5;
|
||||
const double dlt_k3 = 1e-3;
|
||||
|
||||
bool fail = checkErr(k1_e, k1, eps, dlt) || checkErr(k2_e, k2, eps, dlt) || checkErr(k3_e, k3, eps_k3, dlt_k3) ||
|
||||
checkErr(p1_e, p1, eps, dlt) || checkErr(p2_e, p2, eps, dlt);
|
||||
|
||||
if (fail)
|
||||
{
|
||||
// commented according to vp123's recomendation. TODO - improve accuaracy
|
||||
//ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY); ss
|
||||
}
|
||||
ts->printf( CvTS::LOG, "%d) DistCoeff exp=(%.2f, %.2f, %.4f, %.4f %.2f)\n", r, k1, k2, p1, p2, k3);
|
||||
ts->printf( CvTS::LOG, "%d) DistCoeff est=(%.2f, %.2f, %.4f, %.4f %.2f)\n", r, k1_e, k2_e, p1_e, p2_e, k3_e);
|
||||
ts->printf( CvTS::LOG, "%d) AbsError = [%.5f %.5f %.5f %.5f %.5f]\n", r, fabs(k1-k1_e), fabs(k2-k2_e), fabs(p1-p1_e), fabs(p2-p2_e), fabs(k3-k3_e));
|
||||
}
|
||||
|
||||
void compareShiftVecs(const vector<Mat>& tvecs, const vector<Mat>& tvecs_est)
|
||||
{
|
||||
const double eps = 1e-2;
|
||||
const double dlt = 1e-4;
|
||||
|
||||
int err_count = 0;
|
||||
const int errMsgNum = 4;
|
||||
for(size_t i = 0; i < tvecs.size(); ++i)
|
||||
{
|
||||
const Point3d& tvec = *tvecs[i].ptr<Point3d>();
|
||||
const Point3d& tvec_est = *tvecs_est[i].ptr<Point3d>();
|
||||
|
||||
if (norm(tvec_est - tvec) > eps* (norm(tvec) + dlt))
|
||||
{
|
||||
if (err_count++ < errMsgNum)
|
||||
{
|
||||
if (err_count == errMsgNum)
|
||||
ts->printf( CvTS::LOG, "%d) ...\n", r);
|
||||
else
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%d) Bad accuracy in returned tvecs. Index = %d\n", r, i);
|
||||
ts->printf( CvTS::LOG, "%d) norm(tvec_est - tvec) = %f, norm(tvec_exp) = %f \n", r, norm(tvec_est - tvec), norm(tvec));
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compareRotationVecs(const vector<Mat>& rvecs, const vector<Mat>& rvecs_est)
|
||||
{
|
||||
const double eps = 2e-2;
|
||||
const double dlt = 1e-4;
|
||||
|
||||
Mat rmat, rmat_est;
|
||||
int err_count = 0;
|
||||
const int errMsgNum = 4;
|
||||
for(size_t i = 0; i < rvecs.size(); ++i)
|
||||
{
|
||||
Rodrigues(rvecs[i], rmat);
|
||||
Rodrigues(rvecs_est[i], rmat_est);
|
||||
|
||||
if (norm(rmat_est, rmat) > eps* (norm(rmat) + dlt))
|
||||
{
|
||||
if (err_count++ < errMsgNum)
|
||||
{
|
||||
if (err_count == errMsgNum)
|
||||
ts->printf( CvTS::LOG, "%d) ...\n", r);
|
||||
else
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%d) Bad accuracy in returned rvecs (rotation matrs). Index = %d\n", r, i);
|
||||
ts->printf( CvTS::LOG, "%d) norm(rot_mat_est - rot_mat_exp) = %f, norm(rot_mat_exp) = %f \n", r, norm(rmat_est, rmat), norm(rmat));
|
||||
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double reprojectErrorWithoutIntrinsics(const vector<Point3f>& cb3d, const vector<Mat>& rvecs_exp, const vector<Mat>& tvecs_exp,
|
||||
const vector<Mat>& rvecs_est, const vector<Mat>& tvecs_est)
|
||||
{
|
||||
const static Mat eye33 = Mat::eye(3, 3, CV_64F);
|
||||
const static Mat zero15 = Mat::zeros(1, 5, CV_64F);
|
||||
Mat chessboard3D(cb3d);
|
||||
vector<Point2f> uv_exp, uv_est;
|
||||
double res = 0;
|
||||
|
||||
for(size_t i = 0; i < rvecs_exp.size(); ++i)
|
||||
{
|
||||
projectPoints(chessboard3D, rvecs_exp[i], tvecs_exp[i], eye33, zero15, uv_exp);
|
||||
projectPoints(chessboard3D, rvecs_est[i], tvecs_est[i], eye33, zero15, uv_est);
|
||||
for(size_t j = 0; j < cb3d.size(); ++j)
|
||||
res += norm(uv_exp[i] - uv_est[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Size2f sqSile;
|
||||
|
||||
vector<Point3f> chessboard3D;
|
||||
vector<Mat> boards, rvecs_exp, tvecs_exp, rvecs_spnp, tvecs_spnp;
|
||||
vector< vector<Point3f> > objectPoints;
|
||||
vector< vector<Point2f> > imagePoints_art;
|
||||
vector< vector<Point2f> > imagePoints_findCb;
|
||||
|
||||
|
||||
void prepareForTest(const Mat& bg, const Mat& camMat, const Mat& distCoeffs, size_t brdsNum, const ChessBoardGenerator& cbg)
|
||||
{
|
||||
sqSile = Size2f(1.f, 1.f);
|
||||
Size cornersSize = cbg.cornersSize();
|
||||
|
||||
chessboard3D.clear();
|
||||
for(int j = 0; j < cornersSize.height; ++j)
|
||||
for(int i = 0; i < cornersSize.width; ++i)
|
||||
chessboard3D.push_back(Point3f(sqSile.width * i, sqSile.height * j, 0));
|
||||
|
||||
boards.resize(brdsNum);
|
||||
rvecs_exp.resize(brdsNum);
|
||||
tvecs_exp.resize(brdsNum);
|
||||
objectPoints.clear();
|
||||
objectPoints.resize(brdsNum, chessboard3D);
|
||||
imagePoints_art.clear();
|
||||
imagePoints_findCb.clear();
|
||||
|
||||
vector<Point2f> corners_art, corners_fcb;
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
boards[i] = cbg(bg, camMat, distCoeffs, sqSile, corners_art);
|
||||
if(findChessboardCorners(boards[i], cornersSize, corners_fcb))
|
||||
break;
|
||||
}
|
||||
|
||||
//cv::namedWindow("CB"); imshow("CB", boards[i]); cv::waitKey();
|
||||
|
||||
imagePoints_art.push_back(corners_art);
|
||||
imagePoints_findCb.push_back(corners_fcb);
|
||||
|
||||
tvecs_exp[i].create(1, 3, CV_64F);
|
||||
*tvecs_exp[i].ptr<Point3d>() = cbg.corners3d[0];
|
||||
rvecs_exp[i] = calcRvec(cbg.corners3d, cbg.cornersSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void runTest(const Size& imgSize, const Mat_<double>& camMat, const Mat_<double>& distCoeffs, size_t brdsNum, const Size& cornersSize, int flag = 0)
|
||||
{
|
||||
const TermCriteria tc(TermCriteria::EPS|TermCriteria::MAX_ITER, 30, 0.1);
|
||||
|
||||
vector< vector<Point2f> > imagePoints;
|
||||
|
||||
switch(flag)
|
||||
{
|
||||
case JUST_FIND_CORNERS: imagePoints = imagePoints_findCb; break;
|
||||
case ARTIFICIAL_CORNERS: imagePoints = imagePoints_art; break;
|
||||
|
||||
case USE_CORNERS_SUBPIX:
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
{
|
||||
Mat gray;
|
||||
cvtColor(boards[i], gray, CV_BGR2GRAY);
|
||||
vector<Point2f> tmp = imagePoints_findCb[i];
|
||||
cornerSubPix(gray, tmp, Size(5, 5), Size(-1,-1), tc);
|
||||
imagePoints.push_back(tmp);
|
||||
}
|
||||
break;
|
||||
case USE_4QUAD_CORNERS:
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
{
|
||||
Mat gray;
|
||||
cvtColor(boards[i], gray, CV_BGR2GRAY);
|
||||
vector<Point2f> tmp = imagePoints_findCb[i];
|
||||
find4QuadCornerSubpix(gray, tmp, Size(5, 5));
|
||||
imagePoints.push_back(tmp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
Mat camMat_est = Mat::eye(3, 3, CV_64F), distCoeffs_est = Mat::zeros(1, 5, CV_64F);
|
||||
vector<Mat> rvecs_est, tvecs_est;
|
||||
|
||||
int flags = /*CV_CALIB_FIX_K3|*/CV_CALIB_FIX_K4|CV_CALIB_FIX_K5|CV_CALIB_FIX_K6; //CALIB_FIX_K3; //CALIB_FIX_ASPECT_RATIO | | CALIB_ZERO_TANGENT_DIST;
|
||||
double rep_error = calibrateCamera(objectPoints, imagePoints, imgSize, camMat_est, distCoeffs_est, rvecs_est, tvecs_est, flags);
|
||||
rep_error /= brdsNum * cornersSize.area();
|
||||
|
||||
const double thres = 1;
|
||||
if (rep_error > thres)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%d) Too big reproject error = %f\n", r, rep_error);
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
compareCameraMatrs(camMat, camMat_est);
|
||||
compareDistCoeffs(distCoeffs, distCoeffs_est);
|
||||
compareShiftVecs(tvecs_exp, tvecs_est);
|
||||
compareRotationVecs(rvecs_exp, rvecs_est);
|
||||
|
||||
double rep_errorWOI = reprojectErrorWithoutIntrinsics(chessboard3D, rvecs_exp, tvecs_exp, rvecs_est, tvecs_est);
|
||||
rep_errorWOI /= brdsNum * cornersSize.area();
|
||||
|
||||
const double thres2 = 0.01;
|
||||
if (rep_errorWOI > thres2)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%d) Too big reproject error without intrinsics = %f\n", r, rep_errorWOI);
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
ts->printf( CvTS::LOG, "%d) Testing solvePnP...\n", r);
|
||||
rvecs_spnp.resize(brdsNum);
|
||||
tvecs_spnp.resize(brdsNum);
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
solvePnP(Mat(objectPoints[i]), Mat(imagePoints[i]), camMat, distCoeffs, rvecs_spnp[i], tvecs_spnp[i]);
|
||||
|
||||
compareShiftVecs(tvecs_exp, tvecs_spnp);
|
||||
compareRotationVecs(rvecs_exp, rvecs_spnp);
|
||||
}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
RNG& rng = theRNG();
|
||||
|
||||
int progress = 0;
|
||||
int repeat_num = 3;
|
||||
for(r = 0; r < repeat_num; ++r)
|
||||
{
|
||||
const int brds_num = 20;
|
||||
|
||||
Mat bg(Size(640, 480), CV_8UC3);
|
||||
randu(bg, Scalar::all(32), Scalar::all(255));
|
||||
GaussianBlur(bg, bg, Size(5, 5), 2);
|
||||
|
||||
double fx = 300 + (20 * (double)rng - 10);
|
||||
double fy = 300 + (20 * (double)rng - 10);
|
||||
|
||||
double cx = bg.cols/2 + (40 * (double)rng - 20);
|
||||
double cy = bg.rows/2 + (40 * (double)rng - 20);
|
||||
|
||||
Mat_<double> camMat(3, 3);
|
||||
camMat << fx, 0., cx, 0, fy, cy, 0., 0., 1.;
|
||||
|
||||
double k1 = 0.5 + (double)rng/5;
|
||||
double k2 = (double)rng/5;
|
||||
double k3 = (double)rng/5;
|
||||
|
||||
double p1 = 0.001 + (double)rng/10;
|
||||
double p2 = 0.001 + (double)rng/10;
|
||||
|
||||
Mat_<double> distCoeffs(1, 5, 0.0);
|
||||
distCoeffs << k1, k2, p1, p2, k3;
|
||||
|
||||
ChessBoardGenerator cbg(Size(9, 8));
|
||||
cbg.min_cos = 0.9;
|
||||
cbg.cov = 0.8;
|
||||
|
||||
progress = update_progress(progress, r, repeat_num, 0);
|
||||
ts->printf( CvTS::LOG, "\n");
|
||||
prepareForTest(bg, camMat, distCoeffs, brds_num, cbg);
|
||||
|
||||
ts->printf( CvTS::LOG, "artificial corners\n");
|
||||
runTest(bg.size(), camMat, distCoeffs, brds_num, cbg.cornersSize(), ARTIFICIAL_CORNERS);
|
||||
progress = update_progress(progress, r, repeat_num, 0);
|
||||
|
||||
ts->printf( CvTS::LOG, "findChessboard corners\n");
|
||||
runTest(bg.size(), camMat, distCoeffs, brds_num, cbg.cornersSize(), JUST_FIND_CORNERS);
|
||||
progress = update_progress(progress, r, repeat_num, 0);
|
||||
|
||||
ts->printf( CvTS::LOG, "cornersSubPix corners\n");
|
||||
runTest(bg.size(), camMat, distCoeffs, brds_num, cbg.cornersSize(), USE_CORNERS_SUBPIX);
|
||||
progress = update_progress(progress, r, repeat_num, 0);
|
||||
|
||||
ts->printf( CvTS::LOG, "4quad corners\n");
|
||||
runTest(bg.size(), camMat, distCoeffs, brds_num, cbg.cornersSize(), USE_4QUAD_CORNERS);
|
||||
progress = update_progress(progress, r, repeat_num, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CV_CalibrateCameraArtificialTest calibrateCameraArtificialTest;
|
||||
@@ -1,533 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
|
||||
class CV_TrackBaseTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_TrackBaseTest( const char* test_name, const char* test_funcs );
|
||||
virtual ~CV_TrackBaseTest();
|
||||
void clear();
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
|
||||
protected:
|
||||
int read_params( CvFileStorage* fs );
|
||||
void run_func(void);
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void generate_object();
|
||||
|
||||
int min_log_size, max_log_size;
|
||||
CvMat* img;
|
||||
CvBox2D box0;
|
||||
CvSize img_size;
|
||||
CvTermCriteria criteria;
|
||||
int img_type;
|
||||
};
|
||||
|
||||
|
||||
CV_TrackBaseTest::CV_TrackBaseTest( const char* test_name, const char* test_funcs ):
|
||||
CvTest( test_name, test_funcs )
|
||||
{
|
||||
img = 0;
|
||||
test_case_count = 100;
|
||||
min_log_size = 5;
|
||||
max_log_size = 8;
|
||||
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
|
||||
CV_TrackBaseTest::~CV_TrackBaseTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_TrackBaseTest::clear()
|
||||
{
|
||||
cvReleaseMat( &img );
|
||||
CvTest::clear();
|
||||
}
|
||||
|
||||
|
||||
int CV_TrackBaseTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
CvTest::write_default_params( fs );
|
||||
if( ts->get_testing_mode() != CvTS::TIMING_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
write_param( fs, "min_log_size", min_log_size );
|
||||
write_param( fs, "max_log_size", max_log_size );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_TrackBaseTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
test_case_count = cvReadInt( find_param( fs, "test_case_count" ), test_case_count );
|
||||
min_log_size = cvReadInt( find_param( fs, "min_log_size" ), min_log_size );
|
||||
max_log_size = cvReadInt( find_param( fs, "max_log_size" ), max_log_size );
|
||||
|
||||
min_log_size = cvTsClipInt( min_log_size, 1, 10 );
|
||||
max_log_size = cvTsClipInt( max_log_size, 1, 10 );
|
||||
if( min_log_size > max_log_size )
|
||||
{
|
||||
int t;
|
||||
CV_SWAP( min_log_size, max_log_size, t );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_TrackBaseTest::generate_object()
|
||||
{
|
||||
int x, y;
|
||||
double cx = box0.center.x;
|
||||
double cy = box0.center.y;
|
||||
double width = box0.size.width*0.5;
|
||||
double height = box0.size.height*0.5;
|
||||
double angle = box0.angle*CV_PI/180.;
|
||||
double a = sin(angle), b = -cos(angle);
|
||||
double inv_ww = 1./(width*width), inv_hh = 1./(height*height);
|
||||
|
||||
img = cvCreateMat( img_size.height, img_size.width, img_type );
|
||||
cvZero( img );
|
||||
|
||||
// use the straightforward algorithm: for every pixel check if it is inside the ellipse
|
||||
for( y = 0; y < img_size.height; y++ )
|
||||
{
|
||||
uchar* ptr = img->data.ptr + img->step*y;
|
||||
float* fl = (float*)ptr;
|
||||
double x_ = (y - cy)*b, y_ = (y - cy)*a;
|
||||
|
||||
for( x = 0; x < img_size.width; x++ )
|
||||
{
|
||||
double x1 = (x - cx)*a - x_;
|
||||
double y1 = (x - cx)*b + y_;
|
||||
|
||||
if( x1*x1*inv_hh + y1*y1*inv_ww <= 1. )
|
||||
{
|
||||
if( img_type == CV_8U )
|
||||
ptr[x] = (uchar)1;
|
||||
else
|
||||
fl[x] = (float)1.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CV_TrackBaseTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvTest::prepare_test_case( test_case_idx );
|
||||
float m;
|
||||
|
||||
clear();
|
||||
|
||||
box0.size.width = (float)exp((cvTsRandReal(rng) * (max_log_size - min_log_size) + min_log_size)*CV_LOG2);
|
||||
box0.size.height = (float)exp((cvTsRandReal(rng) * (max_log_size - min_log_size) + min_log_size)*CV_LOG2);
|
||||
box0.angle = (float)(cvTsRandReal(rng)*180.);
|
||||
|
||||
if( box0.size.width > box0.size.height )
|
||||
{
|
||||
float t;
|
||||
CV_SWAP( box0.size.width, box0.size.height, t );
|
||||
}
|
||||
|
||||
m = MAX( box0.size.width, box0.size.height );
|
||||
img_size.width = cvRound(cvTsRandReal(rng)*m*0.5 + m + 1);
|
||||
img_size.height = cvRound(cvTsRandReal(rng)*m*0.5 + m + 1);
|
||||
img_type = cvTsRandInt(rng) % 2 ? CV_32F : CV_8U;
|
||||
img_type = CV_8U;
|
||||
|
||||
box0.center.x = (float)(img_size.width*0.5 + (cvTsRandReal(rng)-0.5)*(img_size.width - m));
|
||||
box0.center.y = (float)(img_size.height*0.5 + (cvTsRandReal(rng)-0.5)*(img_size.height - m));
|
||||
|
||||
criteria = cvTermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 10, 0.1 );
|
||||
|
||||
generate_object();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_TrackBaseTest::run_func(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CV_TrackBaseTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
CV_TrackBaseTest track_basetest( "track", "" );
|
||||
|
||||
|
||||
|
||||
///////////////////////// CamShift //////////////////////////////
|
||||
|
||||
class CV_CamShiftTest : public CV_TrackBaseTest
|
||||
{
|
||||
public:
|
||||
CV_CamShiftTest();
|
||||
|
||||
protected:
|
||||
void run_func(void);
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void generate_object();
|
||||
|
||||
CvBox2D box;
|
||||
CvRect init_rect;
|
||||
CvConnectedComp comp;
|
||||
int area0;
|
||||
};
|
||||
|
||||
|
||||
CV_CamShiftTest::CV_CamShiftTest() :
|
||||
CV_TrackBaseTest( "track-camshift", "cvCamShift" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CV_CamShiftTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
double m;
|
||||
int code = CV_TrackBaseTest::prepare_test_case( test_case_idx );
|
||||
int i, area;
|
||||
|
||||
if( code <= 0 )
|
||||
return code;
|
||||
|
||||
area0 = cvCountNonZero(img);
|
||||
|
||||
for(i = 0; i < 100; i++)
|
||||
{
|
||||
CvMat temp;
|
||||
|
||||
m = MAX(box0.size.width,box0.size.height)*0.8;
|
||||
init_rect.x = cvFloor(box0.center.x - m*(0.45 + cvTsRandReal(rng)*0.2));
|
||||
init_rect.y = cvFloor(box0.center.y - m*(0.45 + cvTsRandReal(rng)*0.2));
|
||||
init_rect.width = cvCeil(box0.center.x + m*(0.45 + cvTsRandReal(rng)*0.2) - init_rect.x);
|
||||
init_rect.height = cvCeil(box0.center.y + m*(0.45 + cvTsRandReal(rng)*0.2) - init_rect.y);
|
||||
|
||||
if( init_rect.x < 0 || init_rect.y < 0 ||
|
||||
init_rect.x + init_rect.width >= img_size.width ||
|
||||
init_rect.y + init_rect.height >= img_size.height )
|
||||
continue;
|
||||
|
||||
cvGetSubRect( img, &temp, init_rect );
|
||||
area = cvCountNonZero( &temp );
|
||||
|
||||
if( area >= 0.1*area0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return i < 100 ? code : 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_CamShiftTest::run_func(void)
|
||||
{
|
||||
cvCamShift( img, init_rect, criteria, &comp, &box );
|
||||
}
|
||||
|
||||
|
||||
int CV_CamShiftTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
double m = MAX(box0.size.width, box0.size.height), delta;
|
||||
double diff_angle;
|
||||
|
||||
if( cvIsNaN(box.size.width) || cvIsInf(box.size.width) || box.size.width <= 0 ||
|
||||
cvIsNaN(box.size.height) || cvIsInf(box.size.height) || box.size.height <= 0 ||
|
||||
cvIsNaN(box.center.x) || cvIsInf(box.center.x) ||
|
||||
cvIsNaN(box.center.y) || cvIsInf(box.center.y) ||
|
||||
cvIsNaN(box.angle) || cvIsInf(box.angle) || box.angle < -180 || box.angle > 180 ||
|
||||
cvIsNaN(comp.area) || cvIsInf(comp.area) || comp.area <= 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Invalid CvBox2D or CvConnectedComp was returned by cvCamShift\n" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
box.angle = (float)(180 - box.angle);
|
||||
|
||||
if( fabs(box.size.width - box0.size.width) > box0.size.width*0.2 ||
|
||||
fabs(box.size.height - box0.size.height) > box0.size.height*0.3 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Incorrect CvBox2D size (=%.1f x %.1f, should be %.1f x %.1f)\n",
|
||||
box.size.width, box.size.height, box0.size.width, box0.size.height );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( fabs(box.center.x - box0.center.x) > m*0.1 ||
|
||||
fabs(box.center.y - box0.center.y) > m*0.1 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Incorrect CvBox2D position (=(%.1f, %.1f), should be (%.1f, %.1f))\n",
|
||||
box.center.x, box.center.y, box0.center.x, box0.center.y );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( box.angle < 0 )
|
||||
box.angle += 180;
|
||||
|
||||
diff_angle = fabs(box0.angle - box.angle);
|
||||
diff_angle = MIN( diff_angle, fabs(box0.angle - box.angle + 180));
|
||||
|
||||
if( fabs(diff_angle) > 30 && box0.size.height > box0.size.width*1.2 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Incorrect CvBox2D angle (=%1.f, should be %1.f)\n",
|
||||
box.angle, box0.angle );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
delta = m*0.7;
|
||||
|
||||
if( comp.rect.x < box0.center.x - delta ||
|
||||
comp.rect.y < box0.center.y - delta ||
|
||||
comp.rect.x + comp.rect.width > box0.center.x + delta ||
|
||||
comp.rect.y + comp.rect.height > box0.center.y + delta )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"Incorrect CvConnectedComp ((%d,%d,%d,%d) is not within (%.1f,%.1f,%.1f,%.1f))\n",
|
||||
comp.rect.x, comp.rect.y, comp.rect.x + comp.rect.width, comp.rect.y + comp.rect.height,
|
||||
box0.center.x - delta, box0.center.y - delta, box0.center.x + delta, box0.center.y + delta );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( fabs(comp.area - area0) > area0*0.15 )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"Incorrect CvConnectedComp area (=%.1f, should be %d)\n", comp.area, area0 );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
if( code < 0 )
|
||||
{
|
||||
#if defined _DEBUG && defined WIN32
|
||||
IplImage* dst = cvCreateImage( img_size, 8, 3 );
|
||||
cvNamedWindow( "test", 1 );
|
||||
cvCmpS( img, 0, img, CV_CMP_GT );
|
||||
cvCvtColor( img, dst, CV_GRAY2BGR );
|
||||
cvRectangle( dst, cvPoint(init_rect.x, init_rect.y),
|
||||
cvPoint(init_rect.x + init_rect.width, init_rect.y + init_rect.height),
|
||||
CV_RGB(255,0,0), 3, 8, 0 );
|
||||
cvEllipseBox( dst, box, CV_RGB(0,255,0), 3, 8, 0 );
|
||||
cvShowImage( "test", dst );
|
||||
cvReleaseImage( &dst );
|
||||
cvWaitKey();
|
||||
#endif
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_CamShiftTest camshift_test;
|
||||
|
||||
|
||||
///////////////////////// MeanShift //////////////////////////////
|
||||
|
||||
class CV_MeanShiftTest : public CV_TrackBaseTest
|
||||
{
|
||||
public:
|
||||
CV_MeanShiftTest();
|
||||
|
||||
protected:
|
||||
void run_func(void);
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void generate_object();
|
||||
|
||||
CvRect init_rect;
|
||||
CvConnectedComp comp;
|
||||
int area0, area;
|
||||
};
|
||||
|
||||
|
||||
CV_MeanShiftTest::CV_MeanShiftTest() :
|
||||
CV_TrackBaseTest( "track-meanshift", "cvMeanShift" )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CV_MeanShiftTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
double m;
|
||||
int code = CV_TrackBaseTest::prepare_test_case( test_case_idx );
|
||||
int i;
|
||||
|
||||
if( code <= 0 )
|
||||
return code;
|
||||
|
||||
area0 = cvCountNonZero(img);
|
||||
|
||||
for(i = 0; i < 100; i++)
|
||||
{
|
||||
CvMat temp;
|
||||
|
||||
m = (box0.size.width + box0.size.height)*0.5;
|
||||
init_rect.x = cvFloor(box0.center.x - m*(0.4 + cvTsRandReal(rng)*0.2));
|
||||
init_rect.y = cvFloor(box0.center.y - m*(0.4 + cvTsRandReal(rng)*0.2));
|
||||
init_rect.width = cvCeil(box0.center.x + m*(0.4 + cvTsRandReal(rng)*0.2) - init_rect.x);
|
||||
init_rect.height = cvCeil(box0.center.y + m*(0.4 + cvTsRandReal(rng)*0.2) - init_rect.y);
|
||||
|
||||
if( init_rect.x < 0 || init_rect.y < 0 ||
|
||||
init_rect.x + init_rect.width >= img_size.width ||
|
||||
init_rect.y + init_rect.height >= img_size.height )
|
||||
continue;
|
||||
|
||||
cvGetSubRect( img, &temp, init_rect );
|
||||
area = cvCountNonZero( &temp );
|
||||
|
||||
if( area >= 0.5*area0 )
|
||||
break;
|
||||
}
|
||||
|
||||
return i < 100 ? code : 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_MeanShiftTest::run_func(void)
|
||||
{
|
||||
cvMeanShift( img, init_rect, criteria, &comp );
|
||||
}
|
||||
|
||||
|
||||
int CV_MeanShiftTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
CvPoint2D32f c;
|
||||
double m = MAX(box0.size.width, box0.size.height), delta;
|
||||
|
||||
if( cvIsNaN(comp.area) || cvIsInf(comp.area) || comp.area <= 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Invalid CvConnectedComp was returned by cvMeanShift\n" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
c.x = (float)(comp.rect.x + comp.rect.width*0.5);
|
||||
c.y = (float)(comp.rect.y + comp.rect.height*0.5);
|
||||
|
||||
if( fabs(c.x - box0.center.x) > m*0.1 ||
|
||||
fabs(c.y - box0.center.y) > m*0.1 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Incorrect CvBox2D position (=(%.1f, %.1f), should be (%.1f, %.1f))\n",
|
||||
c.x, c.y, box0.center.x, box0.center.y );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
delta = m*0.7;
|
||||
|
||||
if( comp.rect.x < box0.center.x - delta ||
|
||||
comp.rect.y < box0.center.y - delta ||
|
||||
comp.rect.x + comp.rect.width > box0.center.x + delta ||
|
||||
comp.rect.y + comp.rect.height > box0.center.y + delta )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"Incorrect CvConnectedComp ((%d,%d,%d,%d) is not within (%.1f,%.1f,%.1f,%.1f))\n",
|
||||
comp.rect.x, comp.rect.y, comp.rect.x + comp.rect.width, comp.rect.y + comp.rect.height,
|
||||
box0.center.x - delta, box0.center.y - delta, box0.center.x + delta, box0.center.y + delta );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( fabs((double)(comp.area - area0)) > fabs((double)(area - area0)) + area0*0.05 )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"Incorrect CvConnectedComp area (=%.1f, should be %d)\n", comp.area, area0 );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
if( code < 0 )
|
||||
{
|
||||
#if defined _DEBUG && defined WIN32
|
||||
IplImage* dst = cvCreateImage( img_size, 8, 3 );
|
||||
cvNamedWindow( "test", 1 );
|
||||
cvCmpS( img, 0, img, CV_CMP_GT );
|
||||
cvCvtColor( img, dst, CV_GRAY2BGR );
|
||||
cvRectangle( dst, cvPoint(init_rect.x, init_rect.y),
|
||||
cvPoint(init_rect.x + init_rect.width, init_rect.y + init_rect.height),
|
||||
CV_RGB(255,0,0), 3, 8, 0 );
|
||||
cvRectangle( dst, cvPoint(comp.rect.x, comp.rect.y),
|
||||
cvPoint(comp.rect.x + comp.rect.width, comp.rect.y + comp.rect.height),
|
||||
CV_RGB(0,255,0), 3, 8, 0 );
|
||||
cvShowImage( "test", dst );
|
||||
cvReleaseImage( &dst );
|
||||
cvWaitKey();
|
||||
#endif
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_MeanShiftTest meanshift_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,322 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_CannyTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_CannyTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
int validate_test_results( int /*test_case_idx*/ );
|
||||
|
||||
int aperture_size, use_true_gradient;
|
||||
double threshold1, threshold2;
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
CV_CannyTest::CV_CannyTest()
|
||||
: CvArrTest( "canny", "cvCanny, cvSobel", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
element_wise_relative_error = true;
|
||||
aperture_size = use_true_gradient = 0;
|
||||
threshold1 = threshold2 = 0;
|
||||
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
default_timing_param_names = 0;
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
double thresh_range;
|
||||
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8U;
|
||||
|
||||
aperture_size = cvTsRandInt(rng) % 2 ? 5 : 3;
|
||||
thresh_range = aperture_size == 3 ? 300 : 1000;
|
||||
|
||||
threshold1 = cvTsRandReal(rng)*thresh_range;
|
||||
threshold2 = cvTsRandReal(rng)*thresh_range*0.3;
|
||||
|
||||
if( cvTsRandInt(rng) % 2 )
|
||||
CV_SWAP( threshold1, threshold2, thresh_range );
|
||||
|
||||
use_true_gradient = cvTsRandInt(rng) % 2;
|
||||
test_cpp = (cvTsRandInt(rng) & 256) == 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_CannyTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
CvMat* src = &test_mat[INPUT][0];
|
||||
cvSmooth( src, src, CV_GAUSSIAN, 11, 11, 5, 5 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
double CV_CannyTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::run_func()
|
||||
{
|
||||
if(!test_cpp)
|
||||
cvCanny( test_array[INPUT][0], test_array[OUTPUT][0], threshold1, threshold2,
|
||||
aperture_size + (use_true_gradient ? CV_CANNY_L2_GRADIENT : 0));
|
||||
else
|
||||
{
|
||||
cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
|
||||
cv::Canny(cv::cvarrToMat(test_array[INPUT][0]), _out, threshold1, threshold2,
|
||||
aperture_size + (use_true_gradient ? CV_CANNY_L2_GRADIENT : 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
icvTsCannyFollow( int x, int y, float lowThreshold, const CvMat* mag, CvMat* dst )
|
||||
{
|
||||
static const int ofs[][2] = {{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};
|
||||
int i;
|
||||
|
||||
dst->data.ptr[dst->step*y + x] = (uchar)255;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
int x1 = x + ofs[i][0];
|
||||
int y1 = y + ofs[i][1];
|
||||
if( (unsigned)x1 < (unsigned)mag->cols &&
|
||||
(unsigned)y1 < (unsigned)mag->rows &&
|
||||
mag->data.fl[y1*mag->cols+x1] > lowThreshold &&
|
||||
!dst->data.ptr[dst->step*y1+x1] )
|
||||
icvTsCannyFollow( x1, y1, lowThreshold, mag, dst );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
icvTsCanny( const CvMat* src, CvMat* dst,
|
||||
double threshold1, double threshold2,
|
||||
int aperture_size, int use_true_gradient )
|
||||
{
|
||||
int m = aperture_size;
|
||||
CvMat* _src = cvCreateMat( src->rows + m - 1, src->cols + m - 1, CV_16S );
|
||||
CvMat* dx = cvCreateMat( src->rows, src->cols, CV_16S );
|
||||
CvMat* dy = cvCreateMat( src->rows, src->cols, CV_16S );
|
||||
CvMat* kernel = cvCreateMat( m, m, CV_32F );
|
||||
CvPoint anchor = {m/2, m/2};
|
||||
CvMat* mag = cvCreateMat( src->rows, src->cols, CV_32F );
|
||||
const double tan_pi_8 = tan(CV_PI/8.);
|
||||
const double tan_3pi_8 = tan(CV_PI*3/8);
|
||||
float lowThreshold = (float)MIN(threshold1, threshold2);
|
||||
float highThreshold = (float)MAX(threshold1, threshold2);
|
||||
|
||||
int x, y, width = src->cols, height = src->rows;
|
||||
|
||||
cvTsConvert( src, dx );
|
||||
cvTsPrepareToFilter( dx, _src, anchor, CV_TS_BORDER_REPLICATE );
|
||||
cvTsCalcSobelKernel2D( 1, 0, m, 0, kernel );
|
||||
cvTsConvolve2D( _src, dx, kernel, anchor );
|
||||
cvTsCalcSobelKernel2D( 0, 1, m, 0, kernel );
|
||||
cvTsConvolve2D( _src, dy, kernel, anchor );
|
||||
|
||||
/* estimate magnitude and angle */
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
const short* _dx = (short*)(dx->data.ptr + dx->step*y);
|
||||
const short* _dy = (short*)(dy->data.ptr + dy->step*y);
|
||||
float* _mag = (float*)(mag->data.ptr + mag->step*y);
|
||||
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
float mval = use_true_gradient ?
|
||||
(float)sqrt((double)(_dx[x]*_dx[x] + _dy[x]*_dy[x])) :
|
||||
(float)(abs(_dx[x]) + abs(_dy[x]));
|
||||
_mag[x] = mval;
|
||||
}
|
||||
}
|
||||
|
||||
/* nonmaxima suppression */
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
const short* _dx = (short*)(dx->data.ptr + dx->step*y);
|
||||
const short* _dy = (short*)(dy->data.ptr + dy->step*y);
|
||||
float* _mag = (float*)(mag->data.ptr + mag->step*y);
|
||||
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
int y1 = 0, y2 = 0, x1 = 0, x2 = 0;
|
||||
double tg;
|
||||
float a = _mag[x], b = 0, c = 0;
|
||||
|
||||
if( a <= lowThreshold )
|
||||
continue;
|
||||
|
||||
if( _dx[x] )
|
||||
tg = (double)_dy[x]/_dx[x];
|
||||
else
|
||||
tg = DBL_MAX*CV_SIGN(_dy[x]);
|
||||
|
||||
if( fabs(tg) < tan_pi_8 )
|
||||
{
|
||||
y1 = y2 = y; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else if( tan_pi_8 <= tg && tg <= tan_3pi_8 )
|
||||
{
|
||||
y1 = y + 1; y2 = y - 1; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else if( -tan_3pi_8 <= tg && tg <= -tan_pi_8 )
|
||||
{
|
||||
y1 = y - 1; y2 = y + 1; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( fabs(tg) > tan_3pi_8 );
|
||||
x1 = x2 = x; y1 = y + 1; y2 = y - 1;
|
||||
}
|
||||
|
||||
if( (unsigned)y1 < (unsigned)height && (unsigned)x1 < (unsigned)width )
|
||||
b = (float)fabs((double)mag->data.fl[y1*width+x1]);
|
||||
|
||||
if( (unsigned)y2 < (unsigned)height && (unsigned)x2 < (unsigned)width )
|
||||
c = (float)fabs((double)mag->data.fl[y2*width+x2]);
|
||||
|
||||
if( (a > b || (a == b && ((x1 == x+1 && y1 == y) || (x1 == x && y1 == y+1)))) && a > c )
|
||||
;
|
||||
else
|
||||
_mag[x] = -a;
|
||||
}
|
||||
}
|
||||
|
||||
cvTsZero( dst );
|
||||
|
||||
/* hysteresis threshold */
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
const float* _mag = (float*)(mag->data.ptr + mag->step*y);
|
||||
uchar* _dst = dst->data.ptr + dst->step*y;
|
||||
|
||||
for( x = 0; x < width; x++ )
|
||||
if( _mag[x] > highThreshold && !_dst[x] )
|
||||
icvTsCannyFollow( x, y, lowThreshold, mag, dst );
|
||||
}
|
||||
|
||||
cvReleaseMat( &_src );
|
||||
cvReleaseMat( &dx );
|
||||
cvReleaseMat( &dy );
|
||||
cvReleaseMat( &kernel );
|
||||
cvReleaseMat( &mag );
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::prepare_to_validation( int )
|
||||
{
|
||||
icvTsCanny( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0],
|
||||
threshold1, threshold2, aperture_size, use_true_gradient );
|
||||
|
||||
/*cv::Mat output(&test_mat[OUTPUT][0]);
|
||||
cv::Mat ref_output(&test_mat[REF_OUTPUT][0]);
|
||||
|
||||
cv::absdiff(output, ref_output, output);
|
||||
cv::namedWindow("ref test", 0);
|
||||
cv::imshow("ref test", ref_output);
|
||||
cv::namedWindow("test", 0);
|
||||
cv::imshow("test", output);
|
||||
cv::waitKey();*/
|
||||
}
|
||||
|
||||
|
||||
int CV_CannyTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
int code = CvTS::OK, nz0;
|
||||
prepare_to_validation(test_case_idx);
|
||||
|
||||
double err = cvNorm(&test_mat[OUTPUT][0], &test_mat[REF_OUTPUT][0], CV_L1);
|
||||
if( err == 0 )
|
||||
goto _exit_;
|
||||
|
||||
if( err != cvRound(err) || cvRound(err)%255 != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Some of the pixels, produced by Canny, are not 0's or 255's; the difference is %g\n", err );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
nz0 = cvCountNonZero(&test_mat[REF_OUTPUT][0]);
|
||||
err = (err/255/MAX(nz0,100))*100;
|
||||
if( err > 1 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Too high percentage of non-matching edge pixels = %g%%\n", err);
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_CannyTest canny_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,469 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
//#define GET_STAT
|
||||
|
||||
#define DIST_E "distE"
|
||||
#define S_E "sE"
|
||||
#define NO_PAIR_E "noPairE"
|
||||
//#define TOTAL_NO_PAIR_E "totalNoPairE"
|
||||
|
||||
#define DETECTOR_NAMES "detector_names"
|
||||
#define DETECTORS "detectors"
|
||||
#define IMAGE_FILENAMES "image_filenames"
|
||||
#define VALIDATION "validation"
|
||||
#define FILENAME "fn"
|
||||
|
||||
#define C_SCALE_CASCADE "scale_cascade"
|
||||
|
||||
class CV_DetectorTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_DetectorTest( const char* test_name );
|
||||
virtual int init( CvTS* system );
|
||||
protected:
|
||||
virtual int prepareData( FileStorage& fs );
|
||||
virtual void run( int startFrom );
|
||||
virtual string& getValidationFilename();
|
||||
|
||||
virtual void readDetector( const FileNode& fn ) = 0;
|
||||
virtual void writeDetector( FileStorage& fs, int di ) = 0;
|
||||
int runTestCase( int detectorIdx, vector<vector<Rect> >& objects );
|
||||
virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects ) = 0;
|
||||
int validate( int detectorIdx, vector<vector<Rect> >& objects );
|
||||
|
||||
struct
|
||||
{
|
||||
float dist;
|
||||
float s;
|
||||
float noPair;
|
||||
//float totalNoPair;
|
||||
} eps;
|
||||
vector<string> detectorNames;
|
||||
vector<string> detectorFilenames;
|
||||
vector<string> imageFilenames;
|
||||
vector<Mat> images;
|
||||
string validationFilename;
|
||||
FileStorage validationFS;
|
||||
};
|
||||
|
||||
CV_DetectorTest::CV_DetectorTest( const char* test_name ) : CvTest( test_name, "detectMultiScale" )
|
||||
{
|
||||
}
|
||||
|
||||
int CV_DetectorTest::init(CvTS *system)
|
||||
{
|
||||
clear();
|
||||
ts = system;
|
||||
string dataPath = ts->get_data_path();
|
||||
validationFS.open( dataPath + getValidationFilename(), FileStorage::READ );
|
||||
return prepareData( validationFS );
|
||||
}
|
||||
|
||||
string& CV_DetectorTest::getValidationFilename()
|
||||
{
|
||||
return validationFilename;
|
||||
}
|
||||
|
||||
int CV_DetectorTest::prepareData( FileStorage& _fs )
|
||||
{
|
||||
if( !_fs.isOpened() )
|
||||
test_case_count = -1;
|
||||
else
|
||||
{
|
||||
FileNode fn = _fs.getFirstTopLevelNode();
|
||||
|
||||
fn[DIST_E] >> eps.dist;
|
||||
fn[S_E] >> eps.s;
|
||||
fn[NO_PAIR_E] >> eps.noPair;
|
||||
// fn[TOTAL_NO_PAIR_E] >> eps.totalNoPair;
|
||||
|
||||
// read detectors
|
||||
if( fn[DETECTOR_NAMES].node->data.seq != 0 )
|
||||
{
|
||||
FileNodeIterator it = fn[DETECTOR_NAMES].begin();
|
||||
for( ; it != fn[DETECTOR_NAMES].end(); )
|
||||
{
|
||||
string name;
|
||||
it >> name;
|
||||
detectorNames.push_back(name);
|
||||
readDetector(fn[DETECTORS][name]);
|
||||
}
|
||||
}
|
||||
test_case_count = (int)detectorNames.size();
|
||||
|
||||
// read images filenames and images
|
||||
string dataPath = ts->get_data_path();
|
||||
if( fn[IMAGE_FILENAMES].node->data.seq != 0 )
|
||||
{
|
||||
for( FileNodeIterator it = fn[IMAGE_FILENAMES].begin(); it != fn[IMAGE_FILENAMES].end(); )
|
||||
{
|
||||
string filename;
|
||||
it >> filename;
|
||||
imageFilenames.push_back(filename);
|
||||
Mat img = imread( dataPath+filename, 1 );
|
||||
images.push_back( img );
|
||||
}
|
||||
}
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_DetectorTest::run( int start_from )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
start_from = 0;
|
||||
|
||||
#ifdef GET_STAT
|
||||
validationFS.release();
|
||||
string filename = ts->get_data_path();
|
||||
filename += getValidationFilename();
|
||||
validationFS.open( filename, FileStorage::WRITE );
|
||||
validationFS << FileStorage::getDefaultObjectName(validationFilename) << "{";
|
||||
|
||||
validationFS << DIST_E << eps.dist;
|
||||
validationFS << S_E << eps.s;
|
||||
validationFS << NO_PAIR_E << eps.noPair;
|
||||
// validationFS << TOTAL_NO_PAIR_E << eps.totalNoPair;
|
||||
|
||||
// write detector names
|
||||
validationFS << DETECTOR_NAMES << "[";
|
||||
vector<string>::const_iterator nit = detectorNames.begin();
|
||||
for( ; nit != detectorNames.end(); ++nit )
|
||||
{
|
||||
validationFS << *nit;
|
||||
}
|
||||
validationFS << "]"; // DETECTOR_NAMES
|
||||
|
||||
// write detectors
|
||||
validationFS << DETECTORS << "{";
|
||||
assert( detectorNames.size() == detectorFilenames.size() );
|
||||
nit = detectorNames.begin();
|
||||
for( int di = 0; di < detectorNames.size(), nit != detectorNames.end(); ++nit, di++ )
|
||||
{
|
||||
validationFS << *nit << "{";
|
||||
writeDetector( validationFS, di );
|
||||
validationFS << "}";
|
||||
}
|
||||
validationFS << "}";
|
||||
|
||||
// write image filenames
|
||||
validationFS << IMAGE_FILENAMES << "[";
|
||||
vector<string>::const_iterator it = imageFilenames.begin();
|
||||
for( int ii = 0; it != imageFilenames.end(); ++it, ii++ )
|
||||
{
|
||||
char buf[10];
|
||||
sprintf( buf, "%s%d", "img_", ii );
|
||||
cvWriteComment( validationFS.fs, buf, 0 );
|
||||
validationFS << *it;
|
||||
}
|
||||
validationFS << "]"; // IMAGE_FILENAMES
|
||||
|
||||
validationFS << VALIDATION << "{";
|
||||
#endif
|
||||
|
||||
int progress = 0;
|
||||
for( int di = 0; di < test_case_count; di++ )
|
||||
{
|
||||
progress = update_progress( progress, di, test_case_count, 0 );
|
||||
#ifdef GET_STAT
|
||||
validationFS << detectorNames[di] << "{";
|
||||
#endif
|
||||
vector<vector<Rect> > objects;
|
||||
int temp_code = runTestCase( di, objects );
|
||||
#ifndef GET_STAT
|
||||
if (temp_code == CvTS::OK)
|
||||
temp_code = validate( di, objects );
|
||||
#endif
|
||||
if (temp_code != CvTS::OK)
|
||||
code = temp_code;
|
||||
#ifdef GET_STAT
|
||||
validationFS << "}"; // detectorNames[di]
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GET_STAT
|
||||
validationFS << "}"; // VALIDATION
|
||||
validationFS << "}"; // getDefaultObjectName
|
||||
#endif
|
||||
if ( test_case_count <= 0 || imageFilenames.size() <= 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "validation file is not determined or not correct" );
|
||||
code = CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
int CV_DetectorTest::runTestCase( int detectorIdx, vector<vector<Rect> >& objects )
|
||||
{
|
||||
string dataPath = ts->get_data_path(), detectorFilename;
|
||||
if( !detectorFilenames[detectorIdx].empty() )
|
||||
detectorFilename = dataPath + detectorFilenames[detectorIdx];
|
||||
|
||||
for( int ii = 0; ii < (int)imageFilenames.size(); ++ii )
|
||||
{
|
||||
vector<Rect> imgObjects;
|
||||
Mat image = images[ii];
|
||||
if( image.empty() )
|
||||
{
|
||||
char msg[30];
|
||||
sprintf( msg, "%s %d %s", "image ", ii, " can not be read" );
|
||||
ts->printf( CvTS::LOG, msg );
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
int code = detectMultiScale( detectorIdx, image, imgObjects );
|
||||
if( code != CvTS::OK )
|
||||
return code;
|
||||
|
||||
objects.push_back( imgObjects );
|
||||
|
||||
#ifdef GET_STAT
|
||||
char buf[10];
|
||||
sprintf( buf, "%s%d", "img_", ii );
|
||||
string imageIdxStr = buf;
|
||||
validationFS << imageIdxStr << "[:";
|
||||
for( vector<Rect>::const_iterator it = imgObjects.begin();
|
||||
it != imgObjects.end(); ++it )
|
||||
{
|
||||
validationFS << it->x << it->y << it->width << it->height;
|
||||
}
|
||||
validationFS << "]"; // imageIdxStr
|
||||
#endif
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
|
||||
bool isZero( uchar i ) {return i == 0;}
|
||||
|
||||
int CV_DetectorTest::validate( int detectorIdx, vector<vector<Rect> >& objects )
|
||||
{
|
||||
assert( imageFilenames.size() == objects.size() );
|
||||
int imageIdx = 0;
|
||||
int totalNoPair = 0, totalValRectCount = 0;
|
||||
|
||||
for( vector<vector<Rect> >::const_iterator it = objects.begin();
|
||||
it != objects.end(); ++it, imageIdx++ ) // for image
|
||||
{
|
||||
Size imgSize = images[imageIdx].size();
|
||||
float dist = min(imgSize.height, imgSize.width) * eps.dist;
|
||||
float wDiff = imgSize.width * eps.s;
|
||||
float hDiff = imgSize.height * eps.s;
|
||||
|
||||
int noPair = 0;
|
||||
|
||||
// read validation rectangles
|
||||
char buf[10];
|
||||
sprintf( buf, "%s%d", "img_", imageIdx );
|
||||
string imageIdxStr = buf;
|
||||
FileNode node = validationFS.getFirstTopLevelNode()[VALIDATION][detectorNames[detectorIdx]][imageIdxStr];
|
||||
vector<Rect> valRects;
|
||||
if( node.node->data.seq != 0 )
|
||||
{
|
||||
for( FileNodeIterator it = node.begin(); it != node.end(); )
|
||||
{
|
||||
Rect r;
|
||||
it >> r.x >> r.y >> r.width >> r.height;
|
||||
valRects.push_back(r);
|
||||
}
|
||||
}
|
||||
totalValRectCount += (int)valRects.size();
|
||||
|
||||
// compare rectangles
|
||||
vector<uchar> map(valRects.size(), 0);
|
||||
for( vector<Rect>::const_iterator cr = it->begin();
|
||||
cr != it->end(); ++cr )
|
||||
{
|
||||
// find nearest rectangle
|
||||
Point2f cp1 = Point2f( cr->x + (float)cr->width/2.0f, cr->y + (float)cr->height/2.0f );
|
||||
int minIdx = -1, vi = 0;
|
||||
float minDist = (float)norm( Point(imgSize.width, imgSize.height) );
|
||||
for( vector<Rect>::const_iterator vr = valRects.begin();
|
||||
vr != valRects.end(); ++vr, vi++ )
|
||||
{
|
||||
Point2f cp2 = Point2f( vr->x + (float)vr->width/2.0f, vr->y + (float)vr->height/2.0f );
|
||||
float curDist = (float)norm(cp1-cp2);
|
||||
if( curDist < minDist )
|
||||
{
|
||||
minIdx = vi;
|
||||
minDist = curDist;
|
||||
}
|
||||
}
|
||||
if( minIdx == -1 )
|
||||
{
|
||||
noPair++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect vr = valRects[minIdx];
|
||||
if( map[minIdx] != 0 || (minDist > dist) || (abs(cr->width - vr.width) > wDiff) ||
|
||||
(abs(cr->height - vr.height) > hDiff) )
|
||||
noPair++;
|
||||
else
|
||||
map[minIdx] = 1;
|
||||
}
|
||||
}
|
||||
noPair += (int)count_if( map.begin(), map.end(), isZero );
|
||||
totalNoPair += noPair;
|
||||
if( noPair > cvRound(valRects.size()*eps.noPair)+1 )
|
||||
break;
|
||||
}
|
||||
if( imageIdx < (int)imageFilenames.size() )
|
||||
{
|
||||
char msg[500];
|
||||
sprintf( msg, "detector %s has overrated count of rectangles without pair on %s-image\n",
|
||||
detectorNames[detectorIdx].c_str(), imageFilenames[imageIdx].c_str() );
|
||||
ts->printf( CvTS::LOG, msg );
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
if ( totalNoPair > cvRound(totalValRectCount*eps./*total*/noPair)+1 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "overrated count of rectangles without pair on all images set" );
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------- CascadeDetectorTest -----------------------------------
|
||||
class CV_CascadeDetectorTest : public CV_DetectorTest
|
||||
{
|
||||
public:
|
||||
CV_CascadeDetectorTest( const char* test_name );
|
||||
protected:
|
||||
virtual void readDetector( const FileNode& fn );
|
||||
virtual void writeDetector( FileStorage& fs, int di );
|
||||
virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );
|
||||
vector<int> flags;
|
||||
};
|
||||
|
||||
CV_CascadeDetectorTest::CV_CascadeDetectorTest(const char *test_name)
|
||||
: CV_DetectorTest( test_name )
|
||||
{
|
||||
validationFilename = "cascadeandhog/cascade.xml";
|
||||
}
|
||||
|
||||
void CV_CascadeDetectorTest::readDetector( const FileNode& fn )
|
||||
{
|
||||
string filename;
|
||||
int flag;
|
||||
fn[FILENAME] >> filename;
|
||||
detectorFilenames.push_back(filename);
|
||||
fn[C_SCALE_CASCADE] >> flag;
|
||||
if( flag )
|
||||
flags.push_back( 0 );
|
||||
else
|
||||
flags.push_back( CV_HAAR_SCALE_IMAGE );
|
||||
}
|
||||
|
||||
void CV_CascadeDetectorTest::writeDetector( FileStorage& fs, int di )
|
||||
{
|
||||
int sc = flags[di] & CV_HAAR_SCALE_IMAGE ? 0 : 1;
|
||||
fs << FILENAME << detectorFilenames[di];
|
||||
fs << C_SCALE_CASCADE << sc;
|
||||
}
|
||||
|
||||
int CV_CascadeDetectorTest::detectMultiScale( int di, const Mat& img,
|
||||
vector<Rect>& objects)
|
||||
{
|
||||
string dataPath = ts->get_data_path(), filename;
|
||||
filename = dataPath + detectorFilenames[di];
|
||||
CascadeClassifier cascade( filename );
|
||||
if( cascade.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "cascade %s can not be opened");
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
Mat grayImg;
|
||||
cvtColor( img, grayImg, CV_BGR2GRAY );
|
||||
equalizeHist( grayImg, grayImg );
|
||||
cascade.detectMultiScale( grayImg, objects, 1.1, 3, flags[di] );
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------- HOGDetectorTest -----------------------------------
|
||||
class CV_HOGDetectorTest : public CV_DetectorTest
|
||||
{
|
||||
public:
|
||||
CV_HOGDetectorTest( const char* test_name );
|
||||
protected:
|
||||
virtual void readDetector( const FileNode& fn );
|
||||
virtual void writeDetector( FileStorage& fs, int di );
|
||||
virtual int detectMultiScale( int di, const Mat& img, vector<Rect>& objects );
|
||||
};
|
||||
|
||||
CV_HOGDetectorTest::CV_HOGDetectorTest(const char *test_name)
|
||||
: CV_DetectorTest( test_name )
|
||||
{
|
||||
validationFilename = "cascadeandhog/hog.xml";
|
||||
}
|
||||
|
||||
void CV_HOGDetectorTest::readDetector( const FileNode& fn )
|
||||
{
|
||||
string filename;
|
||||
if( fn[FILENAME].node->data.seq != 0 )
|
||||
fn[FILENAME] >> filename;
|
||||
detectorFilenames.push_back( filename);
|
||||
}
|
||||
|
||||
void CV_HOGDetectorTest::writeDetector( FileStorage& fs, int di )
|
||||
{
|
||||
fs << FILENAME << detectorFilenames[di];
|
||||
}
|
||||
|
||||
int CV_HOGDetectorTest::detectMultiScale( int di, const Mat& img,
|
||||
vector<Rect>& objects)
|
||||
{
|
||||
HOGDescriptor hog;
|
||||
if( detectorFilenames[di].empty() )
|
||||
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
|
||||
else
|
||||
assert(0);
|
||||
hog.detectMultiScale(img, objects);
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
CV_CascadeDetectorTest cascadeTest("cascade-detector");
|
||||
CV_HOGDetectorTest hogTest("hog-detector");
|
||||
@@ -1,455 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
#define _L2_ERR
|
||||
|
||||
void show_points( const Mat& gray, const Mat& u, const vector<Point2f>& v, Size pattern_size, bool was_found )
|
||||
{
|
||||
Mat rgb( gray.size(), CV_8U);
|
||||
merge(vector<Mat>(3, gray), rgb);
|
||||
|
||||
for(size_t i = 0; i < v.size(); i++ )
|
||||
circle( rgb, v[i], 3, CV_RGB(255, 0, 0), CV_FILLED);
|
||||
|
||||
if( !u.empty() )
|
||||
{
|
||||
const Point2f* u_data = u.ptr<Point2f>();
|
||||
size_t count = u.cols * u.rows;
|
||||
for(size_t i = 0; i < count; i++ )
|
||||
circle( rgb, u_data[i], 3, CV_RGB(0, 255, 0), CV_FILLED);
|
||||
}
|
||||
if (!v.empty())
|
||||
{
|
||||
Mat corners((int)v.size(), 1, CV_32FC2, (void*)&v[0]);
|
||||
drawChessboardCorners( rgb, pattern_size, corners, was_found );
|
||||
}
|
||||
//namedWindow( "test", 0 ); imshow( "test", rgb ); waitKey(0);
|
||||
}
|
||||
|
||||
|
||||
enum Pattern { CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
|
||||
|
||||
class CV_ChessboardDetectorTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ChessboardDetectorTest( Pattern pattern, const char* testName, const char* funcName );
|
||||
protected:
|
||||
void run(int);
|
||||
void run_batch(const string& filename);
|
||||
bool checkByGenerator();
|
||||
|
||||
Pattern pattern;
|
||||
};
|
||||
|
||||
CV_ChessboardDetectorTest::CV_ChessboardDetectorTest( Pattern _pattern, const char* testName, const char* funcName ):
|
||||
CvTest( testName, funcName )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
pattern = _pattern;
|
||||
}
|
||||
|
||||
double calcError(const vector<Point2f>& v, const Mat& u)
|
||||
{
|
||||
int count_exp = u.cols * u.rows;
|
||||
const Point2f* u_data = u.ptr<Point2f>();
|
||||
|
||||
double err = numeric_limits<double>::max();
|
||||
for( int k = 0; k < 2; ++k )
|
||||
{
|
||||
double err1 = 0;
|
||||
for( int j = 0; j < count_exp; ++j )
|
||||
{
|
||||
int j1 = k == 0 ? j : count_exp - j - 1;
|
||||
double dx = fabs( v[j].x - u_data[j1].x );
|
||||
double dy = fabs( v[j].y - u_data[j1].y );
|
||||
|
||||
#if defined(_L2_ERR)
|
||||
err1 += dx*dx + dy*dy;
|
||||
#else
|
||||
dx = MAX( dx, dy );
|
||||
if( dx > err1 )
|
||||
err1 = dx;
|
||||
#endif //_L2_ERR
|
||||
//printf("dx = %f\n", dx);
|
||||
}
|
||||
//printf("\n");
|
||||
err = min(err, err1);
|
||||
}
|
||||
|
||||
#if defined(_L2_ERR)
|
||||
err = sqrt(err/count_exp);
|
||||
#endif //_L2_ERR
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
const double rough_success_error_level = 2.5;
|
||||
const double precise_success_error_level = 2;
|
||||
|
||||
|
||||
/* ///////////////////// chess_corner_test ///////////////////////// */
|
||||
void CV_ChessboardDetectorTest::run( int /*start_from */)
|
||||
{
|
||||
/*if (!checkByGenerator())
|
||||
return;*/
|
||||
switch( pattern )
|
||||
{
|
||||
case CHESSBOARD:
|
||||
checkByGenerator();
|
||||
run_batch("chessboard_list.dat");
|
||||
run_batch("chessboard_list_subpixel.dat");
|
||||
break;
|
||||
case CIRCLES_GRID:
|
||||
run_batch("circles_list.dat");
|
||||
break;
|
||||
case ASYMMETRIC_CIRCLES_GRID:
|
||||
run_batch("acircles_list.dat");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
{
|
||||
CvTS& ts = *this->ts;
|
||||
ts.set_failed_test_info( CvTS::OK );
|
||||
|
||||
ts.printf(CvTS::LOG, "\nRunning batch %s\n", filename.c_str());
|
||||
//#define WRITE_POINTS 1
|
||||
#ifndef WRITE_POINTS
|
||||
double max_rough_error = 0, max_precise_error = 0;
|
||||
#endif
|
||||
string folder;
|
||||
switch( pattern )
|
||||
{
|
||||
case CHESSBOARD:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/";
|
||||
break;
|
||||
case CIRCLES_GRID:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/circles/";
|
||||
break;
|
||||
case ASYMMETRIC_CIRCLES_GRID:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/asymmetric_circles/";
|
||||
break;
|
||||
}
|
||||
|
||||
FileStorage fs( folder + filename, FileStorage::READ );
|
||||
FileNode board_list = fs["boards"];
|
||||
|
||||
if( !fs.isOpened() || board_list.empty() || !board_list.isSeq() || board_list.size() % 2 != 0 )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "%s can not be readed or is not valid\n", (folder + filename).c_str() );
|
||||
ts.printf( CvTS::LOG, "fs.isOpened=%d, board_list.empty=%d, board_list.isSeq=%d,board_list.size()%2=%d\n",
|
||||
fs.isOpened(), (int)board_list.empty(), board_list.isSeq(), board_list.size()%2);
|
||||
ts.set_failed_test_info( CvTS::FAIL_MISSING_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
int progress = 0;
|
||||
int max_idx = board_list.node->data.seq->total/2;
|
||||
double sum_error = 0.0;
|
||||
int count = 0;
|
||||
|
||||
for(int idx = 0; idx < max_idx; ++idx )
|
||||
{
|
||||
ts.update_context( this, idx, true );
|
||||
|
||||
/* read the image */
|
||||
string img_file = board_list[idx * 2];
|
||||
Mat gray = imread( folder + img_file, 0);
|
||||
|
||||
if( gray.empty() )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "one of chessboard images can't be read: %s\n", img_file.c_str() );
|
||||
ts.set_failed_test_info( CvTS::FAIL_MISSING_TEST_DATA );
|
||||
continue;
|
||||
}
|
||||
|
||||
string filename = folder + (string)board_list[idx * 2 + 1];
|
||||
Mat expected;
|
||||
{
|
||||
CvMat *u = (CvMat*)cvLoad( filename.c_str() );
|
||||
if(!u )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "one of chessboard corner files can't be read: %s\n", filename.c_str() );
|
||||
ts.set_failed_test_info( CvTS::FAIL_MISSING_TEST_DATA );
|
||||
continue;
|
||||
}
|
||||
expected = Mat(u, true);
|
||||
cvReleaseMat( &u );
|
||||
}
|
||||
size_t count_exp = static_cast<size_t>(expected.cols * expected.rows);
|
||||
Size pattern_size = expected.size();
|
||||
|
||||
vector<Point2f> v;
|
||||
bool result = false;
|
||||
switch( pattern )
|
||||
{
|
||||
case CHESSBOARD:
|
||||
result = findChessboardCorners(gray, pattern_size, v, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
|
||||
break;
|
||||
case CIRCLES_GRID:
|
||||
result = findCirclesGrid(gray, pattern_size, v, CALIB_CB_SYMMETRIC_GRID);
|
||||
break;
|
||||
case ASYMMETRIC_CIRCLES_GRID:
|
||||
result = findCirclesGrid(gray, pattern_size, v, CALIB_CB_ASYMMETRIC_GRID);
|
||||
break;
|
||||
}
|
||||
show_points( gray, Mat(), v, pattern_size, result );
|
||||
if( !result || v.size() != count_exp )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "chessboard is not found in %s\n", img_file.c_str() );
|
||||
ts.set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifndef WRITE_POINTS
|
||||
double err = calcError(v, expected);
|
||||
#if 0
|
||||
if( err > rough_success_error_level )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "bad accuracy of corner guesses\n" );
|
||||
ts.set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
max_rough_error = MAX( max_rough_error, err );
|
||||
#endif
|
||||
if( pattern == CHESSBOARD )
|
||||
cornerSubPix( gray, v, Size(5, 5), Size(-1,-1), TermCriteria(TermCriteria::EPS|TermCriteria::MAX_ITER, 30, 0.1));
|
||||
//find4QuadCornerSubpix(gray, v, Size(5, 5));
|
||||
show_points( gray, expected, v, pattern_size, result );
|
||||
|
||||
#ifndef WRITE_POINTS
|
||||
// printf("called find4QuadCornerSubpix\n");
|
||||
err = calcError(v, expected);
|
||||
sum_error += err;
|
||||
count++;
|
||||
#if 1
|
||||
if( err > precise_success_error_level )
|
||||
{
|
||||
ts.printf( CvTS::LOG, "Image %s: bad accuracy of adjusted corners %f\n", img_file.c_str(), err );
|
||||
ts.set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
ts.printf(CvTS::LOG, "Error on %s is %f\n", img_file.c_str(), err);
|
||||
max_precise_error = MAX( max_precise_error, err );
|
||||
#else
|
||||
Mat mat_v(pattern_size, CV_32FC2, (void*)&v[0]);
|
||||
CvMat cvmat_v = mat_v;
|
||||
cvSave( filename.c_str(), &cvmat_v );
|
||||
#endif
|
||||
progress = update_progress( progress, idx, max_idx, 0 );
|
||||
}
|
||||
|
||||
sum_error /= count;
|
||||
ts.printf(CvTS::LOG, "Average error is %f\n", sum_error);
|
||||
}
|
||||
|
||||
double calcErrorMinError(const Size& cornSz, const vector<Point2f>& corners_found, const vector<Point2f>& corners_generated)
|
||||
{
|
||||
Mat m1(cornSz, CV_32FC2, (Point2f*)&corners_generated[0]);
|
||||
Mat m2; flip(m1, m2, 0);
|
||||
|
||||
Mat m3; flip(m1, m3, 1); m3 = m3.t(); flip(m3, m3, 1);
|
||||
|
||||
Mat m4 = m1.t(); flip(m4, m4, 1);
|
||||
|
||||
double min1 = min(calcError(corners_found, m1), calcError(corners_found, m2));
|
||||
double min2 = min(calcError(corners_found, m3), calcError(corners_found, m4));
|
||||
return min(min1, min2);
|
||||
}
|
||||
|
||||
bool validateData(const ChessBoardGenerator& cbg, const Size& imgSz,
|
||||
const vector<Point2f>& corners_generated)
|
||||
{
|
||||
Size cornersSize = cbg.cornersSize();
|
||||
Mat_<Point2f> mat(cornersSize.height, cornersSize.width, (Point2f*)&corners_generated[0]);
|
||||
|
||||
double minNeibDist = std::numeric_limits<double>::max();
|
||||
double tmp = 0;
|
||||
for(int i = 1; i < mat.rows - 2; ++i)
|
||||
for(int j = 1; j < mat.cols - 2; ++j)
|
||||
{
|
||||
const Point2f& cur = mat(i, j);
|
||||
|
||||
tmp = norm( cur - mat(i + 1, j + 1) );
|
||||
if (tmp < minNeibDist)
|
||||
tmp = minNeibDist;
|
||||
|
||||
tmp = norm( cur - mat(i - 1, j + 1 ) );
|
||||
if (tmp < minNeibDist)
|
||||
tmp = minNeibDist;
|
||||
|
||||
tmp = norm( cur - mat(i + 1, j - 1) );
|
||||
if (tmp < minNeibDist)
|
||||
tmp = minNeibDist;
|
||||
|
||||
tmp = norm( cur - mat(i - 1, j - 1) );
|
||||
if (tmp < minNeibDist)
|
||||
tmp = minNeibDist;
|
||||
}
|
||||
|
||||
const double threshold = 0.25;
|
||||
double cbsize = (max(cornersSize.width, cornersSize.height) + 1) * minNeibDist;
|
||||
int imgsize = min(imgSz.height, imgSz.width);
|
||||
return imgsize * threshold < cbsize;
|
||||
}
|
||||
|
||||
bool CV_ChessboardDetectorTest::checkByGenerator()
|
||||
{
|
||||
bool res = true;
|
||||
//theRNG() = 0x58e6e895b9913160;
|
||||
//cv::DefaultRngAuto dra;
|
||||
//theRNG() = *ts->get_rng();
|
||||
|
||||
Mat bg(Size(800, 600), CV_8UC3, Scalar::all(255));
|
||||
randu(bg, Scalar::all(0), Scalar::all(255));
|
||||
GaussianBlur(bg, bg, Size(7,7), 3.0);
|
||||
|
||||
Mat_<float> camMat(3, 3);
|
||||
camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
|
||||
|
||||
Mat_<float> distCoeffs(1, 5);
|
||||
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
|
||||
|
||||
const Size sizes[] = { Size(6, 6), Size(8, 6), Size(11, 12), Size(5, 4) };
|
||||
const size_t sizes_num = sizeof(sizes)/sizeof(sizes[0]);
|
||||
const int test_num = 16;
|
||||
int progress = 0;
|
||||
for(int i = 0; i < test_num; ++i)
|
||||
{
|
||||
progress = update_progress( progress, i, test_num, 0 );
|
||||
ChessBoardGenerator cbg(sizes[i % sizes_num]);
|
||||
|
||||
vector<Point2f> corners_generated;
|
||||
|
||||
Mat cb = cbg(bg, camMat, distCoeffs, corners_generated);
|
||||
|
||||
if(!validateData(cbg, cb.size(), corners_generated))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Chess board skipped - too small" );
|
||||
continue;
|
||||
}
|
||||
|
||||
/*cb = cb * 0.8 + Scalar::all(30);
|
||||
GaussianBlur(cb, cb, Size(3, 3), 0.8); */
|
||||
//cv::addWeighted(cb, 0.8, bg, 0.2, 20, cb);
|
||||
//cv::namedWindow("CB"); cv::imshow("CB", cb); cv::waitKey();
|
||||
|
||||
vector<Point2f> corners_found;
|
||||
int flags = i % 8; // need to check branches for all flags
|
||||
bool found = findChessboardCorners(cb, cbg.cornersSize(), corners_found, flags);
|
||||
if (!found)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Chess board corners not found\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
res = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
double err = calcErrorMinError(cbg.cornersSize(), corners_found, corners_generated);
|
||||
if( err > rough_success_error_level )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of corner guesses" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
res = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* ***** negative ***** */
|
||||
{
|
||||
vector<Point2f> corners_found;
|
||||
bool found = findChessboardCorners(bg, Size(8, 7), corners_found);
|
||||
if (found)
|
||||
res = false;
|
||||
|
||||
ChessBoardGenerator cbg(Size(8, 7));
|
||||
|
||||
vector<Point2f> cg;
|
||||
Mat cb = cbg(bg, camMat, distCoeffs, cg);
|
||||
|
||||
found = findChessboardCorners(cb, Size(3, 4), corners_found);
|
||||
if (found)
|
||||
res = false;
|
||||
|
||||
Point2f c = std::accumulate(cg.begin(), cg.end(), Point2f(), plus<Point2f>()) * (1.f/cg.size());
|
||||
|
||||
Mat_<double> aff(2, 3);
|
||||
aff << 1.0, 0.0, -(double)c.x, 0.0, 1.0, 0.0;
|
||||
Mat sh;
|
||||
warpAffine(cb, sh, aff, cb.size());
|
||||
|
||||
found = findChessboardCorners(sh, cbg.cornersSize(), corners_found);
|
||||
if (found)
|
||||
res = false;
|
||||
|
||||
vector< vector<Point> > cnts(1);
|
||||
vector<Point>& cnt = cnts[0];
|
||||
cnt.push_back(cg[ 0]); cnt.push_back(cg[0+2]);
|
||||
cnt.push_back(cg[7+0]); cnt.push_back(cg[7+2]);
|
||||
cv::drawContours(cb, cnts, -1, Scalar::all(128), CV_FILLED);
|
||||
|
||||
found = findChessboardCorners(cb, cbg.cornersSize(), corners_found);
|
||||
if (found)
|
||||
res = false;
|
||||
|
||||
cv::drawChessboardCorners(cb, cbg.cornersSize(), Mat(corners_found), found);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
CV_ChessboardDetectorTest chessboard_detector_test ( CHESSBOARD, "chessboard-detector", "cvFindChessboardCorners" );
|
||||
CV_ChessboardDetectorTest circlesgrid_detector_test ( CIRCLES_GRID, "circlesgrid-detector", "findCirclesGrid" );
|
||||
CV_ChessboardDetectorTest asymmetric_circlesgrid_detector_test ( ASYMMETRIC_CIRCLES_GRID, "asymmetric-circlesgrid-detector", "findCirclesGrid" );
|
||||
|
||||
/* End of file. */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,220 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
class Differential
|
||||
{
|
||||
public:
|
||||
typedef Mat_<double> mat_t;
|
||||
|
||||
Differential(double eps_, const mat_t& rv1_, const mat_t& tv1_, const mat_t& rv2_, const mat_t& tv2_)
|
||||
: rv1(rv1_), tv1(tv1_), rv2(rv2_), tv2(tv2_), eps(eps_), ev(3, 1) {}
|
||||
|
||||
void dRv1(mat_t& dr3_dr1, mat_t& dt3_dr1)
|
||||
{
|
||||
dr3_dr1.create(3, 3); dt3_dr1.create(3, 3);
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
ev.setTo(Scalar(0)); ev(i, 0) = eps;
|
||||
|
||||
composeRT( rv1 + ev, tv1, rv2, tv2, rv3_p, tv3_p);
|
||||
composeRT( rv1 - ev, tv1, rv2, tv2, rv3_m, tv3_m);
|
||||
|
||||
dr3_dr1.col(i) = rv3_p - rv3_m;
|
||||
dt3_dr1.col(i) = tv3_p - tv3_m;
|
||||
}
|
||||
dr3_dr1 /= 2 * eps; dt3_dr1 /= 2 * eps;
|
||||
}
|
||||
|
||||
void dRv2(mat_t& dr3_dr2, mat_t& dt3_dr2)
|
||||
{
|
||||
dr3_dr2.create(3, 3); dt3_dr2.create(3, 3);
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
ev.setTo(Scalar(0)); ev(i, 0) = eps;
|
||||
|
||||
composeRT( rv1, tv1, rv2 + ev, tv2, rv3_p, tv3_p);
|
||||
composeRT( rv1, tv1, rv2 - ev, tv2, rv3_m, tv3_m);
|
||||
|
||||
dr3_dr2.col(i) = rv3_p - rv3_m;
|
||||
dt3_dr2.col(i) = tv3_p - tv3_m;
|
||||
}
|
||||
dr3_dr2 /= 2 * eps; dt3_dr2 /= 2 * eps;
|
||||
}
|
||||
|
||||
void dTv1(mat_t& drt3_dt1, mat_t& dt3_dt1)
|
||||
{
|
||||
drt3_dt1.create(3, 3); dt3_dt1.create(3, 3);
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
ev.setTo(Scalar(0)); ev(i, 0) = eps;
|
||||
|
||||
composeRT( rv1, tv1 + ev, rv2, tv2, rv3_p, tv3_p);
|
||||
composeRT( rv1, tv1 - ev, rv2, tv2, rv3_m, tv3_m);
|
||||
|
||||
drt3_dt1.col(i) = rv3_p - rv3_m;
|
||||
dt3_dt1.col(i) = tv3_p - tv3_m;
|
||||
}
|
||||
drt3_dt1 /= 2 * eps; dt3_dt1 /= 2 * eps;
|
||||
}
|
||||
|
||||
void dTv2(mat_t& dr3_dt2, mat_t& dt3_dt2)
|
||||
{
|
||||
dr3_dt2.create(3, 3); dt3_dt2.create(3, 3);
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
ev.setTo(Scalar(0)); ev(i, 0) = eps;
|
||||
|
||||
composeRT( rv1, tv1, rv2, tv2 + ev, rv3_p, tv3_p);
|
||||
composeRT( rv1, tv1, rv2, tv2 - ev, rv3_m, tv3_m);
|
||||
|
||||
dr3_dt2.col(i) = rv3_p - rv3_m;
|
||||
dt3_dt2.col(i) = tv3_p - tv3_m;
|
||||
}
|
||||
dr3_dt2 /= 2 * eps; dt3_dt2 /= 2 * eps;
|
||||
}
|
||||
|
||||
private:
|
||||
const mat_t& rv1, tv1, rv2, tv2;
|
||||
double eps;
|
||||
Mat_<double> ev;
|
||||
|
||||
Differential& operator=(const Differential&);
|
||||
Mat rv3_m, tv3_m, rv3_p, tv3_p;
|
||||
};
|
||||
|
||||
class CV_composeRT_Test : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_composeRT_Test()
|
||||
: CvTest( "composeRT", "cvComposeRT")
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
~CV_composeRT_Test() {}
|
||||
protected:
|
||||
|
||||
void run(int)
|
||||
{
|
||||
CvTS& ts = *this->ts;
|
||||
ts.set_failed_test_info(CvTS::OK);
|
||||
|
||||
Mat_<double> rvec1(3, 1), tvec1(3, 1), rvec2(3, 1), tvec2(3, 1);
|
||||
|
||||
randu(rvec1, Scalar(0), Scalar(6.29));
|
||||
randu(rvec2, Scalar(0), Scalar(6.29));
|
||||
|
||||
randu(tvec1, Scalar(-2), Scalar(2));
|
||||
randu(tvec2, Scalar(-2), Scalar(2));
|
||||
|
||||
Mat rvec3, tvec3;
|
||||
composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);
|
||||
|
||||
Mat rvec3_exp, tvec3_exp;
|
||||
|
||||
Mat rmat1, rmat2;
|
||||
Rodrigues(rvec1, rmat1);
|
||||
Rodrigues(rvec2, rmat2);
|
||||
Rodrigues(rmat2 * rmat1, rvec3_exp);
|
||||
|
||||
tvec3_exp = rmat2 * tvec1 + tvec2;
|
||||
|
||||
const double thres = 1e-5;
|
||||
if (norm(rvec3_exp, rvec3) > thres || norm(tvec3_exp, tvec3) > thres)
|
||||
ts.set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
|
||||
const double eps = 1e-3;
|
||||
Differential diff(eps, rvec1, tvec1, rvec2, tvec2);
|
||||
|
||||
Mat dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2;
|
||||
|
||||
composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3,
|
||||
dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);
|
||||
|
||||
Mat_<double> dr3_dr1, dt3_dr1;
|
||||
diff.dRv1(dr3_dr1, dt3_dr1);
|
||||
|
||||
if (norm(dr3_dr1, dr3dr1) > thres || norm(dt3_dr1, dt3dr1) > thres)
|
||||
{
|
||||
ts.printf( CvTS::LOG, "Invalid derivates by r1\n" );
|
||||
ts.set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dr2, dt3_dr2;
|
||||
diff.dRv2(dr3_dr2, dt3_dr2);
|
||||
|
||||
if (norm(dr3_dr2, dr3dr2) > thres || norm(dt3_dr2, dt3dr2) > thres)
|
||||
{
|
||||
ts.printf( CvTS::LOG, "Invalid derivates by r2\n" );
|
||||
ts.set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dt1, dt3_dt1;
|
||||
diff.dTv1(dr3_dt1, dt3_dt1);
|
||||
|
||||
if (norm(dr3_dt1, dr3dt1) > thres || norm(dt3_dt1, dt3dt1) > thres)
|
||||
{
|
||||
ts.printf( CvTS::LOG, "Invalid derivates by t1\n" );
|
||||
ts.set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dt2, dt3_dt2;
|
||||
diff.dTv2(dr3_dt2, dt3_dt2);
|
||||
|
||||
if (norm(dr3_dt2, dr3dt2) > thres || norm(dt3_dt2, dt3dt2) > thres)
|
||||
{
|
||||
ts.printf( CvTS::LOG, "Invalid derivates by t2\n" );
|
||||
ts.set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CV_composeRT_Test composeRT_test;
|
||||
@@ -1,147 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
/* Testing parameters */
|
||||
static char TestName[] = "State estimation of linear system by means of ConDens Algorithm";
|
||||
static char TestClass[] = "Algorithm";
|
||||
static int Dim;
|
||||
static int Steps;
|
||||
static int SamplesNum;
|
||||
|
||||
static int read_param = 0;
|
||||
static double EPSILON = 1.000;
|
||||
|
||||
static void CondProbDens(CvConDensation* CD, float* Measurement)
|
||||
{
|
||||
float Prob = 1;
|
||||
for(int i = 0; i < CD->SamplesNum;i++)
|
||||
{
|
||||
|
||||
Prob =1;
|
||||
for(int j =0; j < CD->DP;j++)
|
||||
{
|
||||
Prob*=(float)exp(-0.05*(Measurement[j] - CD->flSamples[i][j])*(Measurement[j]-CD->flSamples[i][j]));
|
||||
}
|
||||
|
||||
CD->flConfidence[i] = Prob;
|
||||
}
|
||||
|
||||
}
|
||||
static int fcaConDens( void )
|
||||
{
|
||||
AtsRandState noisegen;
|
||||
AtsRandState dynam;
|
||||
double Error = 0;
|
||||
CvConDensation* ConDens;
|
||||
|
||||
/* Initialization global parameters */
|
||||
if( !read_param )
|
||||
{
|
||||
read_param = 1;
|
||||
/* Reading test-parameters */
|
||||
trsiRead( &Dim,"7","Dimension of dynamical system");
|
||||
trsiRead( &Steps,"100","Length of trajectory to track");
|
||||
trsiRead( &SamplesNum,"64","Length of trajectory to track");
|
||||
}
|
||||
CvMat Sample = cvMat(Dim,1,CV_MAT32F,NULL);
|
||||
CvMat Temp = cvMat(Dim,1,CV_MAT32F,NULL);
|
||||
CvMat LB = cvMat(Dim,1,CV_MAT32F,NULL);
|
||||
CvMat UB = cvMat(Dim,1,CV_MAT32F,NULL);
|
||||
cvmAlloc(&LB);
|
||||
cvmAlloc(&UB);
|
||||
cvmAlloc(&Sample);
|
||||
cvmAlloc(&Temp);
|
||||
ConDens = cvCreateConDensation(Dim, Dim,SamplesNum);
|
||||
CvMat Dyn = cvMat(Dim,Dim,CV_MAT32F,ConDens->DynamMatr);
|
||||
atsRandInit(&dynam,-1.0, 1.0, 1);
|
||||
atsRandInit(&noisegen,-0.1, 0.1, 2);
|
||||
cvmSetIdentity(&Dyn);
|
||||
atsbRand32f(&dynam,Sample.data.fl,Dim);
|
||||
int i;
|
||||
for(i = 0; i<Dim; i++)
|
||||
{
|
||||
LB.data.fl[i] = -1.0f;
|
||||
UB.data.fl[i] = 1.0f;
|
||||
}
|
||||
cvConDensInitSampleSet(ConDens,&LB,&UB);
|
||||
CondProbDens(ConDens,Sample.data.fl);
|
||||
for( i = 0; i<Steps; i++)
|
||||
{
|
||||
cvConDensUpdateByTime(ConDens);
|
||||
int j;
|
||||
for(j = 0; j<Dim; j++)
|
||||
{
|
||||
float t = 0;
|
||||
for(int k=0; k<Dim; k++)
|
||||
{
|
||||
t += Dyn.data.fl[j*Dim+k]*Sample.data.fl[k];
|
||||
}
|
||||
Temp.data.fl[j]= t+atsRand32f(&noisegen);
|
||||
}
|
||||
|
||||
for(j = 0; j<Dim; j++)
|
||||
{
|
||||
Sample.data.fl[j] = Temp.data.fl[j];
|
||||
}
|
||||
CondProbDens(ConDens,Temp.data.fl);
|
||||
}
|
||||
Error = atsCompSinglePrec(Sample.data.fl,ConDens->State,Dim,EPSILON);
|
||||
cvmFree(&Sample);
|
||||
cvmFree(&Temp);
|
||||
cvmFree(&LB);
|
||||
cvmFree(&UB);
|
||||
cvReleaseConDensation(&ConDens);
|
||||
if(Error>=EPSILON)return TRS_FAIL;
|
||||
return TRS_OK;
|
||||
} /* fcaSobel8uC1R */
|
||||
void InitAConDens(void)
|
||||
{
|
||||
trsReg( "Condensation Algorithm", TestName, TestClass, fcaConDens);
|
||||
|
||||
} /* InitASobel */
|
||||
|
||||
/* End of file. */
|
||||
|
||||
#endif
|
||||
@@ -1,46 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -1,405 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_FindContourTest : public CvTest
|
||||
{
|
||||
public:
|
||||
enum { NUM_IMG = 4 };
|
||||
|
||||
CV_FindContourTest();
|
||||
~CV_FindContourTest();
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
int read_params( CvFileStorage* fs );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void run_func();
|
||||
|
||||
int min_blob_size, max_blob_size;
|
||||
int blob_count, max_log_blob_count;
|
||||
int retr_mode, approx_method;
|
||||
|
||||
int min_log_img_size, max_log_img_size;
|
||||
CvSize img_size;
|
||||
int count, count2;
|
||||
|
||||
IplImage* img[NUM_IMG];
|
||||
CvMemStorage* storage;
|
||||
CvSeq *contours, *contours2, *chain;
|
||||
};
|
||||
|
||||
|
||||
CV_FindContourTest::CV_FindContourTest() :
|
||||
CvTest( "contour-find", "cvFindContours, cvDrawContours, cvApproxChains" )
|
||||
{
|
||||
int i;
|
||||
|
||||
test_case_count = 300;
|
||||
min_blob_size = 1;
|
||||
max_blob_size = 50;
|
||||
max_log_blob_count = 10;
|
||||
|
||||
min_log_img_size = 3;
|
||||
max_log_img_size = 10;
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
img[i] = 0;
|
||||
|
||||
storage = 0;
|
||||
}
|
||||
|
||||
|
||||
CV_FindContourTest::~CV_FindContourTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_FindContourTest::clear()
|
||||
{
|
||||
int i;
|
||||
|
||||
CvTest::clear();
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
cvReleaseImage( &img[i] );
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
}
|
||||
|
||||
|
||||
int CV_FindContourTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
CvTest::write_default_params( fs );
|
||||
if( ts->get_testing_mode() != CvTS::TIMING_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
write_param( fs, "min_blob_size", min_blob_size );
|
||||
write_param( fs, "max_blob_size", max_blob_size );
|
||||
write_param( fs, "max_log_blob_count", max_log_blob_count );
|
||||
write_param( fs, "min_log_img_size", min_log_img_size );
|
||||
write_param( fs, "max_log_img_size", max_log_img_size );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_FindContourTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int t;
|
||||
int code = CvTest::read_params( fs );
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
min_blob_size = cvReadInt( find_param( fs, "min_blob_size" ), min_blob_size );
|
||||
max_blob_size = cvReadInt( find_param( fs, "max_blob_size" ), max_blob_size );
|
||||
max_log_blob_count = cvReadInt( find_param( fs, "max_log_blob_count" ), max_log_blob_count );
|
||||
min_log_img_size = cvReadInt( find_param( fs, "min_log_img_size" ), min_log_img_size );
|
||||
max_log_img_size = cvReadInt( find_param( fs, "max_log_img_size" ), max_log_img_size );
|
||||
|
||||
min_blob_size = cvTsClipInt( min_blob_size, 1, 100 );
|
||||
max_blob_size = cvTsClipInt( max_blob_size, 1, 100 );
|
||||
|
||||
if( min_blob_size > max_blob_size )
|
||||
CV_SWAP( min_blob_size, max_blob_size, t );
|
||||
|
||||
max_log_blob_count = cvTsClipInt( max_log_blob_count, 1, 10 );
|
||||
|
||||
min_log_img_size = cvTsClipInt( min_log_img_size, 1, 10 );
|
||||
max_log_img_size = cvTsClipInt( max_log_img_size, 1, 10 );
|
||||
|
||||
if( min_log_img_size > max_log_img_size )
|
||||
CV_SWAP( min_log_img_size, max_log_img_size, t );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsGenerateBlobImage( IplImage* img, int min_blob_size, int max_blob_size,
|
||||
int blob_count, int min_brightness, int max_brightness,
|
||||
CvRNG* rng )
|
||||
{
|
||||
int i;
|
||||
CvSize size;
|
||||
|
||||
assert( img->depth == IPL_DEPTH_8U && img->nChannels == 1 );
|
||||
|
||||
cvZero( img );
|
||||
|
||||
// keep the border clear
|
||||
cvSetImageROI( img, cvRect(1,1,img->width-2,img->height-2) );
|
||||
size = cvGetSize( img );
|
||||
|
||||
for( i = 0; i < blob_count; i++ )
|
||||
{
|
||||
CvPoint center;
|
||||
CvSize axes;
|
||||
int angle = cvTsRandInt(rng) % 180;
|
||||
int brightness = cvTsRandInt(rng) %
|
||||
(max_brightness - min_brightness) + min_brightness;
|
||||
center.x = cvTsRandInt(rng) % size.width;
|
||||
center.y = cvTsRandInt(rng) % size.height;
|
||||
|
||||
axes.width = (cvTsRandInt(rng) %
|
||||
(max_blob_size - min_blob_size) + min_blob_size + 1)/2;
|
||||
axes.height = (cvTsRandInt(rng) %
|
||||
(max_blob_size - min_blob_size) + min_blob_size + 1)/2;
|
||||
|
||||
cvEllipse( img, center, axes, angle, 0, 360, cvScalar(brightness), CV_FILLED );
|
||||
}
|
||||
|
||||
cvResetImageROI( img );
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsMarkContours( IplImage* img, int val )
|
||||
{
|
||||
int i, j;
|
||||
int step = img->widthStep;
|
||||
|
||||
assert( img->depth == IPL_DEPTH_8U && img->nChannels == 1 && (val&1) != 0);
|
||||
|
||||
for( i = 1; i < img->height - 1; i++ )
|
||||
for( j = 1; j < img->width - 1; j++ )
|
||||
{
|
||||
uchar* t = (uchar*)(img->imageData + img->widthStep*i + j);
|
||||
if( *t == 1 && (t[-step] == 0 || t[-1] == 0 || t[1] == 0 || t[step] == 0))
|
||||
*t = (uchar)val;
|
||||
}
|
||||
|
||||
cvThreshold( img, img, val - 2, val, CV_THRESH_BINARY );
|
||||
}
|
||||
|
||||
|
||||
int CV_FindContourTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
const int min_brightness = 0, max_brightness = 2;
|
||||
int i, code = CvTest::prepare_test_case( test_case_idx );
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
clear();
|
||||
|
||||
blob_count = cvRound(exp(cvTsRandReal(rng)*max_log_blob_count*CV_LOG2));
|
||||
|
||||
img_size.width = cvRound(exp((cvTsRandReal(rng)*
|
||||
(max_log_img_size - min_log_img_size) + min_log_img_size)*CV_LOG2));
|
||||
img_size.height = cvRound(exp((cvTsRandReal(rng)*
|
||||
(max_log_img_size - min_log_img_size) + min_log_img_size)*CV_LOG2));
|
||||
|
||||
approx_method = cvTsRandInt( rng ) % 4 + 1;
|
||||
retr_mode = cvTsRandInt( rng ) % 4;
|
||||
|
||||
storage = cvCreateMemStorage( 1 << 10 );
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
img[i] = cvCreateImage( img_size, 8, 1 );
|
||||
|
||||
cvTsGenerateBlobImage( img[0], min_blob_size, max_blob_size,
|
||||
blob_count, min_brightness, max_brightness, rng );
|
||||
|
||||
cvCopy( img[0], img[1] );
|
||||
cvCopy( img[0], img[2] );
|
||||
|
||||
cvTsMarkContours( img[1], 255 );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_FindContourTest::run_func()
|
||||
{
|
||||
contours = contours2 = chain = 0;
|
||||
count = cvFindContours( img[2], storage, &contours, sizeof(CvContour), retr_mode, approx_method );
|
||||
|
||||
cvZero( img[3] );
|
||||
|
||||
if( contours && retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
cvDrawContours( img[3], contours, cvScalar(255), cvScalar(255), INT_MAX, -1 );
|
||||
|
||||
cvCopy( img[0], img[2] );
|
||||
|
||||
count2 = cvFindContours( img[2], storage, &chain, sizeof(CvChain), retr_mode, CV_CHAIN_CODE );
|
||||
|
||||
if( chain )
|
||||
contours2 = cvApproxChains( chain, storage, approx_method, 0, 0, 1 );
|
||||
|
||||
cvZero( img[2] );
|
||||
|
||||
if( contours && retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
cvDrawContours( img[2], contours2, cvScalar(255), cvScalar(255), INT_MAX );
|
||||
}
|
||||
|
||||
|
||||
// the whole testing is done here, run_func() is not utilized in this test
|
||||
int CV_FindContourTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
int i, code = CvTS::OK;
|
||||
|
||||
cvCmpS( img[0], 0, img[0], CV_CMP_GT );
|
||||
|
||||
if( count != count2 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The number of contours retrieved with different "
|
||||
"approximation methods is not the same\n"
|
||||
"(%d contour(s) for method %d vs %d contour(s) for method %d)\n",
|
||||
count, approx_method, count2, CV_CHAIN_CODE );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
}
|
||||
|
||||
if( retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
{
|
||||
code = cvTsCmpEps2( ts, img[0], img[3], 0, true,
|
||||
"Comparing original image with the map of filled contours" );
|
||||
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
|
||||
code = cvTsCmpEps2( ts, img[1], img[2], 0, true,
|
||||
"Comparing contour outline vs manually produced edge map" );
|
||||
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( contours )
|
||||
{
|
||||
CvTreeNodeIterator iterator1;
|
||||
CvTreeNodeIterator iterator2;
|
||||
int count3;
|
||||
|
||||
for( i = 0; i < 2; i++ )
|
||||
{
|
||||
CvTreeNodeIterator iterator;
|
||||
cvInitTreeNodeIterator( &iterator, i == 0 ? contours : contours2, INT_MAX );
|
||||
|
||||
for( count3 = 0; cvNextTreeNode( &iterator ) != 0; count3++ )
|
||||
;
|
||||
|
||||
if( count3 != count )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The returned number of retrieved contours (using the approx_method = %d) does not match\n"
|
||||
"to the actual number of contours in the tree/list (returned %d, actual %d)\n",
|
||||
i == 0 ? approx_method : 0, count, count3 );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
|
||||
cvInitTreeNodeIterator( &iterator1, contours, INT_MAX );
|
||||
cvInitTreeNodeIterator( &iterator2, contours2, INT_MAX );
|
||||
|
||||
for( count3 = 0; count3 < count; count3++ )
|
||||
{
|
||||
CvSeq* seq1 = (CvSeq*)cvNextTreeNode( &iterator1 );
|
||||
CvSeq* seq2 = (CvSeq*)cvNextTreeNode( &iterator2 );
|
||||
CvSeqReader reader1;
|
||||
CvSeqReader reader2;
|
||||
|
||||
if( !seq1 || !seq2 )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"There are NULL pointers in the original contour tree or the "
|
||||
"tree produced by cvApproxChains\n" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
cvStartReadSeq( seq1, &reader1 );
|
||||
cvStartReadSeq( seq2, &reader2 );
|
||||
|
||||
if( seq1->total != seq2->total )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The original contour #%d has %d points, while the corresponding contour has %d point\n",
|
||||
count3, seq1->total, seq2->total );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
for( i = 0; i < seq1->total; i++ )
|
||||
{
|
||||
CvPoint pt1;
|
||||
CvPoint pt2;
|
||||
|
||||
CV_READ_SEQ_ELEM( pt1, reader1 );
|
||||
CV_READ_SEQ_ELEM( pt2, reader2 );
|
||||
|
||||
if( pt1.x != pt2.x || pt1.y != pt2.y )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The point #%d in the contour #%d is different from the corresponding point "
|
||||
"in the approximated chain ((%d,%d) vs (%d,%d)", count3, i, pt1.x, pt1.y, pt2.x, pt2.y );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exit_:
|
||||
if( code < 0 )
|
||||
{
|
||||
#if 0
|
||||
cvNamedWindow( "test", 0 );
|
||||
cvShowImage( "test", img[0] );
|
||||
cvWaitKey();
|
||||
#endif
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_FindContourTest find_contour_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,170 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
/*#include "conio.h"*/
|
||||
|
||||
static char cTestName[] = "Matching Contours";
|
||||
static char cTestClass[] = "Algorithm";
|
||||
static char cFuncName[] = "cvMatchContours";
|
||||
|
||||
static int aMatchContours(void)
|
||||
{
|
||||
CvSeqBlock contour_blk1, contour_blk2;
|
||||
CvContour contour_h1, contour_h2;
|
||||
CvContoursMatchMethod method;
|
||||
int nPoints1 = 20, nPoints2 = 20;
|
||||
int xc,yc,a1 = 10, b1 = 20, a2 = 15, b2 =30, fi = 0;
|
||||
int xmin,ymin,xmax,ymax;
|
||||
int seq_type;
|
||||
double error_test,rezult, eps_rez = 0.1;
|
||||
double pi = 3.1415926;
|
||||
int i;
|
||||
int code = TRS_OK;
|
||||
|
||||
int width=256,height=256;
|
||||
CvPoint *cp1,*cp2;
|
||||
|
||||
/* read tests params */
|
||||
|
||||
if (!trsiRead(&nPoints1,"20","Number of points first contour"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&nPoints2,"20","Number of points second contour"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
if(nPoints1>0&&nPoints2>0)
|
||||
{
|
||||
if (!trsiRead(&a1,"10","first radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&b1,"20","second radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&a2,"15","first radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&b2,"30","second radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&fi,"0","second radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
xc = (int)(width/2.);
|
||||
yc = (int)(height/2.);
|
||||
xmin = width;
|
||||
ymin = height;
|
||||
xmax = 0;
|
||||
ymax = 0;
|
||||
|
||||
cp1 = (CvPoint*) trsmAlloc(nPoints1*sizeof(CvPoint));
|
||||
cp2 = (CvPoint*) trsmAlloc(nPoints2*sizeof(CvPoint));
|
||||
|
||||
for(i=0;i<nPoints1;i++)
|
||||
{
|
||||
cp1[i].x = (int)(a1*cos(2*pi*i/nPoints1))+xc;
|
||||
cp1[i].y = (int)(b1*sin(2*pi*i/nPoints1))+yc;
|
||||
if(xmin> cp1[i].x) xmin = cp1[i].x;
|
||||
if(xmax< cp1[i].x) xmax = cp1[i].x;
|
||||
if(ymin> cp1[i].y) ymin = cp1[i].y;
|
||||
if(ymax< cp1[i].y) ymax = cp1[i].y;
|
||||
}
|
||||
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
|
||||
|
||||
for(i=0;i<nPoints2;i++)
|
||||
{
|
||||
cp2[i].x = (int)(a2*cos(2*pi*i/nPoints2)*cos(2*pi*fi/360.))-
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+xc;
|
||||
|
||||
cp2[i].y = (int)(a2*cos(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*cos(2*pi*fi/360.))+yc;
|
||||
|
||||
if(xmin> cp2[i].x) xmin = cp2[i].x;
|
||||
if(xmax< cp2[i].x) xmax = cp2[i].x;
|
||||
if(ymin> cp2[i].y) ymin = cp2[i].y;
|
||||
if(ymax< cp2[i].y) ymax = cp2[i].y;
|
||||
}
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
|
||||
|
||||
/* contours initialazing */
|
||||
seq_type = CV_SEQ_POLYGON;
|
||||
cvMakeSeqHeaderForArray( seq_type, sizeof(CvContour), sizeof(CvPoint),
|
||||
(char*)cp1, nPoints1, (CvSeq*)&contour_h1, &contour_blk1);
|
||||
|
||||
cvMakeSeqHeaderForArray( seq_type, sizeof(CvContour), sizeof(CvPoint),
|
||||
(char*)cp2, nPoints2, (CvSeq*)&contour_h2, &contour_blk2);
|
||||
|
||||
/* countours matchig */
|
||||
error_test = 0.;
|
||||
|
||||
for (i=1;i<=3;i++)
|
||||
{
|
||||
method = (CvContoursMatchMethod)i;
|
||||
rezult = cvMatchContours((CvSeq*)&contour_h1, (CvSeq*)&contour_h2, method);
|
||||
|
||||
error_test+=rezult;
|
||||
}
|
||||
error_test = error_test/3.;
|
||||
|
||||
if(error_test > eps_rez) code = TRS_FAIL;
|
||||
else code = TRS_OK;
|
||||
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "contours matching error_test =%f \n",
|
||||
error_test);
|
||||
|
||||
trsFree (cp2);
|
||||
trsFree (cp1);
|
||||
}
|
||||
|
||||
|
||||
/* _getch(); */
|
||||
return code;
|
||||
}
|
||||
|
||||
void InitAMatchContours( void )
|
||||
{
|
||||
/* Test Registartion */
|
||||
trsReg(cFuncName,cTestName,cTestClass,aMatchContours);
|
||||
|
||||
} /* InitAMatchContours */
|
||||
|
||||
/* End of file. */
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,245 +0,0 @@
|
||||
/*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 <limits>
|
||||
|
||||
#include "cvtest.h"
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class CV_ChessboardSubpixelTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ChessboardSubpixelTest();
|
||||
|
||||
protected:
|
||||
Mat intrinsic_matrix_;
|
||||
Mat distortion_coeffs_;
|
||||
Size image_size_;
|
||||
|
||||
void run(int);
|
||||
void generateIntrinsicParams();
|
||||
};
|
||||
|
||||
|
||||
int calcDistance(const vector<Point2f>& set1, const vector<Point2f>& set2, double& mean_dist)
|
||||
{
|
||||
if(set1.size() != set2.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<int> indices;
|
||||
double sum_dist = 0.0;
|
||||
for(size_t i = 0; i < set1.size(); i++)
|
||||
{
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
int min_idx = -1;
|
||||
|
||||
for(int j = 0; j < (int)set2.size(); j++)
|
||||
{
|
||||
double dist = norm(set1[i] - set2[j]);
|
||||
if(dist < min_dist)
|
||||
{
|
||||
min_idx = j;
|
||||
min_dist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
// check validity of min_idx
|
||||
if(min_idx == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
std::vector<int>::iterator it = std::find(indices.begin(), indices.end(), min_idx);
|
||||
if(it != indices.end())
|
||||
{
|
||||
// there are two points in set1 corresponding to the same point in set2
|
||||
return 0;
|
||||
}
|
||||
indices.push_back(min_idx);
|
||||
|
||||
// printf("dist %d = %f\n", (int)i, min_dist);
|
||||
|
||||
sum_dist += min_dist*min_dist;
|
||||
}
|
||||
|
||||
mean_dist = sqrt(sum_dist/set1.size());
|
||||
// printf("sum_dist = %f, set1.size() = %d, mean_dist = %f\n", sum_dist, (int)set1.size(), mean_dist);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
CV_ChessboardSubpixelTest::CV_ChessboardSubpixelTest():
|
||||
CvTest( "chessboard-subpixel", "cvFindCornerSubPix" ),
|
||||
intrinsic_matrix_(Size(3, 3), CV_64FC1), distortion_coeffs_(Size(1, 4), CV_64FC1),
|
||||
image_size_(640, 480)
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE | CvTS::TIMING_MODE;
|
||||
}
|
||||
|
||||
/* ///////////////////// chess_corner_test ///////////////////////// */
|
||||
void CV_ChessboardSubpixelTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
int progress = 0;
|
||||
|
||||
CvRNG* rng = ts->get_rng();
|
||||
|
||||
const int runs_count = 20;
|
||||
const int max_pattern_size = 8;
|
||||
const int min_pattern_size = 5;
|
||||
Mat bg(image_size_, CV_8UC1);
|
||||
bg = Scalar(0);
|
||||
|
||||
double sum_dist = 0.0;
|
||||
int count = 0;
|
||||
for(int i = 0; i < runs_count; i++)
|
||||
{
|
||||
const int pattern_width = min_pattern_size + cvRandInt(rng) % (max_pattern_size - min_pattern_size);
|
||||
const int pattern_height = min_pattern_size + cvRandInt(rng) % (max_pattern_size - min_pattern_size);
|
||||
Size pattern_size;
|
||||
if(pattern_width > pattern_height)
|
||||
{
|
||||
pattern_size = Size(pattern_height, pattern_width);
|
||||
}
|
||||
else
|
||||
{
|
||||
pattern_size = Size(pattern_width, pattern_height);
|
||||
}
|
||||
ChessBoardGenerator gen_chessboard(Size(pattern_size.width + 1, pattern_size.height + 1));
|
||||
|
||||
// generates intrinsic camera and distortion matrices
|
||||
generateIntrinsicParams();
|
||||
|
||||
vector<Point2f> corners;
|
||||
Mat chessboard_image = gen_chessboard(bg, intrinsic_matrix_, distortion_coeffs_, corners);
|
||||
|
||||
vector<Point2f> test_corners;
|
||||
bool result = findChessboardCorners(chessboard_image, pattern_size, test_corners, 15);
|
||||
if(!result)
|
||||
{
|
||||
#if 0
|
||||
ts->printf(CvTS::LOG, "Warning: chessboard was not detected! Writing image to test.jpg\n");
|
||||
ts->printf(CvTS::LOG, "Size = %d, %d\n", pattern_size.width, pattern_size.height);
|
||||
ts->printf(CvTS::LOG, "Intrinsic params: fx = %f, fy = %f, cx = %f, cy = %f\n",
|
||||
intrinsic_matrix_.at<double>(0, 0), intrinsic_matrix_.at<double>(1, 1),
|
||||
intrinsic_matrix_.at<double>(0, 2), intrinsic_matrix_.at<double>(1, 2));
|
||||
ts->printf(CvTS::LOG, "Distortion matrix: %f, %f, %f, %f, %f\n",
|
||||
distortion_coeffs_.at<double>(0, 0), distortion_coeffs_.at<double>(0, 1),
|
||||
distortion_coeffs_.at<double>(0, 2), distortion_coeffs_.at<double>(0, 3),
|
||||
distortion_coeffs_.at<double>(0, 4));
|
||||
|
||||
imwrite("test.jpg", chessboard_image);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
double dist1 = 0.0;
|
||||
int ret = calcDistance(corners, test_corners, dist1);
|
||||
if(ret == 0)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "findChessboardCorners returns invalid corner coordinates!\n");
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
}
|
||||
|
||||
IplImage chessboard_image_header = chessboard_image;
|
||||
cvFindCornerSubPix(&chessboard_image_header, (CvPoint2D32f*)&test_corners[0],
|
||||
(int)test_corners.size(), cvSize(3, 3), cvSize(1, 1), cvTermCriteria(CV_TERMCRIT_EPS|CV_TERMCRIT_ITER,300,0.1));
|
||||
find4QuadCornerSubpix(chessboard_image, test_corners, Size(5, 5));
|
||||
|
||||
double dist2 = 0.0;
|
||||
ret = calcDistance(corners, test_corners, dist2);
|
||||
if(ret == 0)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "findCornerSubpix returns invalid corner coordinates!\n");
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
}
|
||||
|
||||
ts->printf(CvTS::LOG, "Error after findChessboardCorners: %f, after findCornerSubPix: %f\n",
|
||||
dist1, dist2);
|
||||
sum_dist += dist2;
|
||||
count++;
|
||||
|
||||
const double max_reduce_factor = 0.8;
|
||||
if(dist1 < dist2*max_reduce_factor)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "findCornerSubPix increases average error!\n");
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
}
|
||||
|
||||
progress = update_progress( progress, i-1, runs_count, 0 );
|
||||
}
|
||||
sum_dist /= count;
|
||||
ts->printf(CvTS::LOG, "Average error after findCornerSubpix: %f\n", sum_dist);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
void CV_ChessboardSubpixelTest::generateIntrinsicParams()
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
const double max_focus_length = 1000.0;
|
||||
const double max_focus_diff = 5.0;
|
||||
|
||||
double fx = cvRandReal(rng)*max_focus_length;
|
||||
double fy = fx + cvRandReal(rng)*max_focus_diff;
|
||||
double cx = image_size_.width/2;
|
||||
double cy = image_size_.height/2;
|
||||
|
||||
double k1 = 0.5*cvRandReal(rng);
|
||||
double k2 = 0.05*cvRandReal(rng);
|
||||
double p1 = 0.05*cvRandReal(rng);
|
||||
double p2 = 0.05*cvRandReal(rng);
|
||||
double k3 = 0.0;
|
||||
|
||||
intrinsic_matrix_ = (Mat_<double>(3, 3) << fx, 0.0, cx, 0.0, fy, cy, 0.0, 0.0, 1.0);
|
||||
distortion_coeffs_ = (Mat_<double>(1, 5) << k1, k2, p1, p2, k3);
|
||||
}
|
||||
|
||||
CV_ChessboardSubpixelTest chessboard_subpixel_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,192 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
static char cTestName[] = "Binary tree create";
|
||||
static char cTestClass[] = "Algorithm";
|
||||
static char cFuncName[] = "cvCreateContourTree";
|
||||
|
||||
static int aCreateContourTree(void)
|
||||
{
|
||||
CvSeqBlock contour_blk1;
|
||||
CvContour contour_h1; /* input contour */
|
||||
CvSeq *contour_h2; /* destination contour */
|
||||
CvContourTree *tree; /* created binary tree */
|
||||
CvMemStorage *storage; /* storage for contour and tree writing */
|
||||
CvTermCriteria criteria; /* criteria for the contour restoring */
|
||||
/* CvSeqReader reader; // points reader of contour */
|
||||
/* ippiTrianAttr vertex;*/
|
||||
|
||||
int block_size = 10000;
|
||||
int nPoints1 = 20;
|
||||
int xc,yc,a1 = 10, b1 = 20, fi = 0;
|
||||
int xmin,ymin,xmax,ymax;
|
||||
double error_test;
|
||||
double pi = 3.1415926, eps_rez = 0.05;
|
||||
double threshold = 1.e-7;
|
||||
double rezult,error;
|
||||
int i, code = TRS_OK;
|
||||
int type_seq = 0;
|
||||
int width=256,height=256;
|
||||
CvPoint *cp1;
|
||||
CvPoint *cp2;
|
||||
|
||||
/* read tests params */
|
||||
|
||||
if (!trsiRead(&nPoints1,"20","Number of points first contour"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
if(nPoints1>0)
|
||||
{
|
||||
if (!trsiRead(&a1,"10","first radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&b1,"20","second radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
if (!trsiRead(&fi,"0","second radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
xc = (int)(width/2.);
|
||||
yc = (int)(height/2.);
|
||||
xmin = width;
|
||||
ymin = height;
|
||||
xmax = 0;
|
||||
ymax = 0;
|
||||
|
||||
cp1 = (CvPoint*) trsmAlloc(nPoints1*sizeof(CvPoint));
|
||||
cp2 = (CvPoint*) trsmAlloc(nPoints1*sizeof(CvPoint));
|
||||
|
||||
for(i=0;i<nPoints1;i++)
|
||||
{
|
||||
cp1[i].x = (int)(a1*cos(2*pi*i/nPoints1))+xc;
|
||||
cp1[i].y = (int)(b1*sin(2*pi*i/nPoints1))+yc;
|
||||
cp1[i].x = (int)(a1*cos(2*pi*i/nPoints1)*cos(2*pi*fi/360.))-
|
||||
(int)(b1*sin(2*pi*i/nPoints1)*sin(2*pi*fi/360.))+xc;
|
||||
|
||||
cp1[i].y = (int)(a1*cos(2*pi*i/nPoints1)*sin(2*pi*fi/360.))+
|
||||
(int)(b1*sin(2*pi*i/nPoints1)*cos(2*pi*fi/360.))+yc;
|
||||
|
||||
if(xmin> cp1[i].x) xmin = cp1[i].x;
|
||||
if(xmax< cp1[i].x) xmax = cp1[i].x;
|
||||
if(ymin> cp1[i].y) ymin = cp1[i].y;
|
||||
if(ymax< cp1[i].y) ymax = cp1[i].y;
|
||||
}
|
||||
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0)
|
||||
return TRS_FAIL;
|
||||
|
||||
|
||||
storage = cvCreateMemStorage( block_size );
|
||||
/* contours initialazing */
|
||||
|
||||
type_seq = CV_SEQ_POLYGON;
|
||||
cvMakeSeqHeaderForArray(type_seq, sizeof(CvContour), sizeof(CvPoint),
|
||||
(char*)cp1, nPoints1, (CvSeq*)&contour_h1, &contour_blk1);
|
||||
|
||||
/* create countour's tree */
|
||||
error_test = 0.;
|
||||
|
||||
tree = cvCreateContourTree ((CvSeq*)&contour_h1, storage, threshold);
|
||||
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "Contour's binary tree is created \n");
|
||||
|
||||
error = 0;
|
||||
criteria.type = CV_TERMCRIT_ITER;
|
||||
criteria.max_iter = 100;
|
||||
contour_h2 = cvContourFromContourTree (tree, storage, criteria);
|
||||
rezult = cvMatchContours ((CvSeq*)&contour_h1, contour_h2,CV_CONTOURS_MATCH_I1);
|
||||
|
||||
error+=rezult;
|
||||
|
||||
criteria.type = CV_TERMCRIT_EPS;
|
||||
criteria.epsilon = (float)0.00001;
|
||||
contour_h2 = cvContourFromContourTree (tree, storage, criteria);
|
||||
rezult = cvMatchContours ((CvSeq*)&contour_h1, contour_h2, CV_CONTOURS_MATCH_I1);
|
||||
error+=rezult;
|
||||
|
||||
criteria.type = CV_TERMCRIT_ITER + CV_TERMCRIT_EPS;
|
||||
criteria.epsilon = (float)0.00001;
|
||||
criteria.max_iter = 1;
|
||||
contour_h2 = cvContourFromContourTree (tree, storage, criteria);
|
||||
rezult = cvMatchContours ((CvSeq*)&contour_h1, contour_h2, CV_CONTOURS_MATCH_I1);
|
||||
error+=rezult;
|
||||
|
||||
criteria.type = CV_TERMCRIT_ITER + CV_TERMCRIT_EPS;
|
||||
criteria.epsilon = 1000.;
|
||||
criteria.max_iter = 100;
|
||||
contour_h2 = cvContourFromContourTree (tree, storage, criteria);
|
||||
rezult = cvMatchContours ((CvSeq*)&contour_h1, contour_h2, CV_CONTOURS_MATCH_I1);
|
||||
error+=rezult;
|
||||
|
||||
if(error > eps_rez )
|
||||
code = TRS_FAIL;
|
||||
else
|
||||
code = TRS_OK;
|
||||
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "contour from contour tree is restored rezult= %f \n",rezult);
|
||||
|
||||
cvCvtSeqToArray(contour_h2, (char*)cp2 );
|
||||
|
||||
cvReleaseMemStorage ( &storage );
|
||||
|
||||
trsFree (cp2);
|
||||
trsFree (cp1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* _getch(); */
|
||||
return code;
|
||||
}
|
||||
|
||||
void InitACreateContourTree( void )
|
||||
{
|
||||
/* Test Registartion */
|
||||
trsReg(cFuncName,cTestName,cTestClass,aCreateContourTree);
|
||||
|
||||
} /* InitACreateContourTree */
|
||||
|
||||
/* End of file. */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,358 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* distrans_param_names[] = { "size", "dist_type", "labels", 0 };
|
||||
static const CvSize distrans_sizes[] = {{30,30}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const CvSize distrans_whole_sizes[] = {{320,240}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const char* distrans_types[] = { "c_3x3", "l1_3x3", "l2_3x3", "l2_5x5", 0 };
|
||||
static const int distrans_labels[] = { 0, 1, -1 };
|
||||
|
||||
class CV_DisTransTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_DisTransTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );
|
||||
int mask_size;
|
||||
int dist_type;
|
||||
int fill_labels;
|
||||
float mask[3];
|
||||
};
|
||||
|
||||
|
||||
CV_DisTransTest::CV_DisTransTest()
|
||||
: CvArrTest( "distrans", "cvDistTransform", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
|
||||
default_timing_param_names = distrans_param_names;
|
||||
depth_list = 0;
|
||||
size_list = distrans_sizes;
|
||||
whole_size_list = distrans_whole_sizes;
|
||||
cn_list = 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_32FC1;
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32SC1;
|
||||
|
||||
if( cvTsRandInt(rng) & 1 )
|
||||
{
|
||||
mask_size = 3;
|
||||
dist_type = cvTsRandInt(rng) % 4;
|
||||
dist_type = dist_type == 0 ? CV_DIST_C : dist_type == 1 ? CV_DIST_L1 :
|
||||
dist_type == 2 ? CV_DIST_L2 : CV_DIST_USER;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_size = 5;
|
||||
dist_type = cvTsRandInt(rng) % 10;
|
||||
dist_type = dist_type == 0 ? CV_DIST_C : dist_type == 1 ? CV_DIST_L1 :
|
||||
dist_type < 6 ? CV_DIST_L2 : CV_DIST_USER;
|
||||
}
|
||||
|
||||
// for now, check only the "labeled" distance transform mode
|
||||
fill_labels = 0;
|
||||
|
||||
if( !fill_labels )
|
||||
sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = cvSize(0,0);
|
||||
|
||||
if( dist_type == CV_DIST_USER )
|
||||
{
|
||||
mask[0] = (float)(1.1 - cvTsRandReal(rng)*0.2);
|
||||
mask[1] = (float)(1.9 - cvTsRandReal(rng)*0.8);
|
||||
mask[2] = (float)(3. - cvTsRandReal(rng));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double CV_DisTransTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
CvSize sz = cvGetMatSize(&test_mat[INPUT][0]);
|
||||
return dist_type == CV_DIST_C || dist_type == CV_DIST_L1 ? 0 : 0.01*MAX(sz.width, sz.height);
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CvArrTest::get_minmax_bounds( i, j, type, low, high );
|
||||
if( i == INPUT && CV_MAT_DEPTH(type) == CV_8U )
|
||||
{
|
||||
*low = cvScalarAll(0);
|
||||
*high = cvScalarAll(10);
|
||||
}
|
||||
}
|
||||
|
||||
int CV_DisTransTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
// the function's response to an "all-nonzeros" image is not determined,
|
||||
// so put at least one zero point
|
||||
CvMat* mat = &test_mat[INPUT][0];
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int i = cvTsRandInt(rng) % mat->rows;
|
||||
int j = cvTsRandInt(rng) % mat->cols;
|
||||
mat->data.ptr[mat->step*i + j] = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::run_func()
|
||||
{
|
||||
cvDistTransform( test_array[INPUT][0], test_array[OUTPUT][0], dist_type, mask_size,
|
||||
dist_type == CV_DIST_USER ? mask : 0, test_array[OUTPUT][1] );
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsDistTransform( const CvMat* _src, CvMat* _dst, int dist_type,
|
||||
int mask_size, float* _mask, CvMat* /*_labels*/ )
|
||||
{
|
||||
int i, j, k;
|
||||
int width = _src->cols, height = _src->rows;
|
||||
const float init_val = 1e6;
|
||||
float mask[3];
|
||||
CvMat* temp;
|
||||
int ofs[16];
|
||||
float delta[16];
|
||||
int tstep, count;
|
||||
|
||||
assert( mask_size == 3 || mask_size == 5 );
|
||||
|
||||
if( dist_type == CV_DIST_USER )
|
||||
memcpy( mask, _mask, sizeof(mask) );
|
||||
else if( dist_type == CV_DIST_C )
|
||||
{
|
||||
mask_size = 3;
|
||||
mask[0] = mask[1] = 1.f;
|
||||
}
|
||||
else if( dist_type == CV_DIST_L1 )
|
||||
{
|
||||
mask_size = 3;
|
||||
mask[0] = 1.f;
|
||||
mask[1] = 2.f;
|
||||
}
|
||||
else if( mask_size == 3 )
|
||||
{
|
||||
mask[0] = 0.955f;
|
||||
mask[1] = 1.3693f;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask[0] = 1.0f;
|
||||
mask[1] = 1.4f;
|
||||
mask[2] = 2.1969f;
|
||||
}
|
||||
|
||||
temp = cvCreateMat( height + mask_size-1, width + mask_size-1, CV_32F );
|
||||
tstep = temp->step / sizeof(float);
|
||||
|
||||
if( mask_size == 3 )
|
||||
{
|
||||
count = 4;
|
||||
ofs[0] = -1; delta[0] = mask[0];
|
||||
ofs[1] = -tstep-1; delta[1] = mask[1];
|
||||
ofs[2] = -tstep; delta[2] = mask[0];
|
||||
ofs[3] = -tstep+1; delta[3] = mask[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 8;
|
||||
ofs[0] = -1; delta[0] = mask[0];
|
||||
ofs[1] = -tstep-2; delta[1] = mask[2];
|
||||
ofs[2] = -tstep-1; delta[2] = mask[1];
|
||||
ofs[3] = -tstep; delta[3] = mask[0];
|
||||
ofs[4] = -tstep+1; delta[4] = mask[1];
|
||||
ofs[5] = -tstep+2; delta[5] = mask[2];
|
||||
ofs[6] = -tstep*2-1; delta[6] = mask[2];
|
||||
ofs[7] = -tstep*2+1; delta[7] = mask[2];
|
||||
}
|
||||
|
||||
for( i = 0; i < mask_size/2; i++ )
|
||||
{
|
||||
float* t0 = (float*)(temp->data.ptr + i*temp->step);
|
||||
float* t1 = (float*)(temp->data.ptr + (temp->rows - i - 1)*temp->step);
|
||||
|
||||
for( j = 0; j < width + mask_size - 1; j++ )
|
||||
t0[j] = t1[j] = init_val;
|
||||
}
|
||||
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
uchar* s = _src->data.ptr + i*_src->step;
|
||||
float* tmp = (float*)(temp->data.ptr + temp->step*(i + (mask_size/2))) + (mask_size/2);
|
||||
|
||||
for( j = 0; j < mask_size/2; j++ )
|
||||
tmp[-j-1] = tmp[j + width] = init_val;
|
||||
|
||||
for( j = 0; j < width; j++ )
|
||||
{
|
||||
if( s[j] == 0 )
|
||||
tmp[j] = 0;
|
||||
else
|
||||
{
|
||||
float min_dist = init_val;
|
||||
for( k = 0; k < count; k++ )
|
||||
{
|
||||
float t = tmp[j+ofs[k]] + delta[k];
|
||||
if( min_dist > t )
|
||||
min_dist = t;
|
||||
}
|
||||
tmp[j] = min_dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( i = height - 1; i >= 0; i-- )
|
||||
{
|
||||
float* d = (float*)(_dst->data.ptr + i*_dst->step);
|
||||
float* tmp = (float*)(temp->data.ptr + temp->step*(i + (mask_size/2))) + (mask_size/2);
|
||||
|
||||
for( j = width - 1; j >= 0; j-- )
|
||||
{
|
||||
float min_dist = tmp[j];
|
||||
if( min_dist > mask[0] )
|
||||
{
|
||||
for( k = 0; k < count; k++ )
|
||||
{
|
||||
float t = tmp[j-ofs[k]] + delta[k];
|
||||
if( min_dist > t )
|
||||
min_dist = t;
|
||||
}
|
||||
tmp[j] = min_dist;
|
||||
}
|
||||
d[j] = min_dist;
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseMat( &temp );
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
cvTsDistTransform( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0],
|
||||
dist_type, mask_size, mask, 0 );
|
||||
}
|
||||
|
||||
|
||||
int CV_DisTransTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::TIMING_MODE )
|
||||
{
|
||||
start_write_param( fs );
|
||||
write_string_list( fs, "dist_type", distrans_types );
|
||||
write_int_list( fs, "labels", distrans_labels, -1, -1 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
const char* distype_str = cvReadString( find_timing_param( "dist_type" ), "l2_5x5" );
|
||||
mask_size = strstr( distype_str, "3x3" ) ? 3 : 5;
|
||||
dist_type = distype_str[0] == 'c' ? CV_DIST_C : distype_str[1] == '1' ? CV_DIST_L1 : CV_DIST_L2;
|
||||
fill_labels = cvReadInt( find_timing_param( "labels" ), 0 );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = CV_32FC1;
|
||||
types[OUTPUT][1] = CV_32SC1;
|
||||
|
||||
if( !fill_labels )
|
||||
sizes[OUTPUT][1] = whole_sizes[OUTPUT][1] = cvSize(0,0);
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "%s,", cvReadString( find_timing_param( "dist_type" ), "l2_5x5" ) );
|
||||
ptr += strlen(ptr);
|
||||
sprintf( ptr, "%s,", fill_labels ? "labels" : "no_labels" );
|
||||
ptr += strlen(ptr);
|
||||
params_left -= 2;
|
||||
|
||||
CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}
|
||||
|
||||
|
||||
CV_DisTransTest distrans_test;
|
||||
|
||||
|
||||
@@ -1,411 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include "highgui.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
//#define DRAW_TEST_IMAGE
|
||||
|
||||
class CV_DrawingTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest( const char* testName ) : CvTest( testName, "drawing funcs" ) {}
|
||||
protected:
|
||||
void run( int );
|
||||
virtual void draw( Mat& img ) = 0;
|
||||
virtual int checkLineIterator( Mat& img) = 0;
|
||||
};
|
||||
|
||||
void CV_DrawingTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
Mat testImg, valImg;
|
||||
const string name = "drawing/image.jpg";
|
||||
string path = ts->get_data_path(), filename;
|
||||
filename = path + name;
|
||||
|
||||
draw( testImg );
|
||||
|
||||
#ifdef DRAW_TEST_IMAGE
|
||||
imwrite( filename, testImg );
|
||||
#else
|
||||
valImg = imread( filename );
|
||||
if( valImg.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "test image can not be read");
|
||||
code = CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
float err = (float)norm( testImg, valImg, CV_RELATIVE_L1 );
|
||||
float Eps = 0.9f;
|
||||
if( err > Eps)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "CV_RELATIVE_L1 between testImg and valImg is equal %f (larger than %f)\n", err, Eps );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
else
|
||||
{
|
||||
code = checkLineIterator( testImg );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
class CV_DrawingTest_CPP : public CV_DrawingTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest_CPP() : CV_DrawingTest( "drawing_cpp" ) {}
|
||||
protected:
|
||||
virtual void draw( Mat& img );
|
||||
virtual int checkLineIterator( Mat& img);
|
||||
};
|
||||
|
||||
void CV_DrawingTest_CPP::draw( Mat& img )
|
||||
{
|
||||
Size imgSize( 600, 400 );
|
||||
img.create( imgSize, CV_8UC3 );
|
||||
|
||||
vector<Point> polyline(4);
|
||||
polyline[0] = Point(0, 0);
|
||||
polyline[1] = Point(imgSize.width, 0);
|
||||
polyline[2] = Point(imgSize.width, imgSize.height);
|
||||
polyline[3] = Point(0, imgSize.height);
|
||||
const Point* pts = &polyline[0];
|
||||
int n = (int)polyline.size();
|
||||
fillPoly( img, &pts, &n, 1, Scalar::all(255) );
|
||||
|
||||
Point p1(1,1), p2(3,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(300,100), 40, Scalar(0,0,255), 3 ); // draw
|
||||
|
||||
p2 = Point(3,imgSize.height+1000);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(500,300), 50, cvColorToScalar(255,CV_8UC3), 5, 8, 1 ); // draw
|
||||
|
||||
p1 = Point(imgSize.width,1), p2 = Point(imgSize.width,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(390,100), 10, Scalar(0,0,255), 3 ); // not draw
|
||||
|
||||
p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
ellipse( img, Point(390,100), Size(20,30), 60, 0, 220.0, Scalar(0,200,0), 4 ); //draw
|
||||
|
||||
ellipse( img, RotatedRect(Point(100,200),Size(200,100),160), Scalar(200,200,255), 5 );
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly( Point(430,180), Size(100,150), 30, 0, 150, 20, polyline );
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines( img, &pts, &n, 1, false, Scalar(0,0,150), 4, CV_AA );
|
||||
n = 0;
|
||||
for( vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
|
||||
{
|
||||
line( img, *it, *(it+1), Scalar(50,250,100));
|
||||
}
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly( Point(500,300), Size(50,80), 0, 0, 180, 10, polyline );
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines( img, &pts, &n, 1, true, Scalar(100,200,100), 20 );
|
||||
fillConvexPoly( img, pts, n, Scalar(0, 80, 0) );
|
||||
|
||||
polyline.resize(8);
|
||||
// external rectengular
|
||||
polyline[0] = Point(0, 0);
|
||||
polyline[1] = Point(80, 0);
|
||||
polyline[2] = Point(80, 80);
|
||||
polyline[3] = Point(0, 80);
|
||||
// internal rectangular
|
||||
polyline[4] = Point(20, 20);
|
||||
polyline[5] = Point(60, 20);
|
||||
polyline[6] = Point(60, 60);
|
||||
polyline[7] = Point(20, 60);
|
||||
const Point* ppts[] = {&polyline[0], &polyline[0]+4};
|
||||
int pn[] = {4, 4};
|
||||
fillPoly( img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20) );
|
||||
|
||||
rectangle( img, Point(0, 300), Point(50, 398), Scalar(0,0,255) );
|
||||
|
||||
string text1 = "OpenCV";
|
||||
int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
|
||||
float fontScale = 2;
|
||||
Size textSize = getTextSize( text1, fontFace, fontScale, thickness, &baseline);
|
||||
baseline += thickness;
|
||||
Point textOrg((img.cols - textSize.width)/2, (img.rows + textSize.height)/2);
|
||||
rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0,0,255));
|
||||
line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255));
|
||||
putText(img, text1, textOrg, fontFace, fontScale, Scalar(150,0,150), thickness, 8);
|
||||
|
||||
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
|
||||
Scalar color(200,0,0);
|
||||
fontScale = 0.5, thickness = 1;
|
||||
int dist = 5;
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg = Point(5,5)+Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 0.5;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,180) + Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
dist = 15, fontScale = 0.5;
|
||||
textSize = getTextSize( text2, FONT_ITALIC, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
|
||||
}
|
||||
|
||||
int CV_DrawingTest_CPP::checkLineIterator( Mat& img )
|
||||
{
|
||||
LineIterator it( img, Point(0,300), Point(1000, 300) );
|
||||
for(int i = 0; i < it.count; ++it, i++ )
|
||||
{
|
||||
Vec3b v = (Vec3b)(*(*it)) - img.at<Vec3b>(300,i);
|
||||
float err = (float)norm( v );
|
||||
if( err != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "LineIterator works incorrect" );
|
||||
return CvTS::FAIL_INVALID_OUTPUT;
|
||||
}
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
class CV_DrawingTest_C : public CV_DrawingTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest_C() : CV_DrawingTest( "drawing_c" ) {}
|
||||
protected:
|
||||
virtual void draw( Mat& img );
|
||||
virtual int checkLineIterator( Mat& img);
|
||||
};
|
||||
|
||||
void CV_DrawingTest_C::draw( Mat& _img )
|
||||
{
|
||||
CvSize imgSize = cvSize(600, 400);
|
||||
_img.create( imgSize, CV_8UC3 );
|
||||
CvMat img = _img;
|
||||
|
||||
vector<CvPoint> polyline(4);
|
||||
polyline[0] = cvPoint(0, 0);
|
||||
polyline[1] = cvPoint(imgSize.width, 0);
|
||||
polyline[2] = cvPoint(imgSize.width, imgSize.height);
|
||||
polyline[3] = cvPoint(0, imgSize.height);
|
||||
CvPoint* pts = &polyline[0];
|
||||
int n = (int)polyline.size();
|
||||
cvFillPoly( &img, &pts, &n, 1, cvScalar(255,255,255) );
|
||||
|
||||
CvPoint p1 = cvPoint(1,1), p2 = cvPoint(3,3);
|
||||
if( cvClipLine(imgSize, &p1, &p2) )
|
||||
cvCircle( &img, cvPoint(300,100), 40, cvScalar(0,0,255), 3 ); // draw
|
||||
|
||||
p1 = cvPoint(1,1), p2 = cvPoint(3,imgSize.height+1000);
|
||||
if( cvClipLine(imgSize, &p1, &p2) )
|
||||
cvCircle( &img, cvPoint(500,300), 50, cvScalar(255,0,0), 5, 8, 1 ); // draw
|
||||
|
||||
p1 = cvPoint(imgSize.width,1), p2 = cvPoint(imgSize.width,3);
|
||||
if( cvClipLine(imgSize, &p1, &p2) )
|
||||
cvCircle( &img, cvPoint(390,100), 10, cvScalar(0,0,255), 3 ); // not draw
|
||||
|
||||
p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3);
|
||||
if( cvClipLine(imgSize, &p1, &p2) )
|
||||
cvEllipse( &img, cvPoint(390,100), cvSize(20,30), 60, 0, 220.0, cvScalar(0,200,0), 4 ); //draw
|
||||
|
||||
CvBox2D box;
|
||||
box.center.x = 100;
|
||||
box.center.y = 200;
|
||||
box.size.width = 200;
|
||||
box.size.height = 100;
|
||||
box.angle = 160;
|
||||
cvEllipseBox( &img, box, Scalar(200,200,255), 5 );
|
||||
|
||||
polyline.resize(9);
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
assert( cvEllipse2Poly( cvPoint(430,180), cvSize(100,150), 30, 0, 150, &polyline[0], 20 ) == n );
|
||||
cvPolyLine( &img, &pts, &n, 1, false, cvScalar(0,0,150), 4, CV_AA );
|
||||
n = 0;
|
||||
for( vector<CvPoint>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
|
||||
{
|
||||
cvLine( &img, *it, *(it+1), cvScalar(50,250,100) );
|
||||
}
|
||||
|
||||
polyline.resize(19);
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
assert( cvEllipse2Poly( cvPoint(500,300), cvSize(50,80), 0, 0, 180, &polyline[0], 10 ) == n );
|
||||
cvPolyLine( &img, &pts, &n, 1, true, Scalar(100,200,100), 20 );
|
||||
cvFillConvexPoly( &img, pts, n, cvScalar(0, 80, 0) );
|
||||
|
||||
polyline.resize(8);
|
||||
// external rectengular
|
||||
polyline[0] = cvPoint(500, 20);
|
||||
polyline[1] = cvPoint(580, 20);
|
||||
polyline[2] = cvPoint(580, 100);
|
||||
polyline[3] = cvPoint(500, 100);
|
||||
// internal rectangular
|
||||
polyline[4] = cvPoint(520, 40);
|
||||
polyline[5] = cvPoint(560, 40);
|
||||
polyline[6] = cvPoint(560, 80);
|
||||
polyline[7] = cvPoint(520, 80);
|
||||
CvPoint* ppts[] = {&polyline[0], &polyline[0]+4};
|
||||
int pn[] = {4, 4};
|
||||
cvFillPoly( &img, ppts, pn, 2, cvScalar(100, 100, 0), 8, 0 );
|
||||
|
||||
cvRectangle( &img, cvPoint(0, 300), cvPoint(50, 398), cvScalar(0,0,255) );
|
||||
|
||||
string text1 = "OpenCV";
|
||||
CvFont font;
|
||||
cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 2, 2, 0, 3 );
|
||||
int baseline = 0;
|
||||
CvSize textSize;
|
||||
cvGetTextSize( text1.c_str(), &font, &textSize, &baseline );
|
||||
baseline += font.thickness;
|
||||
CvPoint textOrg = cvPoint((imgSize.width - textSize.width)/2, (imgSize.height + textSize.height)/2);
|
||||
cvRectangle( &img, cvPoint( textOrg.x, textOrg.y + baseline),
|
||||
cvPoint(textOrg.x + textSize.width, textOrg.y - textSize.height), cvScalar(0,0,255));
|
||||
cvLine( &img, cvPoint(textOrg.x, textOrg.y + font.thickness),
|
||||
cvPoint(textOrg.x + textSize.width, textOrg.y + font.thickness), cvScalar(0, 0, 255));
|
||||
cvPutText( &img, text1.c_str(), textOrg, &font, cvScalar(150,0,150) );
|
||||
|
||||
int dist = 5;
|
||||
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
|
||||
CvScalar color = cvScalar(200,0,0);
|
||||
cvInitFont( &font, FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(5, 5+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_TRIPLEX, 0.5, 0.5, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_COMPLEX_SMALL, 1, 1, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist + 180);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 1, 1, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
cvInitFont( &font, FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
|
||||
dist = 15;
|
||||
cvInitFont( &font, FONT_ITALIC, 0.5, 0.5, 0, 1, CV_AA );
|
||||
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
|
||||
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
|
||||
cvPutText(&img, text2.c_str(), textOrg, &font, color );
|
||||
}
|
||||
|
||||
int CV_DrawingTest_C::checkLineIterator( Mat& _img )
|
||||
{
|
||||
CvLineIterator it;
|
||||
CvMat img = _img;
|
||||
int count = cvInitLineIterator( &img, cvPoint(0,300), cvPoint(1000, 300), &it );
|
||||
for(int i = 0; i < count; i++ )
|
||||
{
|
||||
Vec3b v = (Vec3b)(*(it.ptr)) - _img.at<Vec3b>(300,i);
|
||||
float err = (float)norm( v );
|
||||
if( err != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "CvLineIterator works incorrect" );
|
||||
return CvTS::FAIL_INVALID_OUTPUT;
|
||||
}
|
||||
CV_NEXT_LINE_POINT(it);
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
CV_DrawingTest_CPP drawing_test_cpp;
|
||||
CV_DrawingTest_C drawing_test_c;
|
||||
@@ -1,375 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include <string.h>
|
||||
#include "highgui.h"
|
||||
|
||||
static char* funcs = "cvLine cvLineAA cvRectangle cvCircle cvCircleAA "
|
||||
"cvEllipse cvEllipseAA cvFillConvexPoly cvFillPoly"
|
||||
"cvPolyLine cvPolyLineAA cvPutText";
|
||||
static char* test_desc = "Drawing to image (regression test)";
|
||||
|
||||
static char* filedir_ = "drawing";
|
||||
|
||||
#ifndef RGB
|
||||
#define RGB(r,g,b) CV_RGB(b,g,r)
|
||||
#endif
|
||||
|
||||
static int my_tolower( int c )
|
||||
{
|
||||
return 'A' <= c && c <= 'Z' ? c + ('a' - 'A') : c;
|
||||
}
|
||||
|
||||
static int CheckImage(IplImage* image, char* file, char* /*funcname*/)
|
||||
{
|
||||
//printf("loading %s\n", file );
|
||||
IplImage* read = cvLoadImage( file, 1 );
|
||||
|
||||
if( !read )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "can't read image\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int err = 0;
|
||||
|
||||
#if 0
|
||||
{
|
||||
IplImage* temp = cvCloneImage( read );
|
||||
cvAbsDiff( image, read, temp );
|
||||
cvThreshold( temp, temp, 0, 255, CV_THRESH_BINARY );
|
||||
cvvNamedWindow( "Original", 0 );
|
||||
cvvNamedWindow( "Diff", 0 );
|
||||
cvvShowImage( "Original", read );
|
||||
cvvShowImage( "Diff", temp );
|
||||
cvvWaitKey(0);
|
||||
cvvDestroyWindow( "Original" );
|
||||
cvvDestroyWindow( "Diff" );
|
||||
}
|
||||
#endif
|
||||
|
||||
cvAbsDiff( image, read, read );
|
||||
cvThreshold( read, read, 0, 1, CV_THRESH_BINARY );
|
||||
err = cvRound( cvNorm( read, 0, CV_L1 ))/3;
|
||||
|
||||
cvReleaseImage( &read );
|
||||
return err;
|
||||
}
|
||||
|
||||
static int ProcessImage( IplImage* image, char* funcname, int read )
|
||||
{
|
||||
char name[1000];
|
||||
char lowername[1000];
|
||||
int i = 0, err;
|
||||
|
||||
do
|
||||
{
|
||||
lowername[i] = (char)my_tolower(funcname[i]);
|
||||
}
|
||||
while( funcname[i++] != '\0' );
|
||||
|
||||
if( read )
|
||||
{
|
||||
err = CheckImage( image,
|
||||
atsGetTestDataPath(name, filedir_, lowername, "bmp"),
|
||||
funcname );
|
||||
if( err )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "Error in %s: %d\n", funcname, err );
|
||||
}
|
||||
return 0; //err;
|
||||
}
|
||||
else
|
||||
{
|
||||
cvvSaveImage( atsGetTestDataPath(name, filedir_, lowername, "bmp"), image );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int drawing_test()
|
||||
{
|
||||
static int read_params = 0;
|
||||
static int read = 0;
|
||||
const int channel = 3;
|
||||
CvSize size = cvSize(600, 300);
|
||||
|
||||
int i, j;
|
||||
int Errors = 0;
|
||||
|
||||
if( !read_params )
|
||||
{
|
||||
read_params = 1;
|
||||
|
||||
trsCaseRead( &read, "/n/y", "y", "Read from file ?" );
|
||||
}
|
||||
// Create image
|
||||
IplImage* image = cvCreateImage( size, IPL_DEPTH_8U, channel );
|
||||
|
||||
// cvLine
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i++ )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
|
||||
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
|
||||
|
||||
cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvLine", read );
|
||||
|
||||
// cvLineAA
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i++ )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
|
||||
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
|
||||
|
||||
cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), 1, CV_AA, 0 );
|
||||
}
|
||||
//Errors += ProcessImage( image, "cvLineAA", read );
|
||||
|
||||
// cvRectangle
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i++ )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
|
||||
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
|
||||
|
||||
cvRectangle( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvRectangle", read );
|
||||
|
||||
#if 0
|
||||
named_window( "Diff", 0 );
|
||||
#endif
|
||||
|
||||
// cvCircle
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i++ )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i * 3, i * 2 );
|
||||
CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );
|
||||
|
||||
cvCircle( image, p1, i, CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
cvCircle( image, p2, i, CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
|
||||
#if 0
|
||||
show_iplimage( "Diff", image );
|
||||
wait_key(0);
|
||||
#endif
|
||||
}
|
||||
Errors += ProcessImage( image, "cvCircle", read );
|
||||
|
||||
// cvCircleAA
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i++ )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i * 3, i * 2 );
|
||||
CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );
|
||||
|
||||
cvCircleAA( image, p1, i, RGB(i, 255 - i, 178 + i), 0 );
|
||||
cvCircleAA( image, p2, i, RGB(i, 255 - i, 178 + i), 0 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvCircleAA", read );
|
||||
|
||||
// cvEllipse
|
||||
cvZero( image );
|
||||
|
||||
for( i = 10; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i * 6, i * 3 );
|
||||
CvSize axes = cvSize( i * 3, i * 2 );
|
||||
|
||||
cvEllipse( image, p1, axes,
|
||||
180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
|
||||
CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvEllipse", read );
|
||||
|
||||
// cvEllipseAA
|
||||
cvZero( image );
|
||||
|
||||
for( i = 10; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p1 = cvPoint( i * 6, i * 3 );
|
||||
CvSize axes = cvSize( i * 3, i * 2 );
|
||||
|
||||
cvEllipseAA( image, p1, axes,
|
||||
180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
|
||||
RGB(i, 255 - i, 178 + i), i % 10 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvEllipseAA", read );
|
||||
|
||||
// cvFillConvexPoly
|
||||
cvZero( image );
|
||||
|
||||
for( j = 0; j < 5; j++ )
|
||||
for( i = 0; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p[4] = {{ j * 100 - 10, i }, { j * 100 + 10, i },
|
||||
{ j * 100 + 30, i * 2 }, { j * 100 + 170, i * 3 }};
|
||||
cvFillConvexPoly( image, p, 4, CV_RGB(178+i, 255-i, i) );
|
||||
|
||||
}
|
||||
Errors += ProcessImage( image, "cvFillConvexPoly", read );
|
||||
|
||||
// cvFillPoly
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
|
||||
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
|
||||
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
|
||||
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
|
||||
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
|
||||
|
||||
CvPoint* p[] = {p0, p1, p2, p3, p4};
|
||||
|
||||
int n[] = {4, 4, 4, 4, 4};
|
||||
cvFillPoly( image, p, n, 5, CV_RGB(178+i, 255-i, i) );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvFillPoly", read );
|
||||
|
||||
// cvPolyLine
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
|
||||
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
|
||||
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
|
||||
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
|
||||
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
|
||||
|
||||
CvPoint* p[] = {p0, p1, p2, p3, p4};
|
||||
|
||||
int n[] = {4, 4, 4, 4, 4};
|
||||
cvPolyLine( image, p, n, 5, 1, CV_RGB(178+i, 255-i, i), i % 10 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvPolyLine", read );
|
||||
|
||||
// cvPolyLineAA
|
||||
cvZero( image );
|
||||
|
||||
for( i = 0; i < 100; i += 10 )
|
||||
{
|
||||
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
|
||||
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
|
||||
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
|
||||
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
|
||||
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
|
||||
|
||||
CvPoint* p[] = {p0, p1, p2, p3, p4};
|
||||
|
||||
int n[] = {4, 4, 4, 4, 4};
|
||||
cvPolyLineAA( image, p, n, 5, 1, RGB(i, 255 - i, 178 + i), 0 );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvPolyLineAA", read );
|
||||
|
||||
// cvPolyLineAA
|
||||
cvZero( image );
|
||||
|
||||
for( i = 1; i < 10; i++ )
|
||||
{
|
||||
CvFont font;
|
||||
cvInitFont( &font, CV_FONT_VECTOR0,
|
||||
(double)i / 5, (double)i / 5, (double)i / 10, i );
|
||||
cvPutText( image, "privet. this is test. :)", cvPoint(0, i * 20), &font, CV_RGB(178+i, 255-i, i) );
|
||||
}
|
||||
Errors += ProcessImage( image, "cvPutText", read );
|
||||
|
||||
cvReleaseImage( &image );
|
||||
|
||||
return Errors ? trsResult( TRS_FAIL, "errors" ) : trsResult( TRS_OK, "ok" );
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int resize_test()
|
||||
{
|
||||
IplImage* src = load_iplimage( "d:/user/vp/archive/art/greatwave.jpg" );
|
||||
IplImage* image = cvCreateImage( cvGetSize( src ), 8, 1 );
|
||||
|
||||
cvCvtColor( src, image, CV_BGR2GRAY );
|
||||
|
||||
named_window( "image", 1 );
|
||||
show_iplimage( "image", image );
|
||||
wait_key( 0 );
|
||||
|
||||
named_window( "result", 1 );
|
||||
|
||||
for( int i = 0; i < 30; i++ )
|
||||
{
|
||||
IplImage* dst = cvCreateImage(
|
||||
cvSize( (rand() % 1000) + 1, (rand() % 1000) + 1),
|
||||
8, image->nChannels );
|
||||
|
||||
cvResize( image, dst, CV_INTER_LINEAR );
|
||||
show_iplimage( "result", dst );
|
||||
|
||||
wait_key_ex( 0, 1000 );
|
||||
cvReleaseImage( &dst );
|
||||
}
|
||||
|
||||
cvReleaseImage( &image );
|
||||
destroy_window( "image" );
|
||||
destroy_window( "result" );
|
||||
|
||||
return CV_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void InitADrawingRegress()
|
||||
{
|
||||
/* Register test functions */
|
||||
trsReg( funcs, test_desc, atsAlgoClass, drawing_test );
|
||||
//trsReg( "cvResize", "", atsAlgoClass, resize_test );
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,771 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "aeigenobjects.inc"
|
||||
|
||||
#define __8U 8
|
||||
#define __32F 32
|
||||
#define MAXDIFF 1.01
|
||||
#define RELDIFF 1.0e-4
|
||||
|
||||
typedef struct _UserData /* User data structure for callback mode */
|
||||
{
|
||||
void* addr1; /* Array of objects ROI start addresses */
|
||||
void* addr2;
|
||||
int step1; /* Step in bytes */
|
||||
int step2;
|
||||
CvSize size1; /* ROI or full size */
|
||||
CvSize size2;
|
||||
} UserData;
|
||||
|
||||
/* Testing parameters */
|
||||
static char FuncName[] =
|
||||
"cvCalcCovarMatrixEx, cvCalcEigenObjects, cvCalcDecompCoeff, cvEigenDecomposite, cvEigenProjection";
|
||||
static char TestName[] = "Eigen objects functions group test";
|
||||
static char TestClass[] = "Algorithm";
|
||||
static int obj_number, obj_width, obj_height;
|
||||
static double rel_bufSize;
|
||||
|
||||
/*-----------------------------=--=-=== Callback functions ===-=--=---------------------*/
|
||||
|
||||
int read_callback_8u( int ind, void* buf, void* userData)
|
||||
{
|
||||
int i, j, k = 0;
|
||||
UserData* data = (UserData*)userData;
|
||||
uchar* start = ((uchar**)(data->addr1))[ind];
|
||||
uchar* buff = (uchar*)buf;
|
||||
|
||||
if( ind<0 ) return CV_BADFACTOR_ERR;
|
||||
if( buf==NULL || userData==NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
for( i=0; i<data->size1.height; i++, start+=data->step1 )
|
||||
for( j=0; j<data->size1.width; j++, k++ )
|
||||
buff[k] = start[j];
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
/*----------------------*/
|
||||
int read_callback_32f( int ind, void* buf, void* userData)
|
||||
{
|
||||
int i, j, k = 0;
|
||||
UserData* data = (UserData*)userData;
|
||||
float* start = ((float**)(data->addr2))[ind];
|
||||
float* buff = (float*)buf;
|
||||
|
||||
if( ind<0 ) return CV_BADFACTOR_ERR;
|
||||
if( buf==NULL || userData==NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
for( i=0; i<data->size2.height; i++, start+=data->step2/4 )
|
||||
for( j=0; j<data->size2.width; j++, k++ )
|
||||
buff[k] = start[j];
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
/*========================*/
|
||||
int write_callback_8u( int ind, void* buf, void* userData)
|
||||
{
|
||||
int i, j, k = 0;
|
||||
UserData* data = (UserData*)userData;
|
||||
uchar* start = ((uchar**)(data->addr1))[ind];
|
||||
uchar* buff = (uchar*)buf;
|
||||
|
||||
if( ind<0 ) return CV_BADFACTOR_ERR;
|
||||
if( buf==NULL || userData==NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
for( i=0; i<data->size1.height; i++, start+=data->step1 )
|
||||
for( j=0; j<data->size1.width; j++, k++ )
|
||||
start[j] = buff[k];
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
/*----------------------*/
|
||||
int write_callback_32f( int ind, void* buf, void* userData)
|
||||
{
|
||||
int i, j, k = 0;
|
||||
UserData* data = (UserData*)userData;
|
||||
float* start = ((float**)(data->addr2))[ind];
|
||||
float* buff = (float*)buf;
|
||||
|
||||
if( ind<0 ) return CV_BADFACTOR_ERR;
|
||||
if( buf==NULL || userData==NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
for( i=0; i<data->size2.height; i++, start+=data->step2/4 )
|
||||
for( j=0; j<data->size2.width; j++, k++ )
|
||||
start[j] = buff[k];
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
|
||||
/*##########################################=-- Test body --=###########################*/
|
||||
static int fmaEigenObjects( void )
|
||||
{
|
||||
int n, n4, i, j, ie, m1, rep = 0, roi, roi4, bufSize;
|
||||
int roix=0, roiy=0, sizex, sizey, step, step4, step44;
|
||||
int err0, err1, err2, err3, err4, err5, err6, err7, err=0;
|
||||
uchar *pro, *pro0, *object;
|
||||
uchar** objs;
|
||||
float *covMatr, *covMatr0, *avg, *avg0, *eigVal, *eigVal0, *coeffs, *coeffs0,
|
||||
covMatrMax, coeffm, singleCoeff0;
|
||||
float **eigObjs, **eigObjs0;
|
||||
IplImage **Objs, **EigObjs, **EigObjs0, *Pro, *Pro0, *Object, *Avg, *Avg0;
|
||||
double eps0, amax=0, singleCoeff, p;
|
||||
AtsRandState state;
|
||||
CvSize size;
|
||||
int r;
|
||||
CvTermCriteria limit;
|
||||
UserData userData;
|
||||
int (*read_callback)( int ind, void* buf, void* userData)=
|
||||
read_callback_8u;
|
||||
int (*read2_callback)( int ind, void* buf, void* userData)=
|
||||
read_callback_32f;
|
||||
int (*write_callback)( int ind, void* buf, void* userData)=
|
||||
write_callback_32f;
|
||||
CvInput* u_r = (CvInput*)&read_callback;
|
||||
CvInput* u_r2= (CvInput*)&read2_callback;
|
||||
CvInput* u_w = (CvInput*)&write_callback;
|
||||
void* read_ = (u_r)->data;
|
||||
void* read_2 = (u_r2)->data;
|
||||
void* write_ = (u_w)->data;
|
||||
|
||||
/* Reading test parameters */
|
||||
trsiRead( &obj_width, "100", "width of objects" );
|
||||
trsiRead( &obj_height, "100", "height of objects" );
|
||||
trsiRead( &obj_number, "11", "number of objects" );
|
||||
trsdRead( &rel_bufSize, "0.09", "relative i/o buffer size" );
|
||||
|
||||
if( rel_bufSize < 0.0 ) rel_bufSize = 0.0;
|
||||
m1 = obj_number - 1;
|
||||
eps0= 1.0e-27;
|
||||
n = obj_width * obj_height;
|
||||
sizex = obj_width, sizey = obj_height;
|
||||
|
||||
Objs = (IplImage**)cvAlloc(sizeof(IplImage*) * obj_number );
|
||||
EigObjs = (IplImage**)cvAlloc(sizeof(IplImage*) * m1 );
|
||||
EigObjs0 = (IplImage**)cvAlloc(sizeof(IplImage*) * m1 );
|
||||
|
||||
objs = (uchar**)cvAlloc(sizeof(uchar*) * obj_number );
|
||||
eigObjs = (float**)cvAlloc(sizeof(float*) * m1 );
|
||||
eigObjs0 = (float**)cvAlloc(sizeof(float*) * m1 );
|
||||
covMatr = (float*) cvAlloc(sizeof(float) * obj_number * obj_number );
|
||||
covMatr0 = (float*) cvAlloc(sizeof(float) * obj_number * obj_number );
|
||||
coeffs = (float*) cvAlloc(sizeof(float*) * m1 );
|
||||
coeffs0 = (float*) cvAlloc(sizeof(float*) * m1 );
|
||||
eigVal = (float*) cvAlloc(sizeof(float) * obj_number );
|
||||
eigVal0 = (float*) cvAlloc(sizeof(float) * obj_number );
|
||||
|
||||
size.width = obj_width; size.height = obj_height;
|
||||
atsRandInit( &state, 0, 255, 13 );
|
||||
|
||||
Avg = cvCreateImage( size, IPL_DEPTH_32F, 1 );
|
||||
cvSetImageROI( Avg, cvRect(0, 0, Avg->width, Avg->height) );
|
||||
Avg0 = cvCreateImage( size, IPL_DEPTH_32F, 1 );
|
||||
cvSetImageROI( Avg0, cvRect(0, 0, Avg0->width, Avg0->height) );
|
||||
avg = (float*)Avg->imageData;
|
||||
avg0 = (float*)Avg0->imageData;
|
||||
Pro = cvCreateImage( size, IPL_DEPTH_8U, 1 );
|
||||
cvSetImageROI( Pro, cvRect(0, 0, Pro->width, Pro->height) );
|
||||
Pro0 = cvCreateImage( size, IPL_DEPTH_8U, 1 );
|
||||
cvSetImageROI( Pro0, cvRect(0, 0, Pro0->width, Pro0->height) );
|
||||
pro = (uchar*)Pro->imageData;
|
||||
pro0 = (uchar*)Pro0->imageData;
|
||||
Object = cvCreateImage( size, IPL_DEPTH_8U, 1 );
|
||||
cvSetImageROI( Object, cvRect(0, 0, Object->width, Object->height) );
|
||||
object = (uchar*)Object->imageData;
|
||||
|
||||
step = Pro->widthStep; step4 = Avg->widthStep; step44 = step4/4;
|
||||
n = step*obj_height; n4= step44*obj_height;
|
||||
atsbRand8u ( &state, object, n );
|
||||
|
||||
for( i=0; i<obj_number; i++ )
|
||||
{
|
||||
Objs[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
|
||||
cvSetImageROI( Objs[i], cvRect(0, 0, Objs[i]->width, Objs[i]->height) );
|
||||
objs[i] = (uchar*)Objs[i]->imageData;
|
||||
atsbRand8u ( &state, objs[i], n );
|
||||
if( i < m1 )
|
||||
{
|
||||
EigObjs[i] = cvCreateImage( size, IPL_DEPTH_32F, 1 );
|
||||
cvSetImageROI( EigObjs[i], cvRect(0, 0, EigObjs[i]->width, EigObjs[i]->height) );
|
||||
EigObjs0[i] = cvCreateImage( size, IPL_DEPTH_32F, 1 );
|
||||
cvSetImageROI( EigObjs0[i], cvRect(0, 0, EigObjs0[i]->width, EigObjs0[i]->height) );
|
||||
}
|
||||
}
|
||||
|
||||
limit.type = CV_TERMCRIT_ITER; limit.max_iter = m1; limit.epsilon = 1;//(float)eps0;
|
||||
|
||||
bufSize = (int)(4*n*obj_number*rel_bufSize);
|
||||
trsWrite(TW_RUN|TW_CON, "\n i/o buffer size : %10d bytes\n", bufSize );
|
||||
|
||||
trsWrite(TW_RUN|TW_CON, "\n ROI unsupported\n" );
|
||||
|
||||
/* User data fill */
|
||||
userData.addr1 = (void*)objs;
|
||||
userData.addr2 = (void*)eigObjs;
|
||||
userData.step1 = step;
|
||||
userData.step2 = step4;
|
||||
|
||||
|
||||
repeat:
|
||||
roi = roiy*step + roix;
|
||||
roi4 = roiy*step44 + roix;
|
||||
|
||||
Avg->roi->xOffset = roix; Avg->roi->yOffset = roiy;
|
||||
Avg->roi->height = size.height; Avg->roi->width = size.width;
|
||||
Avg0->roi->xOffset = roix; Avg0->roi->yOffset = roiy;
|
||||
Avg0->roi->height = size.height; Avg0->roi->width = size.width;
|
||||
Pro->roi->xOffset = roix; Pro->roi->yOffset = roiy;
|
||||
Pro->roi->height = size.height; Pro->roi->width = size.width;
|
||||
Pro0->roi->xOffset = roix; Pro0->roi->yOffset = roiy;
|
||||
Pro0->roi->height = size.height; Pro0->roi->width = size.width;
|
||||
Object->roi->xOffset = roix; Object->roi->yOffset = roiy;
|
||||
Object->roi->height = size.height; Object->roi->width = size.width;
|
||||
|
||||
for( i=0; i<obj_number; i++ )
|
||||
{
|
||||
Objs[i]->roi->xOffset = roix; Objs[i]->roi->yOffset = roiy;
|
||||
Objs[i]->roi->height = size.height; Objs[i]->roi->width = size.width;
|
||||
objs[i] = (uchar*)Objs[i]->imageData + roi;
|
||||
if( i < m1 )
|
||||
{
|
||||
EigObjs[i]->roi->xOffset = roix; EigObjs[i]->roi->yOffset = roiy;
|
||||
EigObjs[i]->roi->height = size.height; EigObjs[i]->roi->width = size.width;
|
||||
EigObjs0[i]->roi->xOffset = roix; EigObjs0[i]->roi->yOffset = roiy;
|
||||
EigObjs0[i]->roi->height = size.height; EigObjs0[i]->roi->width = size.width;
|
||||
eigObjs[i] = (float*)EigObjs[i]->imageData + roi4;
|
||||
eigObjs0[i] = (float*)EigObjs0[i]->imageData + roi4;
|
||||
}
|
||||
}
|
||||
|
||||
userData.size1 = userData.size2 = size;
|
||||
|
||||
/* =================================== Test functions run ============================= */
|
||||
|
||||
r = _cvCalcEigenObjects_8u32fR_q( obj_number, objs, step, eigObjs0, step4,
|
||||
size, eigVal0, avg0+roi4, step4, &m1, &eps0 );
|
||||
|
||||
r = _cvEigenDecomposite_8u32fR_q( object+roi, step, m1, eigObjs0, step4,
|
||||
avg0+roi4, step4, size, coeffs0 );
|
||||
|
||||
r = _cvEigenProjection_8u32fR_q( m1, eigObjs0, step4, coeffs0, avg0+roi4, step4,
|
||||
pro0+roi, step, size );
|
||||
|
||||
r = _cvCalcCovarMatrix_8u32fR_q( obj_number, objs, step, avg0+roi4, step4,
|
||||
size, covMatr0 );
|
||||
|
||||
singleCoeff0 = _cvCalcDecompCoeff_8u32fR_q( object+roi, step, eigObjs0[0], step4,
|
||||
avg0+roi4, step4, size );
|
||||
|
||||
covMatrMax = 0.f;
|
||||
for( i=0; i<obj_number*obj_number; i++ )
|
||||
if( covMatrMax < (float)fabs( covMatr[i] ) )
|
||||
covMatrMax = (float)fabs( covMatr[i] );
|
||||
|
||||
amax = 0;
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*obj_width + j;
|
||||
float e = eigObjs0[ie][ij];
|
||||
if( amax < fabs(e) ) amax = fabs(e);
|
||||
}
|
||||
|
||||
coeffm = 0.f;
|
||||
for( i=0; i<m1; i++ )
|
||||
if( coeffm < (float)fabs(coeffs0[i]) ) coeffm = (float)fabs(coeffs0[i]);
|
||||
|
||||
/*- - - - - - - - - - - - - - - - - - - - - without callbacks - - - - - - - - - - - - - */
|
||||
for( i=0; i<obj_number*obj_number; i++ ) covMatr[i] = covMatr0[i];
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) pro[i*step + j] = pro0[i*step + j];
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) avg[i*step44 + j] = avg0[i*step44 + j];
|
||||
for( i=0; i<m1; i++ ) { coeffs[i] = coeffs0[i]; eigVal[i] = eigVal0[i]; }
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
eigObjs[ie][i*step44+j] = eigObjs0[ie][i*step44+j];
|
||||
|
||||
err1 = err2 = err3 = err4 = err5 = err6 = err7 = 0;
|
||||
|
||||
cvCalcCovarMatrixEx( obj_number,
|
||||
(void*)Objs,
|
||||
CV_EIGOBJ_NO_CALLBACK,
|
||||
bufSize,
|
||||
NULL,
|
||||
(void*)&userData,
|
||||
Avg,
|
||||
covMatr );
|
||||
|
||||
cvCalcEigenObjects ( obj_number,
|
||||
(void*)Objs,
|
||||
(void*)EigObjs,
|
||||
CV_EIGOBJ_NO_CALLBACK,
|
||||
bufSize,
|
||||
(void*)&userData,
|
||||
&limit,
|
||||
Avg,
|
||||
eigVal );
|
||||
|
||||
singleCoeff = cvCalcDecompCoeff( Object, EigObjs[0], Avg );
|
||||
if( fabs( (singleCoeff - singleCoeff0)/singleCoeff0 ) > RELDIFF ) err7++;
|
||||
|
||||
cvEigenDecomposite( Object,
|
||||
m1,
|
||||
(void*)EigObjs,
|
||||
CV_EIGOBJ_NO_CALLBACK,
|
||||
(void*)&userData,
|
||||
Avg,
|
||||
coeffs );
|
||||
cvEigenProjection ( (void*)EigObjs,
|
||||
m1,
|
||||
CV_EIGOBJ_NO_CALLBACK,
|
||||
(void*)&userData,
|
||||
coeffs,
|
||||
Avg,
|
||||
Pro );
|
||||
|
||||
/* Covariance matrix comparision */
|
||||
for( i=0; i<obj_number*obj_number; i++ )
|
||||
if( fabs(covMatr[i] - covMatr0[i]) > RELDIFF*fabs(covMatrMax) ) err6++;
|
||||
|
||||
/* Averaged object comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
if( fabs( (avg+roi)[ij] - (avg0+roi)[ij] ) > MAXDIFF ) err1++;
|
||||
}
|
||||
|
||||
/* Eigen objects comparision */
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
float e0 = (eigObjs0[ie])[ij], e = (eigObjs[ie])[ij];
|
||||
if( fabs( (e-e0)/amax ) > RELDIFF ) err2++;
|
||||
}
|
||||
|
||||
/* Eigen values comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
{
|
||||
double e0 = eigVal0[i], e = eigVal[i];
|
||||
if(e0)
|
||||
if( fabs( (e-e0)/e0 ) > RELDIFF ) err3++;
|
||||
}
|
||||
|
||||
/* Decomposition coefficients comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
if(coeffs0[i])
|
||||
if( fabs( (coeffs[i] - coeffs0[i])/coeffm ) > RELDIFF ) err4++;
|
||||
|
||||
/* Projection comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step + j;
|
||||
if( fabs( (double)((pro+roi)[ij] - (pro0+roi)[ij]) ) > MAXDIFF ) err5++;
|
||||
}
|
||||
|
||||
err0 = 0;
|
||||
p = 100.f*err6/(float)(obj_number*obj_number);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Covar. matrix - %d errors (%7.3f %% );\n", err6, p );
|
||||
err0 += err6;
|
||||
}
|
||||
p = 100.f*err1/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Averaged obj. - %d errors (%7.3f %% );\n", err1, p );
|
||||
err0 += err1;
|
||||
}
|
||||
p = 100.f*err3/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen values - %d errors (%7.3f %% );\n", err3, p );
|
||||
err0 += err3;
|
||||
}
|
||||
p = 100.f*err2/(float)(size.height*size.width*m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen objects - %d errors (%7.3f %% );\n", err2, p );
|
||||
err0 += err2;
|
||||
}
|
||||
p = 100.f*err4/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Decomp.coeffs - %d errors (%7.3f %% );\n", err4, p );
|
||||
err0 += err4;
|
||||
}
|
||||
if( ((float)err7)/m1 > 0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Single dec.c. - %d errors ;\n", err7);
|
||||
err0 += err7;
|
||||
}
|
||||
p = 100.f*err5/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Projection - %d errors (%7.3f %% );\n", err5, p );
|
||||
err0 += err5;
|
||||
}
|
||||
trsWrite(TW_RUN|TW_CON, " without callbacks : %8d errors;\n", err0 );
|
||||
|
||||
err += err0;
|
||||
|
||||
/*- - - - - - - - - - - - - - - - - - - - - input callback - - - - - - - - - - - - - */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) pro[i*step + j] = pro0[i*step + j];
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) avg[i*step44 + j] = avg0[i*step44 + j];
|
||||
for( i=0; i<m1; i++ ) { coeffs[i] = coeffs0[i]; eigVal[i] = eigVal0[i]; }
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
eigObjs[ie][i*step44+j] = eigObjs0[ie][i*step44+j];
|
||||
|
||||
err1 = err2 = err3 = err4 = err5 = err6 = err7 = 0;
|
||||
|
||||
cvCalcEigenObjects ( obj_number,
|
||||
read_,
|
||||
(void*)EigObjs,
|
||||
CV_EIGOBJ_INPUT_CALLBACK,
|
||||
bufSize,
|
||||
(void*)&userData,
|
||||
&limit,
|
||||
Avg,
|
||||
eigVal );
|
||||
|
||||
cvEigenDecomposite( Object,
|
||||
m1,
|
||||
read_2,
|
||||
CV_EIGOBJ_INPUT_CALLBACK,
|
||||
(void*)&userData,
|
||||
Avg,
|
||||
coeffs );
|
||||
|
||||
cvEigenProjection ( read_2,
|
||||
m1,
|
||||
CV_EIGOBJ_INPUT_CALLBACK,
|
||||
(void*)&userData,
|
||||
coeffs,
|
||||
Avg,
|
||||
Pro );
|
||||
|
||||
/* Averaged object comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
if( fabs( (avg+roi)[ij] - (avg0+roi)[ij] ) > MAXDIFF ) err1++;
|
||||
}
|
||||
|
||||
/* Eigen objects comparision */
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
float e0 = (eigObjs0[ie])[ij], e = (eigObjs[ie])[ij];
|
||||
if( fabs( (e-e0)/amax ) > RELDIFF ) err2++;
|
||||
}
|
||||
|
||||
/* Eigen values comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
{
|
||||
double e0 = eigVal0[i], e = eigVal[i];
|
||||
if(e0)
|
||||
if( fabs( (e-e0)/e0 ) > RELDIFF ) err3++;
|
||||
}
|
||||
|
||||
/* Projection comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step + j;
|
||||
if( fabs( (double)((pro+roi)[ij] - (pro0+roi)[ij]) ) > MAXDIFF ) err5++;
|
||||
}
|
||||
|
||||
/* Decomposition coefficients comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
if(coeffs0[i])
|
||||
if( fabs( (coeffs[i] - coeffs0[i])/coeffm ) > RELDIFF ) err4++;
|
||||
|
||||
err0 = 0;
|
||||
p = 100.f*err1/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Averaged obj. - %d errors (%7.3f %% );\n", err1, p );
|
||||
err0 += err1;
|
||||
}
|
||||
p = 100.f*err3/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen values - %d errors (%7.3f %% );\n", err3, p );
|
||||
err0 += err3;
|
||||
}
|
||||
p = 100.f*err2/(float)(size.height*size.width*m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen objects - %d errors (%7.3f %% );\n", err2, p );
|
||||
err0 += err2;
|
||||
}
|
||||
p = 100.f*err4/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Decomp.coeffs - %d errors (%7.3f %% );\n", err4, p );
|
||||
err0 += err4;
|
||||
}
|
||||
p = 100.f*err5/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Projection - %d errors (%7.3f %% );\n", err5, p );
|
||||
err0 += err5;
|
||||
}
|
||||
trsWrite(TW_RUN|TW_CON, " input callback : %8d errors;\n", err0 );
|
||||
|
||||
err += err0;
|
||||
|
||||
/*- - - - - - - - - - - - - - - - - - - - - output callback - - - - - - - - - - - - - */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) avg[i*step44 + j] = avg0[i*step44 + j];
|
||||
for( i=0; i<m1; i++ ) eigVal[i] = eigVal0[i];
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
eigObjs[ie][i*step44+j] = eigObjs0[ie][i*step44+j];
|
||||
|
||||
err1 = err2 = err3 = err4 = err5 = 0;
|
||||
|
||||
cvCalcEigenObjects ( obj_number,
|
||||
(void*)Objs,
|
||||
write_,
|
||||
CV_EIGOBJ_OUTPUT_CALLBACK,
|
||||
bufSize,
|
||||
(void*)&userData,
|
||||
&limit,
|
||||
Avg,
|
||||
eigVal );
|
||||
|
||||
/* Averaged object comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
if( fabs( (avg+roi)[ij] - (avg0+roi)[ij] ) > MAXDIFF ) err1++;
|
||||
}
|
||||
|
||||
/* Eigen objects comparision */
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
float e0 = (eigObjs0[ie])[ij], e = (eigObjs[ie])[ij];
|
||||
if( fabs( (e-e0)/amax ) > RELDIFF ) err2++;
|
||||
}
|
||||
|
||||
/* Eigen values comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
{
|
||||
double e0 = eigVal0[i], e = eigVal[i];
|
||||
if(e0)
|
||||
if( fabs( (e-e0)/e0 ) > RELDIFF ) err3++;
|
||||
}
|
||||
|
||||
err0 = 0;
|
||||
p = 100.f*err1/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Averaged obj. - %d errors (%7.3f %% );\n", err1, p );
|
||||
err0 += err1;
|
||||
}
|
||||
p = 100.f*err3/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen values - %d errors (%7.3f %% );\n", err3, p );
|
||||
err0 += err3;
|
||||
}
|
||||
p = 100.f*err2/(float)(size.height*size.width*m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen objects - %d errors (%7.3f %% );\n", err2, p );
|
||||
err0 += err2;
|
||||
}
|
||||
trsWrite(TW_RUN|TW_CON, " output callback : %8d errors;\n", err0 );
|
||||
|
||||
err += err0;
|
||||
|
||||
/*- - - - - - - - - - - - - - - - - - - - - both callbacks - - - - - - - - - - - - - */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ ) avg[i*step44 + j] = avg0[i*step44 + j];
|
||||
for( i=0; i<m1; i++ ) eigVal[i] = eigVal0[i];
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
eigObjs[ie][i*step44+j] = eigObjs0[ie][i*step44+j];
|
||||
|
||||
err1 = err2 = err3 = err4 = err5 = 0;
|
||||
|
||||
cvCalcEigenObjects ( obj_number,
|
||||
read_,
|
||||
write_,
|
||||
CV_EIGOBJ_INPUT_CALLBACK | CV_EIGOBJ_OUTPUT_CALLBACK,
|
||||
bufSize,
|
||||
(void*)&userData,
|
||||
&limit,
|
||||
Avg,
|
||||
eigVal );
|
||||
|
||||
/* Averaged object comparision */
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
if( fabs( (avg+roi)[ij] - (avg0+roi)[ij] ) > MAXDIFF ) err1++;
|
||||
}
|
||||
|
||||
/* Eigen objects comparision */
|
||||
for( ie=0; ie<m1; ie++ )
|
||||
for( i=0; i<size.height; i++ )
|
||||
for( j=0; j<size.width; j++ )
|
||||
{
|
||||
int ij = i*step44 + j;
|
||||
float e0 = (eigObjs0[ie])[ij], e = (eigObjs[ie])[ij];
|
||||
if( fabs( (e-e0)/amax ) > RELDIFF ) err2++;
|
||||
}
|
||||
|
||||
/* Eigen values comparision */
|
||||
for( i=0; i<m1; i++ )
|
||||
{
|
||||
double e0 = eigVal0[i], e = eigVal[i];
|
||||
if(e0)
|
||||
if( fabs( (e-e0)/e0 ) > RELDIFF ) err3++;
|
||||
}
|
||||
|
||||
err0 = 0;
|
||||
p = 100.f*err1/(float)(size.height*size.width);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Averaged obj. - %d errors (%7.3f %% );\n", err1, p );
|
||||
err0 += err1;
|
||||
}
|
||||
p = 100.f*err3/(float)(m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen values - %d errors (%7.3f %% );\n", err3, p );
|
||||
err0 += err3;
|
||||
}
|
||||
p = 100.f*err2/(float)(size.height*size.width*m1);
|
||||
if( p>0.1 )
|
||||
{
|
||||
trsWrite(TW_RUN|TW_CON, " Eigen objects - %d errors (%7.3f %% );\n", err2, p );
|
||||
err0 += err2;
|
||||
}
|
||||
trsWrite(TW_RUN|TW_CON, " both callbacks : %8d errors;\n", err0 );
|
||||
|
||||
err += err0;
|
||||
|
||||
|
||||
/*================================-- test with ROI --===================================*/
|
||||
|
||||
if(!rep)
|
||||
{
|
||||
roix = (int)(0.157f*obj_width);
|
||||
roiy = (int)(0.131f*obj_height);
|
||||
sizex = (int)(0.611f*obj_width);
|
||||
sizey = (int)(0.737f*obj_height);
|
||||
roi = roiy*obj_width + roix;
|
||||
|
||||
trsWrite(TW_RUN|TW_CON, "\n ROI supported\n" );
|
||||
rep++;
|
||||
size.width = sizex; size.height = sizey;
|
||||
|
||||
goto repeat;
|
||||
}
|
||||
|
||||
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ free memory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
cvReleaseImage( &Avg );
|
||||
cvReleaseImage( &Avg0 );
|
||||
cvReleaseImage( &Pro );
|
||||
cvReleaseImage( &Pro0 );
|
||||
cvReleaseImage( &Object );
|
||||
for( i=0; i<obj_number; i++ )
|
||||
{
|
||||
cvReleaseImage( &Objs[i] );
|
||||
if( i < m1 )
|
||||
{
|
||||
cvReleaseImage( &EigObjs[i] );
|
||||
cvReleaseImage( &EigObjs0[i] );
|
||||
}
|
||||
}
|
||||
|
||||
cvFree( &objs );
|
||||
cvFree( &eigObjs );
|
||||
cvFree( &eigObjs0 );
|
||||
cvFree( &coeffs );
|
||||
cvFree( &coeffs0 );
|
||||
cvFree( &eigVal );
|
||||
cvFree( &eigVal0 );
|
||||
cvFree( &Objs );
|
||||
cvFree( &EigObjs );
|
||||
cvFree( &EigObjs0 );
|
||||
cvFree( &covMatr );
|
||||
cvFree( &covMatr0 );
|
||||
|
||||
trsWrite(TW_RUN|TW_CON, "\n Errors number: %d\n", err );
|
||||
|
||||
if(err) return trsResult( TRS_FAIL, "Algorithm test has passed. %d errors.", err );
|
||||
else return trsResult( TRS_OK, "Algorithm test has passed successfully" );
|
||||
|
||||
} /*fma*/
|
||||
|
||||
/*------------------------------------------- Initialize function ------------------------ */
|
||||
void InitAEigenObjects( void )
|
||||
{
|
||||
/* Registering test function */
|
||||
trsReg( FuncName, TestName, TestClass, fmaEigenObjects );
|
||||
} /* InitAEigenObjects */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file */
|
||||
@@ -1,457 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
/*______________________________________________________________________________________*/
|
||||
/* */
|
||||
/* Test functions for the Eigen Objects functions group */
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
#include "cvtest.h"
|
||||
|
||||
static int _cvCalcCovarMatrix_8u32fR_q( int nObjects,
|
||||
uchar** objects,
|
||||
int objStep,
|
||||
float* avg,
|
||||
int avgStep,
|
||||
CvSize size,
|
||||
float* covarMatrix )
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if ( nObjects < 2 ) return CV_BADFACTOR_ERR;
|
||||
if ( size.width > objStep || 4*size.width > avgStep || size.height < 1)
|
||||
return CV_BADSIZE_ERR;
|
||||
if ( objects == NULL || avg == NULL || covarMatrix == NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
avgStep /= 4;
|
||||
|
||||
for(i=0; i<nObjects; i++)
|
||||
{
|
||||
uchar* bu = objects[i];
|
||||
for(j=i; j<nObjects; j++)
|
||||
{
|
||||
int ij = i*nObjects + j, k, l;
|
||||
float w = 0.f;
|
||||
float* a = avg;
|
||||
uchar* bu1 = bu;
|
||||
uchar* bu2 = objects[j];
|
||||
|
||||
for(k=0; k<size.height; k++, bu1 += objStep, bu2 += objStep, a += avgStep)
|
||||
{
|
||||
for(l = 0; l < size.width-3; l+=4)
|
||||
{
|
||||
float f = a [l];
|
||||
uchar u1 = bu1[l];
|
||||
uchar u2 = bu2[l];
|
||||
w += ( u1 - f ) * ( u2 - f );
|
||||
f = a [l+1];
|
||||
u1 = bu1[l+1];
|
||||
u2 = bu2[l+1];
|
||||
w += ( u1 - f ) * ( u2 - f );
|
||||
f = a [l+2];
|
||||
u1 = bu1[l+2];
|
||||
u2 = bu2[l+2];
|
||||
w += ( u1 - f ) * ( u2 - f );
|
||||
f = a [l+3];
|
||||
u1 = bu1[l+3];
|
||||
u2 = bu2[l+3];
|
||||
w += ( u1 - f ) * ( u2 - f );
|
||||
}
|
||||
for(; l < size.width; l++)
|
||||
{
|
||||
float f = a [l];
|
||||
uchar u1 = bu1[l];
|
||||
uchar u2 = bu2[l];
|
||||
w += ( u1 - f ) * ( u2 - f );
|
||||
}
|
||||
}
|
||||
|
||||
covarMatrix[ij] = w;
|
||||
ij = j*nObjects + i;
|
||||
covarMatrix[ij] = w;
|
||||
}
|
||||
}
|
||||
|
||||
return CV_NO_ERR;
|
||||
} /* end of _cvCalcCovarMatrix_8u32fR */
|
||||
|
||||
|
||||
/* copy of _cvJacobiEigen_32f */
|
||||
int _cvJacobiEigens_32f ( float* A,
|
||||
float* V,
|
||||
float* E,
|
||||
int n,
|
||||
float eps )
|
||||
{
|
||||
int i, j, k, ind;
|
||||
float *AA = A, *VV = V;
|
||||
double Amax, anorm=0, ax;
|
||||
|
||||
if ( A == NULL || V == NULL || E == NULL ) return CV_NULLPTR_ERR;
|
||||
if ( n <= 0 ) return CV_BADSIZE_ERR;
|
||||
if (eps < 1.0e-7f ) eps = 1.0e-7f;
|
||||
|
||||
/*-------- Prepare --------*/
|
||||
for(i=0; i<n; i++, VV+=n, AA+=n)
|
||||
{
|
||||
for(j=0; j<i; j++)
|
||||
{
|
||||
double Am = AA[j];
|
||||
anorm += Am*Am;
|
||||
}
|
||||
for(j=0; j<n; j++) VV[j] = 0.f;
|
||||
VV[i] = 1.f;
|
||||
}
|
||||
|
||||
anorm = sqrt( anorm + anorm );
|
||||
ax = anorm*eps/n;
|
||||
Amax = anorm;
|
||||
|
||||
while ( Amax > ax )
|
||||
{
|
||||
Amax /= n;
|
||||
do /* while (ind) */
|
||||
{
|
||||
int p, q;
|
||||
float *V1 = V, *A1 = A;
|
||||
ind = 0;
|
||||
for(p=0; p<n-1; p++, A1+=n, V1+=n)
|
||||
{
|
||||
float *A2 = A + n*(p+1), *V2 = V + n*(p+1);
|
||||
for(q=p+1; q<n; q++, A2+=n, V2+=n)
|
||||
{
|
||||
double x, y, c, s, c2, s2, a;
|
||||
float *A3, Apq=A1[q], App, Aqq, Aip, Aiq, Vpi, Vqi;
|
||||
if( fabs( Apq ) < Amax ) continue;
|
||||
|
||||
ind=1;
|
||||
|
||||
/*---- Calculation of rotation angle's sine & cosine ----*/
|
||||
App = A1[p];
|
||||
Aqq = A2[q];
|
||||
y = 5.0e-1*(App - Aqq);
|
||||
x = -Apq / sqrt(Apq*Apq + y*y);
|
||||
if(y<0.0) x = -x;
|
||||
s = x / sqrt(2.0*(1.0 + sqrt(1.0 - x*x)));
|
||||
s2 = s*s;
|
||||
c = sqrt(1.0 - s2);
|
||||
c2 = c*c;
|
||||
a = 2.0*Apq*c*s;
|
||||
|
||||
/*---- Apq annulation ----*/
|
||||
A3 = A;
|
||||
for(i=0; i<p; i++, A3+=n)
|
||||
{
|
||||
Aip = A3[p];
|
||||
Aiq = A3[q];
|
||||
Vpi = V1[i];
|
||||
Vqi = V2[i];
|
||||
A3[p] = (float)(Aip*c - Aiq*s);
|
||||
A3[q] = (float)(Aiq*c + Aip*s);
|
||||
V1[i] = (float)(Vpi*c - Vqi*s);
|
||||
V2[i] = (float)(Vqi*c + Vpi*s);
|
||||
}
|
||||
for(; i<q; i++, A3+=n)
|
||||
{
|
||||
Aip = A1[i];
|
||||
Aiq = A3[q];
|
||||
Vpi = V1[i];
|
||||
Vqi = V2[i];
|
||||
A1[i] = (float)(Aip*c - Aiq*s);
|
||||
A3[q] = (float)(Aiq*c + Aip*s);
|
||||
V1[i] = (float)(Vpi*c - Vqi*s);
|
||||
V2[i] = (float)(Vqi*c + Vpi*s);
|
||||
}
|
||||
for(; i<n; i++)
|
||||
{
|
||||
Aip = A1[i];
|
||||
Aiq = A2[i];
|
||||
Vpi = V1[i];
|
||||
Vqi = V2[i];
|
||||
A1[i] = (float)(Aip*c - Aiq*s);
|
||||
A2[i] = (float)(Aiq*c + Aip*s);
|
||||
V1[i] = (float)(Vpi*c - Vqi*s);
|
||||
V2[i] = (float)(Vqi*c + Vpi*s);
|
||||
}
|
||||
A1[p] = (float)(App*c2 + Aqq*s2 - a);
|
||||
A2[q] = (float)(App*s2 + Aqq*c2 + a);
|
||||
A1[q] = A2[p] = 0.0f;
|
||||
} /*q*/
|
||||
} /*p*/
|
||||
} while (ind);
|
||||
Amax /= n;
|
||||
} /* while ( Amax > ax ) */
|
||||
|
||||
for(i=0, k=0; i<n; i++, k+=n+1) E[i] = A[k];
|
||||
/*printf(" M = %d\n", M);*/
|
||||
|
||||
/* -------- ordering --------*/
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
int m = i;
|
||||
float Em = (float)fabs(E[i]);
|
||||
for(j=i+1; j<n; j++)
|
||||
{
|
||||
float Ej = (float)fabs(E[j]);
|
||||
m = ( Em < Ej ) ? j : m;
|
||||
Em = ( Em < Ej ) ? Ej : Em;
|
||||
}
|
||||
if( m != i )
|
||||
{
|
||||
int l;
|
||||
float b = E[i];
|
||||
E[i] = E[m];
|
||||
E[m] = b;
|
||||
for(j=0, k=i*n, l=m*n; j<n; j++, k++, l++)
|
||||
{
|
||||
b = V[k];
|
||||
V[k] = V[l];
|
||||
V[l] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
int _cvCalcEigenObjects_8u32fR_q( int nObjects,
|
||||
uchar** objects,
|
||||
int objStep,
|
||||
float** eigObjs,
|
||||
int eigStep,
|
||||
CvSize size,
|
||||
float* eigVals,
|
||||
float* avg,
|
||||
int avgStep,
|
||||
int* nEigObjs,
|
||||
double* eps )
|
||||
{
|
||||
int i, j, k, l;
|
||||
uchar *bu;
|
||||
float *c=0, *ev=0, *bf, *bf1, *bf2, m;
|
||||
int r;
|
||||
|
||||
|
||||
if ( nObjects < 2 ) return CV_BADFACTOR_ERR;
|
||||
if ( size.width > objStep || 4*size.width > eigStep ||
|
||||
4*size.width > avgStep || size.height < 1) return CV_BADSIZE_ERR;
|
||||
if ( objects == NULL || eigObjs == NULL || eigVals == NULL ||
|
||||
avg == NULL || nEigObjs == NULL || eps == NULL ) return CV_NULLPTR_ERR;
|
||||
for( i=0; i<nObjects; i++ ) if( objects[i] == NULL ) return CV_NULLPTR_ERR;
|
||||
for( i=0; i<*nEigObjs; i++ ) if( eigObjs[i] == NULL ) return CV_NULLPTR_ERR;
|
||||
|
||||
eigStep /= 4;
|
||||
avgStep /= 4;
|
||||
|
||||
/* Calculation of averaged object */
|
||||
bf = avg;
|
||||
for(i = 0; i < size.height; i++, bf += avgStep)
|
||||
for(j = 0; j < size.width; j++)
|
||||
bf[j] = 0.f;
|
||||
for(k = 0; k < nObjects; k++)
|
||||
{
|
||||
bu = objects[k];
|
||||
bf = avg;
|
||||
for(i = 0; i < size.height; i++, bu +=objStep, bf += avgStep)
|
||||
for(j = 0; j < size.width; j++)
|
||||
bf[j] += bu[j];
|
||||
}
|
||||
m = 1.0f/(float)nObjects;
|
||||
bf = avg;
|
||||
for(i = 0; i < size.height; i++, bf += avgStep)
|
||||
for(j = 0; j < size.width; j++)
|
||||
bf[j] *= m;
|
||||
|
||||
/* Calculation of covariance matrix */
|
||||
c = (float*)cvAlloc ( sizeof(float)*nObjects*nObjects );
|
||||
if(c==NULL) return CV_OUTOFMEM_ERR;
|
||||
|
||||
r = _cvCalcCovarMatrix_8u32fR_q ( nObjects, objects, objStep,
|
||||
avg, 4*avgStep, size, c );
|
||||
if(r) { cvFree( &c ); return r; }
|
||||
|
||||
/* Calculation of eigenvalues & eigenvectors */
|
||||
ev = (float*)cvAlloc ( sizeof(float)*nObjects*nObjects );
|
||||
if(ev==NULL) { cvFree( &c ); return CV_OUTOFMEM_ERR; }
|
||||
|
||||
_cvJacobiEigens_32f( c, ev, eigVals, nObjects, 0.0f );
|
||||
cvFree( &c );
|
||||
|
||||
for(i=0; i<*nEigObjs; i++) if( fabs(eigVals[i]/eigVals[0]) < *eps ) break;
|
||||
*nEigObjs = i;
|
||||
*eps = fabs(eigVals[*nEigObjs-1]/eigVals[0]);
|
||||
|
||||
/* Calculation of eigenobjects */
|
||||
bf2 = ev;
|
||||
for(i=0; i<*nEigObjs; i++, bf2+=nObjects)
|
||||
{
|
||||
float e = (float)(1.0/sqrt(eigVals[i]));
|
||||
float* u = eigObjs[i];
|
||||
|
||||
bf = u;
|
||||
for(l=0; l<size.height; l++, bf+=eigStep)
|
||||
for(j=0; j<size.width; j++) bf[j] = 0.0f;
|
||||
|
||||
for(k=0; k<nObjects; k++)
|
||||
{
|
||||
float v = e*bf2[k];
|
||||
bf = u;
|
||||
bu = objects[k];
|
||||
bf1 = avg;
|
||||
for(l=0; l<size.height; l++, bf+=eigStep, bf1+=avgStep, bu+=objStep)
|
||||
for(j=0; j<size.width; j++) bf[j] += v * ((float)bu[j] - bf1[j]);
|
||||
}
|
||||
}
|
||||
|
||||
cvFree( &ev );
|
||||
return CV_NO_ERR;
|
||||
} /* --- End of _cvCalcEigenObjects_8u32fR --- */
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
float _cvCalcDecompCoeff_8u32fR_q( uchar* obj,
|
||||
int objStep,
|
||||
float* eigObj,
|
||||
int eigStep,
|
||||
float* avg,
|
||||
int avgStep,
|
||||
CvSize size )
|
||||
{
|
||||
int i, k;
|
||||
float w = 0.0f;
|
||||
|
||||
if ( size.width > objStep || 4*size.width > eigStep
|
||||
|| 4*size.width > avgStep || size.height < 1) return -1.0e30f;
|
||||
if ( obj == NULL || eigObj == NULL || avg == NULL ) return -1.0e30f;
|
||||
|
||||
eigStep /= 4;
|
||||
avgStep /= 4;
|
||||
|
||||
for(i = 0; i < size.height; i++, obj += objStep, eigObj += eigStep, avg += avgStep)
|
||||
for(k = 0; k < size.width; k++)
|
||||
w += eigObj[k]*( (float)obj[k] - avg[k] );
|
||||
|
||||
return w;
|
||||
}
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
int _cvEigenDecomposite_8u32fR_q( uchar* obj,
|
||||
int objStep,
|
||||
int nEigObjs,
|
||||
float** eigObjs,
|
||||
int eigStep,
|
||||
float* avg,
|
||||
int avgStep,
|
||||
CvSize size,
|
||||
float* coeffs )
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( nEigObjs < 2 ) return CV_BADFACTOR_ERR;
|
||||
if ( size.width > objStep || 4*size.width > eigStep ||
|
||||
4*size.width > avgStep || size.height < 1) return CV_BADSIZE_ERR;
|
||||
if ( obj == NULL || eigObjs == NULL || coeffs == NULL || avg == NULL)
|
||||
return CV_NULLPTR_ERR;
|
||||
|
||||
for(i=0; i<nEigObjs; i++)
|
||||
{
|
||||
float w = _cvCalcDecompCoeff_8u32fR_q( obj, objStep, eigObjs[i], eigStep,
|
||||
avg, avgStep, size );
|
||||
if( w < -1.0e29f ) return CV_NOTDEFINED_ERR;
|
||||
coeffs[i] = w;
|
||||
}
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
int _cvEigenProjection_8u32fR_q( int nEigObjs,
|
||||
float** eigens,
|
||||
int eigStep,
|
||||
float* coeffs,
|
||||
float* avg,
|
||||
int avgStep,
|
||||
uchar* rest,
|
||||
int restStep,
|
||||
CvSize size )
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
if ( size.width > avgStep || 4*size.width > eigStep || size.height < 1)
|
||||
return CV_BADSIZE_ERR;
|
||||
if ( rest == NULL || eigens == NULL || avg == NULL || coeffs == NULL )
|
||||
return CV_NULLPTR_ERR;
|
||||
eigStep /= 4;
|
||||
avgStep /= 4;
|
||||
|
||||
for(i = 0; i < size.height; i++, rest+=restStep, avg+=avgStep)
|
||||
{
|
||||
int ij = i*eigStep;
|
||||
for(j = 0; j < size.width; j++, ij++)
|
||||
{
|
||||
float w = avg[j];
|
||||
for(k=0; k<nEigObjs-3; k+=4)
|
||||
{
|
||||
float* b = eigens[k];
|
||||
w += coeffs[k ] * b[ij];
|
||||
b = eigens [k+1];
|
||||
w += coeffs[k+1] * b[ij];
|
||||
b = eigens [k+2];
|
||||
w += coeffs[k+2] * b[ij];
|
||||
b = eigens [k+3];
|
||||
w += coeffs[k+3] * b[ij];
|
||||
}
|
||||
for(; k<nEigObjs; k++)
|
||||
{
|
||||
float* b = eigens[k];
|
||||
w += coeffs[k] * b[ij];
|
||||
}
|
||||
w = w<-0.499999f ? -0.499999f : w>255.499f ? 255.499f : w;
|
||||
rest[j] = (uchar)cvRound( w );
|
||||
}
|
||||
}
|
||||
return CV_NO_ERR;
|
||||
}
|
||||
/*______________________________________________________________________________________*/
|
||||
|
||||
/* << End of file >> */
|
||||
@@ -1,122 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
/*////////////////////// emd_test /////////////////////////*/
|
||||
|
||||
typedef struct matr_info
|
||||
{
|
||||
float* x_origin;
|
||||
float* y_origin;
|
||||
float* matr;
|
||||
int rows;
|
||||
int cols;
|
||||
}
|
||||
matr_info;
|
||||
|
||||
static float matr_dist( const float* x, const float* y, void* param )
|
||||
{
|
||||
matr_info* mi = (matr_info*)param;
|
||||
int i = (int)(x - mi->x_origin) - 1;
|
||||
int j = (int)(y - mi->y_origin) - 1;
|
||||
assert( 0 <= i && i < mi->rows &&
|
||||
0 <= j && j < mi->cols );
|
||||
return mi->matr[i*mi->cols + j];
|
||||
}
|
||||
|
||||
class CV_EMDTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_EMDTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_EMDTest::CV_EMDTest():
|
||||
CvTest( "emd", "cvCalcEMD" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_EMDTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
const double success_error_level = 1e-6;
|
||||
#define M 10000
|
||||
double emd0 = 2460./210;
|
||||
static float cost[] =
|
||||
{
|
||||
16, 16, 13, 22, 17,
|
||||
14, 14, 13, 19, 15,
|
||||
19, 19, 20, 23, M,
|
||||
M , 0, M, 0, 0
|
||||
};
|
||||
static float w1[] = { 50, 60, 50, 50 },
|
||||
w2[] = { 30, 20, 70, 30, 60 };
|
||||
matr_info mi;
|
||||
float emd;
|
||||
|
||||
mi.x_origin = w1;
|
||||
mi.y_origin = w2;
|
||||
|
||||
mi.rows = sizeof(w1)/sizeof(w1[0]);
|
||||
mi.cols = sizeof(w2)/sizeof(w2[0]);
|
||||
mi.matr = cost;
|
||||
|
||||
emd = cvCalcEMD( w1, mi.rows, w2, mi.cols, 0, (CvDisType)-1,
|
||||
matr_dist, 0, &mi );
|
||||
|
||||
if( fabs( emd - emd0 ) > success_error_level*emd0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The computed distance is %.2f, while it should be %.2f\n", emd, emd0 );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_EMDTest emd_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,176 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_RigidTransform_Test : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_RigidTransform_Test();
|
||||
~CV_RigidTransform_Test();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool testNPoints(int);
|
||||
bool testImage();
|
||||
};
|
||||
|
||||
CV_RigidTransform_Test::CV_RigidTransform_Test(): CvTest( "optflow-estimate-rigid", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_RigidTransform_Test::~CV_RigidTransform_Test() {}
|
||||
|
||||
struct WrapAff2D
|
||||
{
|
||||
const double *F;
|
||||
WrapAff2D(const Mat& aff) : F(aff.ptr<double>()) {}
|
||||
Point2f operator()(const Point2f& p)
|
||||
{
|
||||
return Point2d( p.x * F[0] + p.y * F[1] + F[2],
|
||||
p.x * F[3] + p.y * F[4] + F[5]);
|
||||
}
|
||||
};
|
||||
|
||||
bool CV_RigidTransform_Test::testNPoints(int from)
|
||||
{
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
|
||||
int progress = 0;
|
||||
int k, ntests = 10000;
|
||||
|
||||
for( k = from; k < ntests; k++ )
|
||||
{
|
||||
ts->update_context( this, k, true );
|
||||
progress = update_progress(progress, k, ntests, 0);
|
||||
|
||||
Mat aff(2, 3, CV_64F);
|
||||
rng.fill(aff, CV_RAND_UNI, Scalar(-2), Scalar(2));
|
||||
|
||||
int n = (unsigned)rng % 100 + 10;
|
||||
|
||||
Mat fpts(1, n, CV_32FC2);
|
||||
Mat tpts(1, n, CV_32FC2);
|
||||
|
||||
rng.fill(fpts, CV_RAND_UNI, Scalar(0,0), Scalar(10,10));
|
||||
transform(fpts.ptr<Point2f>(), fpts.ptr<Point2f>() + n, tpts.ptr<Point2f>(), WrapAff2D(aff));
|
||||
|
||||
Mat noise(1, n, CV_32FC2);
|
||||
rng.fill(noise, CV_RAND_NORMAL, Scalar::all(0), Scalar::all(0.001*(n<=7 ? 0 : n <= 30 ? 1 : 10)));
|
||||
tpts += noise;
|
||||
|
||||
Mat aff_est = estimateRigidTransform(fpts, tpts, true);
|
||||
|
||||
double thres = 0.1*norm(aff);
|
||||
double d = norm(aff_est, aff, NORM_L2);
|
||||
if (d > thres)
|
||||
{
|
||||
double dB=0, nB=0;
|
||||
if (n <= 4)
|
||||
{
|
||||
Mat A = fpts.reshape(1, 3);
|
||||
Mat B = A - repeat(A.row(0), 3, 1), Bt = B.t();
|
||||
B = Bt*B;
|
||||
dB = cv::determinant(B);
|
||||
nB = norm(B);
|
||||
if( fabs(dB) < 0.01*nB )
|
||||
continue;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( CvTS::LOG, "Threshold = %f, norm of difference = %f", thres, d );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_RigidTransform_Test::testImage()
|
||||
{
|
||||
Mat img;
|
||||
pyrDown(imread( string(ts->get_data_path()) + "shared/graffiti.png", 1), img);
|
||||
|
||||
Mat aff = cv::getRotationMatrix2D(Point(img.cols/2, img.rows/2), 1, 0.99);
|
||||
aff.ptr<double>()[2]+=3;
|
||||
aff.ptr<double>()[5]+=3;
|
||||
|
||||
Mat rotated;
|
||||
warpAffine(img, rotated, aff, img.size());
|
||||
|
||||
Mat aff_est = estimateRigidTransform(img, rotated, true);
|
||||
|
||||
const double thres = 0.03;
|
||||
if (norm(aff_est, aff, NORM_INF) > thres)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( CvTS::LOG, "Threshold = %f, norm of difference = %f", thres,
|
||||
norm(aff_est, aff, NORM_INF) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_RigidTransform_Test::run( int start_from )
|
||||
{
|
||||
DefaultRngAuto dra; (void)dra;
|
||||
|
||||
if (!testNPoints(start_from))
|
||||
return;
|
||||
|
||||
if (!testImage())
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_RigidTransform_Test CV_RigidTransform_test;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,196 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_Affine3D_EstTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_Affine3D_EstTest();
|
||||
~CV_Affine3D_EstTest();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool test4Points();
|
||||
bool testNPoints();
|
||||
};
|
||||
|
||||
CV_Affine3D_EstTest::CV_Affine3D_EstTest(): CvTest( "algorithm-estimateAffine3D", "cv::estimateAffine3D" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_Affine3D_EstTest::~CV_Affine3D_EstTest() {}
|
||||
|
||||
|
||||
float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); }
|
||||
|
||||
|
||||
struct WrapAff
|
||||
{
|
||||
const double *F;
|
||||
WrapAff(const Mat& aff) : F(aff.ptr<double>()) {}
|
||||
Point3f operator()(const Point3f& p)
|
||||
{
|
||||
return Point3d( p.x * F[0] + p.y * F[1] + p.z * F[2] + F[3],
|
||||
p.x * F[4] + p.y * F[5] + p.z * F[6] + F[7],
|
||||
p.x * F[8] + p.y * F[9] + p.z * F[10] + F[11] );
|
||||
}
|
||||
};
|
||||
|
||||
bool CV_Affine3D_EstTest::test4Points()
|
||||
{
|
||||
Mat aff(3, 4, CV_64F);
|
||||
cv::randu(aff, Scalar(1), Scalar(3));
|
||||
|
||||
// setting points that are no in the same line
|
||||
|
||||
Mat fpts(1, 4, CV_32FC3);
|
||||
Mat tpts(1, 4, CV_32FC3);
|
||||
|
||||
fpts.ptr<Point3f>()[0] = Point3f( rngIn(1,2), rngIn(1,2), rngIn(5, 6) );
|
||||
fpts.ptr<Point3f>()[1] = Point3f( rngIn(3,4), rngIn(3,4), rngIn(5, 6) );
|
||||
fpts.ptr<Point3f>()[2] = Point3f( rngIn(1,2), rngIn(3,4), rngIn(5, 6) );
|
||||
fpts.ptr<Point3f>()[3] = Point3f( rngIn(3,4), rngIn(1,2), rngIn(5, 6) );
|
||||
|
||||
transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + 4, tpts.ptr<Point3f>(), WrapAff(aff));
|
||||
|
||||
Mat aff_est;
|
||||
vector<uchar> outliers;
|
||||
estimateAffine3D(fpts, tpts, aff_est, outliers);
|
||||
|
||||
const double thres = 1e-3;
|
||||
if (norm(aff_est, aff, NORM_INF) > thres)
|
||||
{
|
||||
//cout << norm(aff_est, aff, NORM_INF) << endl;
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct Noise
|
||||
{
|
||||
float l;
|
||||
Noise(float level) : l(level) {}
|
||||
Point3f operator()(const Point3f& p)
|
||||
{
|
||||
RNG& rng = theRNG();
|
||||
return Point3f( p.x + l * (float)rng, p.y + l * (float)rng, p.z + l * (float)rng);
|
||||
}
|
||||
};
|
||||
|
||||
bool CV_Affine3D_EstTest::testNPoints()
|
||||
{
|
||||
Mat aff(3, 4, CV_64F);
|
||||
cv::randu(aff, Scalar(-2), Scalar(2));
|
||||
|
||||
// setting points that are no in the same line
|
||||
|
||||
const int n = 100;
|
||||
const int m = 3*n/5;
|
||||
const Point3f shift_outl = Point3f(15, 15, 15);
|
||||
const float noise_level = 20.f;
|
||||
|
||||
Mat fpts(1, n, CV_32FC3);
|
||||
Mat tpts(1, n, CV_32FC3);
|
||||
|
||||
randu(fpts, Scalar::all(0), Scalar::all(100));
|
||||
transform(fpts.ptr<Point3f>(), fpts.ptr<Point3f>() + n, tpts.ptr<Point3f>(), WrapAff(aff));
|
||||
|
||||
/* adding noise*/
|
||||
transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, bind2nd(plus<Point3f>(), shift_outl));
|
||||
transform(tpts.ptr<Point3f>() + m, tpts.ptr<Point3f>() + n, tpts.ptr<Point3f>() + m, Noise(noise_level));
|
||||
|
||||
Mat aff_est;
|
||||
vector<uchar> outl;
|
||||
int res = estimateAffine3D(fpts, tpts, aff_est, outl);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
const double thres = 1e-4;
|
||||
if (norm(aff_est, aff, NORM_INF) > thres)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool outl_good = count(outl.begin(), outl.end(), 1) == m &&
|
||||
m == accumulate(outl.begin(), outl.begin() + m, 0);
|
||||
|
||||
if (!outl_good)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CV_Affine3D_EstTest::run( int /* start_from */)
|
||||
{
|
||||
DefaultRngAuto dra; (void)dra;
|
||||
|
||||
if (!test4Points())
|
||||
return;
|
||||
|
||||
if (!testNPoints())
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_Affine3D_EstTest CV_Affine3D_Est_test;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,596 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* floodfill_param_names[] = { "size", "channels", "depth", "dist_type", "labels", 0 };
|
||||
static const CvSize floodfill_sizes[] = {{320, 240}, {720,480}, {-1,-1}};
|
||||
static const CvSize floodfill_whole_sizes[] = {{320, 240}, {720,480}, {-1,-1}};
|
||||
//static const char* floodfill_types[] = { "fixed_level", "fixed_range", "floating_range", 0 };
|
||||
static const int floodfill_depths[] = { CV_8U, CV_32F, -1 };
|
||||
static const int floodfill_channels[] = { 1, 3, -1 };
|
||||
|
||||
class CV_FloodFillTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_FloodFillTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
void fill_array( int test_case_idx, int i, int j, CvMat* arr );
|
||||
|
||||
/*int write_default_params(CvFileStorage* fs);
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );*/
|
||||
CvPoint seed_pt;
|
||||
CvScalar new_val;
|
||||
CvScalar l_diff, u_diff;
|
||||
int connectivity;
|
||||
bool use_mask, mask_only;
|
||||
int range_type;
|
||||
int new_mask_val;
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
CV_FloodFillTest::CV_FloodFillTest()
|
||||
: CvArrTest( "floodfill", "cvFloodFill", "" )
|
||||
{
|
||||
test_array[INPUT_OUTPUT].push(NULL);
|
||||
test_array[INPUT_OUTPUT].push(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
|
||||
default_timing_param_names = floodfill_param_names;
|
||||
depth_list = floodfill_depths;
|
||||
size_list = floodfill_sizes;
|
||||
whole_size_list = floodfill_whole_sizes;
|
||||
cn_list = floodfill_channels;
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int depth, cn;
|
||||
int i;
|
||||
double buf[8];
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
depth = cvTsRandInt(rng) % 2;
|
||||
depth = depth == 0 ? CV_8U : CV_32F;
|
||||
cn = cvTsRandInt(rng) & 1 ? 3 : 1;
|
||||
|
||||
use_mask = (cvTsRandInt(rng) & 1) != 0;
|
||||
connectivity = (cvTsRandInt(rng) & 1) ? 4 : 8;
|
||||
mask_only = use_mask && (cvTsRandInt(rng) & 1) != 0;
|
||||
new_mask_val = cvTsRandInt(rng) & 255;
|
||||
range_type = cvTsRandInt(rng) % 3;
|
||||
|
||||
types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = CV_MAKETYPE(depth, cn);
|
||||
types[INPUT_OUTPUT][1] = types[REF_INPUT_OUTPUT][1] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(9,1);
|
||||
|
||||
if( !use_mask )
|
||||
sizes[INPUT_OUTPUT][1] = sizes[REF_INPUT_OUTPUT][1] = cvSize(0,0);
|
||||
else
|
||||
{
|
||||
CvSize sz = sizes[INPUT_OUTPUT][0];
|
||||
sizes[INPUT_OUTPUT][1] = sizes[REF_INPUT_OUTPUT][1] = cvSize(sz.width+2,sz.height+2);
|
||||
}
|
||||
|
||||
seed_pt.x = cvTsRandInt(rng) % sizes[INPUT_OUTPUT][0].width;
|
||||
seed_pt.y = cvTsRandInt(rng) % sizes[INPUT_OUTPUT][0].height;
|
||||
|
||||
if( range_type == 0 )
|
||||
l_diff = u_diff = cvScalarAll(0.);
|
||||
else
|
||||
{
|
||||
CvMat m = cvMat( 1, 8, CV_16S, buf );
|
||||
cvRandArr( rng, &m, CV_RAND_NORMAL, cvScalarAll(0), cvScalarAll(32) );
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
l_diff.val[i] = fabs(m.data.s[i]/16.);
|
||||
u_diff.val[i] = fabs(m.data.s[i+4]/16.);
|
||||
}
|
||||
}
|
||||
|
||||
new_val = cvScalarAll(0.);
|
||||
for( i = 0; i < cn; i++ )
|
||||
new_val.val[i] = cvTsRandReal(rng)*255;
|
||||
|
||||
test_cpp = (cvTsRandInt(rng) & 256) == 0;
|
||||
}
|
||||
|
||||
|
||||
double CV_FloodFillTest::get_success_error_level( int /*test_case_idx*/, int i, int j )
|
||||
{
|
||||
return i == OUTPUT ? FLT_EPSILON : j == 0 ? FLT_EPSILON : 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::fill_array( int test_case_idx, int i, int j, CvMat* arr )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
|
||||
if( i != INPUT && i != INPUT_OUTPUT )
|
||||
{
|
||||
CvArrTest::fill_array( test_case_idx, i, j, arr );
|
||||
return;
|
||||
}
|
||||
|
||||
if( j == 0 )
|
||||
{
|
||||
CvMat* tmp = arr;
|
||||
CvScalar m = cvScalarAll(128);
|
||||
CvScalar s = cvScalarAll(10);
|
||||
|
||||
if( CV_MAT_DEPTH(arr->type) == CV_32FC1 )
|
||||
tmp = cvCreateMat( arr->rows, arr->cols, arr->type & CV_MAT_CN_MASK );
|
||||
|
||||
if( range_type == 0 )
|
||||
s = cvScalarAll(2);
|
||||
|
||||
cvRandArr( rng, tmp, CV_RAND_NORMAL, m, s );
|
||||
if( arr != tmp )
|
||||
{
|
||||
cvTsConvert( tmp, arr );
|
||||
cvReleaseMat( &tmp );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CvScalar l = cvScalarAll(-2);
|
||||
CvScalar u = cvScalarAll(2);
|
||||
cvRandArr( rng, arr, CV_RAND_UNI, l, u );
|
||||
cvRectangle( arr, cvPoint(0,0), cvPoint(arr->cols-1,arr->rows-1), cvScalarAll(1), 1, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::run_func()
|
||||
{
|
||||
int flags = connectivity + (mask_only ? CV_FLOODFILL_MASK_ONLY : 0) +
|
||||
(range_type == 1 ? CV_FLOODFILL_FIXED_RANGE : 0) + (new_mask_val << 8);
|
||||
double* odata = test_mat[OUTPUT][0].data.db;
|
||||
|
||||
if(!test_cpp)
|
||||
{
|
||||
CvConnectedComp comp;
|
||||
cvFloodFill( test_array[INPUT_OUTPUT][0], seed_pt, new_val, l_diff, u_diff, &comp,
|
||||
flags, test_array[INPUT_OUTPUT][1] );
|
||||
odata[0] = comp.area;
|
||||
odata[1] = comp.rect.x;
|
||||
odata[2] = comp.rect.y;
|
||||
odata[3] = comp.rect.width;
|
||||
odata[4] = comp.rect.height;
|
||||
odata[5] = comp.value.val[0];
|
||||
odata[6] = comp.value.val[1];
|
||||
odata[7] = comp.value.val[2];
|
||||
odata[8] = comp.value.val[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat img = cv::cvarrToMat(test_array[INPUT_OUTPUT][0]),
|
||||
mask = test_array[INPUT_OUTPUT][1] ? cv::cvarrToMat(test_array[INPUT_OUTPUT][1]) : cv::Mat();
|
||||
cv::Rect rect;
|
||||
int area;
|
||||
if( !mask.data )
|
||||
area = cv::floodFill( img, seed_pt, new_val, &rect, l_diff, u_diff, flags );
|
||||
else
|
||||
area = cv::floodFill( img, mask, seed_pt, new_val, &rect, l_diff, u_diff, flags );
|
||||
odata[0] = area;
|
||||
odata[1] = rect.x;
|
||||
odata[2] = rect.y;
|
||||
odata[3] = rect.width;
|
||||
odata[4] = rect.height;
|
||||
odata[5] = odata[6] = odata[7] = odata[8] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct ff_offset_pair_t
|
||||
{
|
||||
int mofs, iofs;
|
||||
}
|
||||
ff_offset_pair_t;
|
||||
|
||||
static void
|
||||
cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
|
||||
CvScalar l_diff, CvScalar u_diff, CvMat* _mask,
|
||||
double* comp, int connectivity, int range_type,
|
||||
int new_mask_val, bool mask_only )
|
||||
{
|
||||
CvMemStorage* st = cvCreateMemStorage();
|
||||
ff_offset_pair_t p0, p;
|
||||
CvSeq* seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(p0), st );
|
||||
CvMat* tmp = _img;
|
||||
CvMat* mask;
|
||||
CvRect r = cvRect( 0, 0, -1, -1 );
|
||||
int area = 0;
|
||||
int i, j;
|
||||
ushort* m;
|
||||
float* img;
|
||||
int mstep, step;
|
||||
int cn = CV_MAT_CN(_img->type);
|
||||
int mdelta[8], idelta[8], ncount;
|
||||
int cols = _img->cols, rows = _img->rows;
|
||||
int u0 = 0, u1 = 0, u2 = 0;
|
||||
double s0 = 0, s1 = 0, s2 = 0;
|
||||
|
||||
if( CV_MAT_DEPTH(_img->type) == CV_8U )
|
||||
{
|
||||
tmp = cvCreateMat( rows, cols, CV_MAKETYPE(CV_32F,CV_MAT_CN(_img->type)) );
|
||||
cvTsConvert(_img, tmp);
|
||||
}
|
||||
|
||||
mask = cvCreateMat( rows + 2, cols + 2, CV_16UC1 );
|
||||
|
||||
if( _mask )
|
||||
cvTsConvert( _mask, mask );
|
||||
else
|
||||
{
|
||||
cvTsZero( mask );
|
||||
cvRectangle( mask, cvPoint(0,0), cvPoint(mask->cols-1,mask->rows-1), cvScalarAll(1.), 1, 8, 0 );
|
||||
}
|
||||
|
||||
new_mask_val = (new_mask_val != 0 ? new_mask_val : 1) << 8;
|
||||
|
||||
m = (ushort*)(mask->data.ptr + mask->step) + 1;
|
||||
mstep = mask->step / sizeof(m[0]);
|
||||
img = tmp->data.fl;
|
||||
step = tmp->step / sizeof(img[0]);
|
||||
|
||||
p0.mofs = seed_pt.y*mstep + seed_pt.x;
|
||||
p0.iofs = seed_pt.y*step + seed_pt.x*cn;
|
||||
|
||||
if( m[p0.mofs] )
|
||||
goto _exit_;
|
||||
|
||||
cvSeqPush( seq, &p0 );
|
||||
m[p0.mofs] = (ushort)new_mask_val;
|
||||
|
||||
if( connectivity == 4 )
|
||||
{
|
||||
ncount = 4;
|
||||
mdelta[0] = -mstep; idelta[0] = -step;
|
||||
mdelta[1] = -1; idelta[1] = -cn;
|
||||
mdelta[2] = 1; idelta[2] = cn;
|
||||
mdelta[3] = mstep; idelta[3] = step;
|
||||
}
|
||||
else
|
||||
{
|
||||
ncount = 8;
|
||||
mdelta[0] = -mstep-1; mdelta[1] = -mstep; mdelta[2] = -mstep+1;
|
||||
idelta[0] = -step-cn; idelta[1] = -step; idelta[2] = -step+cn;
|
||||
|
||||
mdelta[3] = -1; mdelta[4] = 1;
|
||||
idelta[3] = -cn; idelta[4] = cn;
|
||||
|
||||
mdelta[5] = mstep-1; mdelta[6] = mstep; mdelta[7] = mstep+1;
|
||||
idelta[5] = step-cn; idelta[6] = step; idelta[7] = step+cn;
|
||||
}
|
||||
|
||||
if( cn == 1 )
|
||||
{
|
||||
float a0 = (float)-l_diff.val[0];
|
||||
float b0 = (float)u_diff.val[0];
|
||||
|
||||
s0 = img[p0.iofs];
|
||||
|
||||
if( range_type < 2 )
|
||||
{
|
||||
a0 += (float)s0; b0 += (float)s0;
|
||||
}
|
||||
|
||||
while( seq->total )
|
||||
{
|
||||
cvSeqPop( seq, &p0 );
|
||||
float a = a0, b = b0;
|
||||
float* ptr = img + p0.iofs;
|
||||
ushort* mptr = m + p0.mofs;
|
||||
|
||||
if( range_type == 2 )
|
||||
a += ptr[0], b += ptr[0];
|
||||
|
||||
for( i = 0; i < ncount; i++ )
|
||||
{
|
||||
int md = mdelta[i], id = idelta[i];
|
||||
float v;
|
||||
if( !mptr[md] && a <= (v = ptr[id]) && v <= b )
|
||||
{
|
||||
mptr[md] = (ushort)new_mask_val;
|
||||
p.mofs = p0.mofs + md;
|
||||
p.iofs = p0.iofs + id;
|
||||
cvSeqPush( seq, &p );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float a0 = (float)-l_diff.val[0];
|
||||
float a1 = (float)-l_diff.val[1];
|
||||
float a2 = (float)-l_diff.val[2];
|
||||
float b0 = (float)u_diff.val[0];
|
||||
float b1 = (float)u_diff.val[1];
|
||||
float b2 = (float)u_diff.val[2];
|
||||
|
||||
s0 = img[p0.iofs];
|
||||
s1 = img[p0.iofs + 1];
|
||||
s2 = img[p0.iofs + 2];
|
||||
|
||||
if( range_type < 2 )
|
||||
{
|
||||
a0 += (float)s0; b0 += (float)s0;
|
||||
a1 += (float)s1; b1 += (float)s1;
|
||||
a2 += (float)s2; b2 += (float)s2;
|
||||
}
|
||||
|
||||
while( seq->total )
|
||||
{
|
||||
cvSeqPop( seq, &p0 );
|
||||
float _a0 = a0, _a1 = a1, _a2 = a2;
|
||||
float _b0 = b0, _b1 = b1, _b2 = b2;
|
||||
float* ptr = img + p0.iofs;
|
||||
ushort* mptr = m + p0.mofs;
|
||||
|
||||
if( range_type == 2 )
|
||||
{
|
||||
_a0 += ptr[0]; _b0 += ptr[0];
|
||||
_a1 += ptr[1]; _b1 += ptr[1];
|
||||
_a2 += ptr[2]; _b2 += ptr[2];
|
||||
}
|
||||
|
||||
for( i = 0; i < ncount; i++ )
|
||||
{
|
||||
int md = mdelta[i], id = idelta[i];
|
||||
float v;
|
||||
if( !mptr[md] &&
|
||||
_a0 <= (v = ptr[id]) && v <= _b0 &&
|
||||
_a1 <= (v = ptr[id+1]) && v <= _b1 &&
|
||||
_a2 <= (v = ptr[id+2]) && v <= _b2 )
|
||||
{
|
||||
mptr[md] = (ushort)new_mask_val;
|
||||
p.mofs = p0.mofs + md;
|
||||
p.iofs = p0.iofs + id;
|
||||
cvSeqPush( seq, &p );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.x = r.width = seed_pt.x;
|
||||
r.y = r.height = seed_pt.y;
|
||||
|
||||
if( !mask_only )
|
||||
{
|
||||
s0 = new_val.val[0];
|
||||
s1 = new_val.val[1];
|
||||
s2 = new_val.val[2];
|
||||
|
||||
if( tmp != _img )
|
||||
{
|
||||
u0 = cvRound(s0);
|
||||
u0 = CV_CAST_8U(u0);
|
||||
u1 = cvRound(s1);
|
||||
u1 = CV_CAST_8U(u1);
|
||||
u2 = cvRound(s2);
|
||||
u2 = CV_CAST_8U(u2);
|
||||
|
||||
s0 = u0;
|
||||
s1 = u1;
|
||||
s2 = u2;
|
||||
}
|
||||
}
|
||||
else
|
||||
s0 = s1 = s2 = 0;
|
||||
|
||||
new_mask_val >>= 8;
|
||||
|
||||
for( i = 0; i < rows; i++ )
|
||||
{
|
||||
float* ptr = img + i*step;
|
||||
ushort* mptr = m + i*mstep;
|
||||
uchar* dmptr = _mask ? _mask->data.ptr + (i+1)*_mask->step + 1 : 0;
|
||||
uchar* dptr = tmp != _img ? _img->data.ptr + i*_img->step : 0;
|
||||
double area0 = area;
|
||||
|
||||
for( j = 0; j < cols; j++ )
|
||||
{
|
||||
if( mptr[j] > 255 )
|
||||
{
|
||||
if( dmptr )
|
||||
dmptr[j] = (uchar)new_mask_val;
|
||||
if( !mask_only )
|
||||
{
|
||||
if( cn == 1 )
|
||||
{
|
||||
if( dptr )
|
||||
dptr[j] = (uchar)u0;
|
||||
else
|
||||
ptr[j] = (float)s0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dptr )
|
||||
{
|
||||
dptr[j*3] = (uchar)u0;
|
||||
dptr[j*3+1] = (uchar)u1;
|
||||
dptr[j*3+2] = (uchar)u2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr[j*3] = (float)s0;
|
||||
ptr[j*3+1] = (float)s1;
|
||||
ptr[j*3+2] = (float)s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cn == 1 )
|
||||
s0 += ptr[j];
|
||||
else
|
||||
{
|
||||
s0 += ptr[j*3];
|
||||
s1 += ptr[j*3+1];
|
||||
s2 += ptr[j*3+2];
|
||||
}
|
||||
}
|
||||
|
||||
area++;
|
||||
if( r.x > j )
|
||||
r.x = j;
|
||||
if( r.width < j )
|
||||
r.width = j;
|
||||
}
|
||||
}
|
||||
|
||||
if( area != area0 )
|
||||
{
|
||||
if( r.y > i )
|
||||
r.y = i;
|
||||
if( r.height < i )
|
||||
r.height = i;
|
||||
}
|
||||
}
|
||||
|
||||
_exit_:
|
||||
cvReleaseMat( &mask );
|
||||
if( tmp != _img )
|
||||
cvReleaseMat( &tmp );
|
||||
|
||||
comp[0] = area;
|
||||
comp[1] = r.x;
|
||||
comp[2] = r.y;
|
||||
comp[3] = r.width - r.x + 1;
|
||||
comp[4] = r.height - r.y + 1;
|
||||
if( mask_only )
|
||||
{
|
||||
double t = area ? 1./area : 0;
|
||||
s0 *= t;
|
||||
s1 *= t;
|
||||
s2 *= t;
|
||||
}
|
||||
comp[5] = s0;
|
||||
comp[6] = s1;
|
||||
comp[7] = s2;
|
||||
comp[8] = 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
double* comp = test_mat[REF_OUTPUT][0].data.db;
|
||||
cvTsFloodFill( &test_mat[REF_INPUT_OUTPUT][0], seed_pt, new_val, l_diff, u_diff,
|
||||
test_array[REF_INPUT_OUTPUT][1] ? &test_mat[REF_INPUT_OUTPUT][1] : 0,
|
||||
comp, connectivity, range_type, new_mask_val, mask_only );
|
||||
if(test_cpp)
|
||||
comp[5] = comp[6] = comp[7] = comp[8] = 0;
|
||||
}
|
||||
|
||||
|
||||
/*int CV_FloodFillTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::TIMING_MODE )
|
||||
{
|
||||
start_write_param( fs );
|
||||
write_string_list( fs, "dist_type", floodfill_types );
|
||||
write_int_list( fs, "labels", floodfill_labels, -1, -1 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
const char* distype_str = cvReadString( find_timing_param( "dist_type" ), "l2_5x5" );
|
||||
mask_size = strstr( distype_str, "3x3" ) ? 3 : 5;
|
||||
dist_type = distype_str[0] == 'c' ? CV_DIST_C : distype_str[1] == '1' ? CV_DIST_L1 : CV_DIST_L2;
|
||||
fill_labels = cvReadInt( find_timing_param( "labels" ), 0 );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = CV_32FC1;
|
||||
types[OUTPUT][1] = CV_32SC1;
|
||||
|
||||
if( !fill_labels )
|
||||
sizes[OUTPUT][0] = whole_sizes[OUTPUT][0] = cvSize(0,0);
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "%s,", cvReadString( find_timing_param( "dist_type" ), "l2_5x5" ) );
|
||||
ptr += strlen(ptr);
|
||||
sprintf( ptr, "%s,", fill_labels ? "labels" : "no_labels" );
|
||||
ptr += strlen(ptr);
|
||||
params_left -= 2;
|
||||
|
||||
CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}*/
|
||||
|
||||
|
||||
CV_FloodFillTest floodfill_test;
|
||||
|
||||
/* End of file. */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,253 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0 /* avoid this while a substitution for IPL DCT is not ready */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
|
||||
static char* funcs[] =
|
||||
{
|
||||
"cvImgToObs_DCT"
|
||||
};
|
||||
|
||||
static char *test_desc[] =
|
||||
{
|
||||
"Comparing against IPL DCT"
|
||||
};
|
||||
|
||||
/* actual parameters */
|
||||
static int min_img_size, max_img_size;
|
||||
static int max_dct_size;
|
||||
static int base_iters;
|
||||
|
||||
static int init_hmm_obs_params = 0;
|
||||
|
||||
static const int img8u_range = 256;
|
||||
|
||||
static void read_hmm_obs_params( void )
|
||||
{
|
||||
if( !init_hmm_obs_params )
|
||||
{
|
||||
/* read tests params */
|
||||
trsiRead( &min_img_size, "10", "Minimal width or height of image" );
|
||||
trsiRead( &max_img_size, "300", "Maximal width or height of image" );
|
||||
trsiRead( &max_dct_size, "24", "Maximum DCT size" );
|
||||
trsiRead( &base_iters, "100", "Base number of iterations" );
|
||||
|
||||
init_hmm_obs_params = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static CvSize hmm_obs_dct_get_size( IplImage* img, CvSize dctSize, CvSize delta )
|
||||
{
|
||||
CvSize result;
|
||||
CvRect roi = cvGetImageROI( img );
|
||||
|
||||
result.width = (roi.width - dctSize.width + delta.width) / delta.width;
|
||||
result.height = (roi.height - dctSize.height + delta.height) / delta.height;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void hmm_obs_dct_etalon( IplImage* img, char* obs, CvSize dctSize,
|
||||
CvSize obsSize, CvSize delta )
|
||||
{
|
||||
IplImage *src = cvCreateImage( dctSize, IPL_DEPTH_8U, 1 );
|
||||
IplImage *dst = cvCreateImage( dctSize, IPL_DEPTH_32F, 1 );
|
||||
|
||||
CvSize result = hmm_obs_dct_get_size( img, dctSize, delta );
|
||||
|
||||
int x, y, j;
|
||||
int obs_step = obsSize.width*sizeof(float);
|
||||
|
||||
result.width *= delta.width;
|
||||
result.height *= delta.height;
|
||||
|
||||
for( y = 0; y < result.height; y += delta.height )
|
||||
for( x = 0; x < result.width; x += delta.width )
|
||||
{
|
||||
cvSetImageROI( img, cvRect( x, y, dctSize.width, dctSize.height ));
|
||||
cvCopy( img, src );
|
||||
iplDCT2D( src, dst, IPL_DCT_Forward );
|
||||
for( j = 0; j < obsSize.height; j++ )
|
||||
{
|
||||
memcpy( obs, dst->imageData + dst->widthStep*j, obs_step );
|
||||
obs += obs_step;
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseImage( &src );
|
||||
cvReleaseImage( &dst );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ///////////////////// moments_test ///////////////////////// */
|
||||
static int hmm_dct_test( void )
|
||||
{
|
||||
const double success_error_level = 1.1;
|
||||
|
||||
int seed = atsGetSeed();
|
||||
int code = TRS_OK;
|
||||
const int max_obs_size = 8;
|
||||
|
||||
/* position where the maximum error occured */
|
||||
int i, merr_iter = 0;
|
||||
|
||||
/* test parameters */
|
||||
double max_err = 0.;
|
||||
|
||||
IplImage *img = 0;
|
||||
IplImage *obs = 0;
|
||||
IplImage *obs2 = 0;
|
||||
AtsRandState rng_state;
|
||||
CvSize obs_size;
|
||||
|
||||
atsRandInit( &rng_state, 0, img8u_range, seed );
|
||||
|
||||
read_hmm_obs_params();
|
||||
|
||||
img = cvCreateImage( cvSize( max_img_size, max_img_size ), IPL_DEPTH_8U, 1 );
|
||||
obs_size.height = max_img_size;
|
||||
obs_size.width = obs_size.height*64;
|
||||
obs = cvCreateImage( obs_size, IPL_DEPTH_32F, 1 );
|
||||
obs2 = cvCreateImage( obs_size, IPL_DEPTH_32F, 1 );
|
||||
|
||||
for( i = 0; i < base_iters; i++ )
|
||||
{
|
||||
CvSize size;
|
||||
CvSize dctSize, obsSize, delta, result;
|
||||
double err = 0;
|
||||
|
||||
size.width = atsRandPlain32s( &rng_state ) %
|
||||
(max_img_size - min_img_size + 1) + min_img_size;
|
||||
size.height = atsRandPlain32s( &rng_state ) %
|
||||
(max_img_size - min_img_size + 1) + min_img_size;
|
||||
|
||||
dctSize.width = atsRandPlain32s( &rng_state ) % (max_dct_size - 1) + 2;
|
||||
if( dctSize.width > size.width )
|
||||
dctSize.width = size.width;
|
||||
dctSize.height = atsRandPlain32s( &rng_state ) % (max_dct_size - 1) + 2;
|
||||
if( dctSize.height > size.height )
|
||||
dctSize.height = size.height;
|
||||
|
||||
obsSize.width = atsRandPlain32s( &rng_state ) % max_obs_size + 1;
|
||||
if( obsSize.width > dctSize.width )
|
||||
obsSize.width = dctSize.width;
|
||||
obsSize.height = atsRandPlain32s( &rng_state ) % max_obs_size + 1;
|
||||
if( obsSize.height > dctSize.height )
|
||||
obsSize.height = dctSize.height;
|
||||
|
||||
delta.width = atsRandPlain32s( &rng_state ) % dctSize.width + 1;
|
||||
delta.height = atsRandPlain32s( &rng_state ) % dctSize.height + 1;
|
||||
|
||||
cvSetImageROI( img, cvRect( 0, 0, size.width, size.height ));
|
||||
|
||||
result = hmm_obs_dct_get_size( img, dctSize, delta );
|
||||
|
||||
atsFillRandomImageEx( img, &rng_state );
|
||||
|
||||
OPENCV_CALL( cvImgToObs_DCT( img, (float*)(obs->imageData), dctSize, obsSize, delta ));
|
||||
|
||||
hmm_obs_dct_etalon( img, obs2->imageData, dctSize, obsSize, delta );
|
||||
|
||||
obs->width = obs2->width = result.width*obsSize.width*obsSize.height;
|
||||
obs->height = obs2->height = result.height;
|
||||
obs->widthStep = obs2->widthStep = obs->width*sizeof(float);
|
||||
|
||||
assert( obs->roi == 0 && obs2->roi == 0 );
|
||||
|
||||
err = cvNorm( obs, obs2, CV_C );
|
||||
|
||||
obs->width = obs2->width = max_img_size;
|
||||
obs->height = obs2->height = max_img_size;
|
||||
obs->widthStep = obs2->widthStep = obs->width*sizeof(float);
|
||||
|
||||
if( err > max_err )
|
||||
{
|
||||
merr_iter = i;
|
||||
max_err = err;
|
||||
if( max_err > success_error_level )
|
||||
goto test_exit;
|
||||
}
|
||||
}
|
||||
|
||||
test_exit:
|
||||
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &obs );
|
||||
cvReleaseImage( &obs2 );
|
||||
|
||||
if( code == TRS_OK )
|
||||
{
|
||||
trsWrite( ATS_LST, "Max err is %g at iter = %d, seed = %08x",
|
||||
max_err, merr_iter, seed );
|
||||
|
||||
return max_err <= success_error_level ?
|
||||
trsResult( TRS_OK, "No errors" ) :
|
||||
trsResult( TRS_FAIL, "Bad accuracy" );
|
||||
}
|
||||
/*else
|
||||
{
|
||||
trsWrite( ATS_LST, "Fatal error at iter = %d, seed = %08x", i, seed );
|
||||
return trsResult( TRS_FAIL, "Function returns error code" );
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void InitAImageToHMMObs( void )
|
||||
{
|
||||
/* Register test functions */
|
||||
|
||||
trsReg( funcs[0], test_desc[0], atsAlgoClass, hmm_dct_test );
|
||||
|
||||
} /* InitAMoments */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,128 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#define HT_STANDARD (size_t)1
|
||||
#define HT_PP (size_t)2
|
||||
#define HT_MD (size_t)3
|
||||
|
||||
static char* func_names[] = {"cvHoughTransform", "cvHoughTransformP", "cvHoughTransformSDiv"};
|
||||
static char* test_desc[] = { "Run the hough transform function"};
|
||||
|
||||
int test_dt(void* arg);
|
||||
int read_image_dims(void);
|
||||
int read_gen_type(void);
|
||||
|
||||
int test_ht(void* arg)
|
||||
{
|
||||
int nlines = 10;
|
||||
int* lines = new int[4*nlines];
|
||||
float* flines = new float[2*nlines];
|
||||
float rho = 10.0f, theta = 0.1f;
|
||||
int srn = 10, stn = 10;
|
||||
int threshold = 10;
|
||||
int lineLength = 10, lineGap = 2;
|
||||
int w = 100; /* width and height of the rect */
|
||||
int h = 100;
|
||||
int type = (int)(size_t)arg;
|
||||
IplImage* image; /* Source and destination images */
|
||||
image = cvCreateImage( cvSize(w, h), 8, 1 );
|
||||
cvZero(image);
|
||||
|
||||
if( image == NULL )
|
||||
{
|
||||
delete lines;
|
||||
delete flines;
|
||||
return trsResult(TRS_FAIL, "Not enough memory to perform the test");
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case HT_STANDARD:
|
||||
/* Run the distance transformation function */
|
||||
cvHoughLines(image, rho, theta, threshold, flines, nlines);
|
||||
break;
|
||||
|
||||
case HT_PP:
|
||||
cvHoughLinesP(image, rho, theta, threshold, lineLength, lineGap, lines, nlines);
|
||||
break;
|
||||
|
||||
case HT_MD:
|
||||
cvHoughLinesSDiv(image, rho, srn, theta, stn, threshold, flines, nlines);
|
||||
break;
|
||||
|
||||
default:
|
||||
cvReleaseImage(& image);
|
||||
delete lines;
|
||||
delete flines;
|
||||
trsResult(TRS_FAIL, "No such function");
|
||||
}
|
||||
cvReleaseImage( &image );
|
||||
delete lines;
|
||||
delete flines;
|
||||
if(cvGetErrStatus() < 0)
|
||||
{
|
||||
return trsResult(TRS_FAIL, "Function returned 'bad argument'");
|
||||
}
|
||||
else
|
||||
{
|
||||
return trsResult(TRS_OK, "No errors");
|
||||
}
|
||||
}
|
||||
|
||||
void InitAHoughLines(void)
|
||||
{
|
||||
/* Registering test functions */
|
||||
trsRegArg(func_names[0], test_desc[0], atsAlgoClass, test_ht, HT_STANDARD);
|
||||
trsRegArg(func_names[1], test_desc[0], atsAlgoClass, test_ht, HT_PP);
|
||||
trsRegArg(func_names[2], test_desc[0], atsAlgoClass, test_ht, HT_MD);
|
||||
|
||||
} /* InitADistanceTransform*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,335 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#define DEPTH_8U 0
|
||||
|
||||
/* Testing parameters */
|
||||
static char test_desc[] = "Image Creation & access";
|
||||
static char func_name[] = "cvCreateImage cvCreateImageHeader cvSetImageROI cvGetImageROI "
|
||||
"cvSetImageCOI cvCreateImageData cvReleaseImageData "
|
||||
"cvSetImageData cvCloneImage cvCopyImage cvInitImageHeader";
|
||||
|
||||
static int depths[] = { IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
|
||||
IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F, 0};
|
||||
static int channels[] = {1, 2, 3, 4, 0};
|
||||
|
||||
static char* imageData = (char*)cvAlloc(10000);
|
||||
|
||||
const int align = 4;
|
||||
|
||||
static int foaImage( void )
|
||||
{
|
||||
CvSize size = cvSize(320, 200);
|
||||
int i, j;
|
||||
int Errors = 0;
|
||||
//Creating new image with different channels & depths
|
||||
for( i = 0; depths[i] != 0; i++ ) // cycle for depths
|
||||
for(j = 0; channels[j] != 0; j++) // cycle for channels
|
||||
{
|
||||
if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
|
||||
continue; // all non 1 channels
|
||||
IplImage* image = cvCreateImage( size, depths[i], channels[j] );
|
||||
if( image->width != size.width || image->height != size.height )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCreateImage: Size mismatch: act %d x %d exp %d x %d\n",
|
||||
image->width, image->height, size.width, size.height );
|
||||
Errors++;
|
||||
}
|
||||
if( size.width * (depths[i] & IPL_DEPTH_MASK) / 8 > image->widthStep ||
|
||||
(image->widthStep & 3) )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCreateImage: Wrong widthStep: act %d\n",
|
||||
image->widthStep );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvReleaseImage( &image );
|
||||
}
|
||||
trsWrite( ATS_CON, "cvCreateImage: ... done\n" );
|
||||
|
||||
//Creating new image header with different channels & depths
|
||||
for( i = 0; depths[i] != 0; i++ ) // cycle for depths
|
||||
for(j = 0; channels[j] != 0; j++) // cycle for channels
|
||||
{
|
||||
if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
|
||||
continue; // all non 1 channels
|
||||
if( depths[i] == (int)IPL_DEPTH_8S )
|
||||
continue;
|
||||
IplImage* image = cvCreateImageHeader( size, depths[i], channels[j] );
|
||||
if( image->width != size.width || image->height != size.height )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCreateImageHeader: Size mismatch: act %d x %d exp %d x %d\n",
|
||||
image->width, image->height, size.width, size.height );
|
||||
Errors++;
|
||||
}
|
||||
if( size.width * (depths[i] & IPL_DEPTH_MASK) / 8 > image->widthStep ||
|
||||
(image->widthStep & 3) )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: Wrong widthStep: act %d\n",
|
||||
image->widthStep );
|
||||
Errors++;
|
||||
}
|
||||
if( image->imageData )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: imageData created :(\n" );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvSetImageROI( image, cvRect(1, 1, size.width - 1, size.height - 1) );
|
||||
if( image->roi->coi )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvSetImageROI: coi non zero\n" );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
CvRect rect = cvGetImageROI( image );
|
||||
if( rect.x != 1 || rect.y != 1 ||
|
||||
rect.width != size.width - 1 || rect.height != size.height - 1 )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvGetImageROI: wrong rect: act %d x %d x %d x %d "
|
||||
"exp %d x %d x %d x %d\n",
|
||||
rect.x, rect.y, rect.width, rect.height,
|
||||
1, 1, size.width - 1, size.height - 1 );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvSetImageCOI( image, 1 );
|
||||
if( image->roi->coi != 1 )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvSetImageCOI: soi non 1\n" );
|
||||
Errors++;
|
||||
}
|
||||
if( image->roi->xOffset != 1 || image->roi->yOffset != 1 ||
|
||||
image->roi->width != size.width - 1 ||
|
||||
image->roi->height != size.height - 1)
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCreateImageHeader: Size mismatch: act %d x %d x %d x %d"
|
||||
"exp %d x %d x %d x %d\n",
|
||||
image->roi->xOffset, image->roi->yOffset,
|
||||
image->roi->width, image->roi->height,
|
||||
1, 1, size.width - 1, size.height - 1 );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvCreateImageData( image );
|
||||
if( !image->imageData )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCreateImageData: Wow :)... where is imageData ?....\n" );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvReleaseImageData( image );
|
||||
if( image->imageData )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvReleaseImageData: imageData non zero :(\n" );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvSetImageData( image, imageData, size.width * channels[j] * 8 ); // magic width step :)
|
||||
if( image->imageData != imageData )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvSetImageData: wrong pointer to imageData: act %x, exp %x\n",
|
||||
image->imageData, imageData );
|
||||
Errors++;
|
||||
}
|
||||
if( image->widthStep != size.width * channels[j] * 8 )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvSetImageData: wrong imageStep: act %d, exp %d\n",
|
||||
image->widthStep, size.width * channels[j] * 8 );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
cvReleaseImageHeader( &image );
|
||||
}
|
||||
trsWrite( ATS_CON, "cvCreateImageHeader: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvSetImageROI: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvGetImageROI: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvSetImageCOI: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvCreateImageData: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvReleaseImageData: ... done\n" );
|
||||
trsWrite( ATS_CON, "cvSetImageData: ... done\n" );
|
||||
|
||||
for( i = 0; depths[i] != 0; i++ ) // cycle for depths
|
||||
for(j = 0; channels[j] != 0; j++) // cycle for channels
|
||||
{
|
||||
if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
|
||||
continue; // all non 1 channels
|
||||
if( depths[i] == (int)IPL_DEPTH_8S )
|
||||
continue;
|
||||
IplImage* src = cvCreateImage( size, depths[i], channels[j] );
|
||||
//IplImage* dst = cvCreateImage( size, depths[i], channels[j] );
|
||||
IplImage* dst = 0;
|
||||
IplImage* clone = 0;
|
||||
|
||||
cvSetImageROI( src, cvRect(1, 1, size.width - 1, size.height - 1) );
|
||||
|
||||
for( int k = 0; k < src->widthStep * src->height; k++ )
|
||||
src->imageData[k] = (char)k;
|
||||
|
||||
//cvCopy/*Image*/( src, dst );
|
||||
dst = cvCloneImage( src );
|
||||
clone = dst;
|
||||
|
||||
if( clone->width != dst->width || clone->height != dst->height )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCopyImage/cvCloneImage: wrong destination size:"
|
||||
"%d x %d <> %d %d\n",
|
||||
clone->width, clone->height, dst->width, dst->height );
|
||||
Errors++;
|
||||
}
|
||||
if( clone->widthStep != src->widthStep )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCloneImage: wrong width step: act %d exp %d\n",
|
||||
clone->widthStep, src->widthStep );
|
||||
Errors++;
|
||||
}
|
||||
if( !clone->roi )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCloneImage: roi was lost\n" );
|
||||
Errors++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( clone->roi->xOffset != 1 || clone->roi->yOffset != 1 ||
|
||||
clone->roi->width != size.width - 1 ||
|
||||
clone->roi->height != size.height - 1 )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCloneImage: Size mismatch: act %d x %d x %d x %d"
|
||||
"exp %d x %d x %d x %d\n",
|
||||
clone->roi->xOffset, clone->roi->yOffset,
|
||||
clone->roi->width, clone->roi->height,
|
||||
1, 1, size.width - 1, size.height - 1 );
|
||||
Errors++;
|
||||
}
|
||||
|
||||
}
|
||||
if( depths[i] == IPL_DEPTH_32F )
|
||||
{
|
||||
src->depth = IPL_DEPTH_32S;
|
||||
dst->depth = IPL_DEPTH_32S;
|
||||
}
|
||||
else if( depths[i] == IPL_DEPTH_64F )
|
||||
{
|
||||
src->depth = IPL_DEPTH_32S;
|
||||
dst->depth = IPL_DEPTH_32S;
|
||||
|
||||
src->width *= 2;
|
||||
dst->width *= 2;
|
||||
}
|
||||
|
||||
if( cvNorm( src, dst, CV_L1 ) )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCopyImage: wrong destination image\n" );
|
||||
Errors++;
|
||||
}
|
||||
/*if( cvNorm( src, clone, CV_L1 ) )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCloneImage: wrong destination image\n" );
|
||||
Errors++;
|
||||
}*/
|
||||
|
||||
cvReleaseImage( &src );
|
||||
cvReleaseImage( &clone );
|
||||
}
|
||||
trsWrite( ATS_CON, "cvCloneImage: ... done\n" );
|
||||
//trsWrite( ATS_CON, "cvCopyImage: ... done\n" );
|
||||
|
||||
//Init new image header with different channels & depths
|
||||
for( i = 0; depths[i] != 0; i++ ) // cycle for depths
|
||||
for(j = 0; channels[j] != 0; j++) // cycle for channels
|
||||
{
|
||||
if( depths[i] == IPL_DEPTH_1U && channels[j] != 1 ) // skip for IPL_DEPTH_1U
|
||||
continue; // all non 1 channels
|
||||
IplImage image;
|
||||
cvInitImageHeader( &image, size, depths[i], channels[j], IPL_ORIGIN_TL, align );
|
||||
if( image.width != size.width || image.height != size.height )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvInitImageHeader: Size mismatch: act %d x %d exp %d x %d\n",
|
||||
image.width, image.height, size.width, size.height );
|
||||
Errors++;
|
||||
}
|
||||
if( ((size.width * channels[j] * (depths[i] & IPL_DEPTH_MASK) / 8 + align - 1) &
|
||||
~(align - 1)) != image.widthStep )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST,
|
||||
"cvCreateImageHeader: Wrong widthStep: act %d exp: %d\n",
|
||||
image.widthStep,
|
||||
(size.width * (depths[i] & IPL_DEPTH_MASK) / 8 + align - 1) &
|
||||
~(align - 1) );
|
||||
Errors++;
|
||||
}
|
||||
if( image.imageData )
|
||||
{
|
||||
trsWrite( ATS_CON | ATS_LST, "cvCreateImageHeader: imageData created :(\n" );
|
||||
Errors++;
|
||||
}
|
||||
}
|
||||
trsWrite( ATS_CON, "cvInitImageHeader: ... done\n" );
|
||||
|
||||
if( !Errors )
|
||||
return trsResult( TRS_OK, "Ok" );
|
||||
else
|
||||
return trsResult( TRS_FAIL, "%d errors" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InitAImage()
|
||||
{
|
||||
/* Register test function */
|
||||
trsReg( func_name, test_desc, atsAlgoClass, foaImage );
|
||||
} /* InitACanny */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,123 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_KalmanTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_KalmanTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_KalmanTest::CV_KalmanTest():
|
||||
CvTest( "kalman", "cvKalmanPredict, cvKalmanCorrect" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_KalmanTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
const int Dim = 7;
|
||||
const int Steps = 100;
|
||||
const double max_init = 1;
|
||||
const double max_noise = 0.1;
|
||||
|
||||
const double EPSILON = 1.000;
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvKalman* Kalm;
|
||||
int i, j;
|
||||
|
||||
CvMat* Sample = cvCreateMat(Dim,1,CV_32F);
|
||||
CvMat* Temp = cvCreateMat(Dim,1,CV_32F);
|
||||
|
||||
Kalm = cvCreateKalman(Dim, Dim);
|
||||
CvMat Dyn = cvMat(Dim,Dim,CV_32F,Kalm->DynamMatr);
|
||||
CvMat Mes = cvMat(Dim,Dim,CV_32F,Kalm->MeasurementMatr);
|
||||
CvMat PNC = cvMat(Dim,Dim,CV_32F,Kalm->PNCovariance);
|
||||
CvMat MNC = cvMat(Dim,Dim,CV_32F,Kalm->MNCovariance);
|
||||
CvMat PriErr = cvMat(Dim,Dim,CV_32F,Kalm->PriorErrorCovariance);
|
||||
CvMat PostErr = cvMat(Dim,Dim,CV_32F,Kalm->PosterErrorCovariance);
|
||||
CvMat PriState = cvMat(Dim,1,CV_32F,Kalm->PriorState);
|
||||
CvMat PostState = cvMat(Dim,1,CV_32F,Kalm->PosterState);
|
||||
cvSetIdentity(&PNC);
|
||||
cvSetIdentity(&PriErr);
|
||||
cvSetIdentity(&PostErr);
|
||||
cvSetZero(&MNC);
|
||||
cvSetZero(&PriState);
|
||||
cvSetZero(&PostState);
|
||||
cvSetIdentity(&Mes);
|
||||
cvSetIdentity(&Dyn);
|
||||
cvRandArr(rng, Sample, CV_RAND_UNI, cvScalarAll(-max_init), cvScalarAll(max_init));
|
||||
cvKalmanCorrect(Kalm, Sample);
|
||||
for(i = 0; i<Steps; i++)
|
||||
{
|
||||
cvKalmanPredict(Kalm);
|
||||
for(j = 0; j<Dim; j++)
|
||||
{
|
||||
float t = 0;
|
||||
for(int k=0; k<Dim; k++)
|
||||
{
|
||||
t += Dyn.data.fl[j*Dim+k]*Sample->data.fl[k];
|
||||
}
|
||||
Temp->data.fl[j]= (float)(t+(cvTsRandReal(rng)*2-1)*max_noise);
|
||||
}
|
||||
cvCopy( Temp, Sample );
|
||||
cvKalmanCorrect(Kalm,Temp);
|
||||
}
|
||||
|
||||
code = cvTsCmpEps2( ts, Sample, Kalm->state_post, EPSILON, false, "The final estimated state" );
|
||||
|
||||
cvReleaseMat(&Sample);
|
||||
cvReleaseMat(&Temp);
|
||||
cvReleaseKalman(&Kalm);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_KalmanTest kalman_test;
|
||||
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,291 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
/* Testing parameters */
|
||||
static char test_desc[] = "KMeans clustering";
|
||||
static char* func_name[] =
|
||||
{
|
||||
"cvKMeans"
|
||||
};
|
||||
|
||||
//based on Ara Nefian's implementation
|
||||
float distance(float* vector_1, float *vector_2, int VecSize)
|
||||
{
|
||||
int i;
|
||||
float dist;
|
||||
|
||||
dist = 0.0;
|
||||
for (i = 0; i < VecSize; i++)
|
||||
{
|
||||
//printf ("%f, %f\n", vector_1[i], vector_2[i]);
|
||||
dist = dist + (vector_1[i] - vector_2[i])*(vector_1[i] - vector_2[i]);
|
||||
}
|
||||
return dist;
|
||||
}
|
||||
|
||||
//returns number of made iterations
|
||||
int _real_kmeans( int numClusters, float **sample, int numSamples,
|
||||
int VecSize, int* a_class, double eps, int iter )
|
||||
|
||||
{
|
||||
int i, k, n;
|
||||
int *counter;
|
||||
float minDist;
|
||||
float *dist;
|
||||
float **curr_cluster;
|
||||
float **prev_cluster;
|
||||
|
||||
float error;
|
||||
|
||||
//printf("* numSamples = %d, numClusters = %d, VecSize = %d\n", numSamples, numClusters, VecSize);
|
||||
|
||||
//memory allocation
|
||||
dist = new float[numClusters];
|
||||
counter = new int[numClusters];
|
||||
|
||||
//allocate memory for curr_cluster and prev_cluster
|
||||
curr_cluster = new float*[numClusters];
|
||||
prev_cluster = new float*[numClusters];
|
||||
for (k = 0; k < numClusters; k++){
|
||||
curr_cluster[k] = new float[VecSize];
|
||||
prev_cluster[k] = new float[VecSize];
|
||||
}
|
||||
|
||||
//pick initial cluster centers
|
||||
for (k = 0; k < numClusters; k++)
|
||||
{
|
||||
for (n = 0; n < VecSize; n++)
|
||||
{
|
||||
curr_cluster[k][n] = sample[k*(numSamples/numClusters)][n];
|
||||
prev_cluster[k][n] = sample[k*(numSamples/numClusters)][n];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int NumIter = 0;
|
||||
error = FLT_MAX;
|
||||
while ((error > eps) && (NumIter < iter))
|
||||
{
|
||||
NumIter++;
|
||||
//printf("NumIter = %d, error = %lf, \n", NumIter, error);
|
||||
|
||||
//assign samples to clusters
|
||||
for (i = 0; i < numSamples; i++)
|
||||
{
|
||||
for (k = 0; k < numClusters; k++)
|
||||
{
|
||||
dist[k] = distance(sample[i], curr_cluster[k], VecSize);
|
||||
}
|
||||
minDist = dist[0];
|
||||
a_class[i] = 0;
|
||||
for (k = 1; k < numClusters; k++)
|
||||
{
|
||||
if (dist[k] < minDist)
|
||||
{
|
||||
minDist = dist[k];
|
||||
a_class[i] = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//reset clusters and counters
|
||||
for (k = 0; k < numClusters; k++){
|
||||
counter[k] = 0;
|
||||
for (n = 0; n < VecSize; n++){
|
||||
curr_cluster[k][n] = 0.0;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < numSamples; i++){
|
||||
for (n = 0; n < VecSize; n++){
|
||||
curr_cluster[a_class[i]][n] = curr_cluster[a_class[i]][n] + sample[i][n];
|
||||
}
|
||||
counter[a_class[i]]++;
|
||||
}
|
||||
|
||||
for (k = 0; k < numClusters; k++){
|
||||
for (n = 0; n < VecSize; n++){
|
||||
curr_cluster[k][n] = curr_cluster[k][n]/(float)counter[k];
|
||||
}
|
||||
}
|
||||
|
||||
error = 0.0;
|
||||
for (k = 0; k < numClusters; k++){
|
||||
for (n = 0; n < VecSize; n++){
|
||||
error = error + (curr_cluster[k][n] - prev_cluster[k][n])*(curr_cluster[k][n] - prev_cluster[k][n]);
|
||||
}
|
||||
}
|
||||
//error = error/(double)(numClusters*VecSize);
|
||||
|
||||
//copy curr_clusters to prev_clusters
|
||||
for (k = 0; k < numClusters; k++){
|
||||
for (n =0; n < VecSize; n++){
|
||||
prev_cluster[k][n] = curr_cluster[k][n];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//deallocate memory for curr_cluster and prev_cluster
|
||||
for (k = 0; k < numClusters; k++){
|
||||
delete curr_cluster[k];
|
||||
delete prev_cluster[k];
|
||||
}
|
||||
delete curr_cluster;
|
||||
delete prev_cluster;
|
||||
|
||||
delete counter;
|
||||
delete dist;
|
||||
return NumIter;
|
||||
|
||||
}
|
||||
|
||||
static int fmaKMeans(void)
|
||||
{
|
||||
CvTermCriteria crit;
|
||||
float** vectors;
|
||||
int* output;
|
||||
int* etalon_output;
|
||||
|
||||
int lErrors = 0;
|
||||
int lNumVect = 0;
|
||||
int lVectSize = 0;
|
||||
int lNumClust = 0;
|
||||
int lMaxNumIter = 0;
|
||||
float flEpsilon = 0;
|
||||
|
||||
int i,j;
|
||||
static int read_param = 0;
|
||||
|
||||
/* Initialization global parameters */
|
||||
if( !read_param )
|
||||
{
|
||||
read_param = 1;
|
||||
/* Read test-parameters */
|
||||
trsiRead( &lNumVect, "1000", "Number of vectors" );
|
||||
trsiRead( &lVectSize, "10", "Number of vectors" );
|
||||
trsiRead( &lNumClust, "20", "Number of clusters" );
|
||||
trsiRead( &lMaxNumIter,"100","Maximal number of iterations");
|
||||
trssRead( &flEpsilon, "0.5", "Accuracy" );
|
||||
}
|
||||
|
||||
crit = cvTermCriteria( CV_TERMCRIT_EPS|CV_TERMCRIT_ITER, lMaxNumIter, flEpsilon );
|
||||
|
||||
//allocate vectors
|
||||
vectors = (float**)cvAlloc( lNumVect * sizeof(float*) );
|
||||
for( i = 0; i < lNumVect; i++ )
|
||||
{
|
||||
vectors[i] = (float*)cvAlloc( lVectSize * sizeof( float ) );
|
||||
}
|
||||
|
||||
output = (int*)cvAlloc( lNumVect * sizeof(int) );
|
||||
etalon_output = (int*)cvAlloc( lNumVect * sizeof(int) );
|
||||
|
||||
//fill input vectors
|
||||
for( i = 0; i < lNumVect; i++ )
|
||||
{
|
||||
ats1flInitRandom( -2000, 2000, vectors[i], lVectSize );
|
||||
}
|
||||
|
||||
/* run etalon kmeans */
|
||||
/* actually it is the simpliest realization of kmeans */
|
||||
|
||||
int ni = _real_kmeans( lNumClust, vectors, lNumVect, lVectSize, etalon_output, crit.epsilon, crit.max_iter );
|
||||
|
||||
trsWrite( ATS_CON, "%d iterations done\n", ni );
|
||||
|
||||
/* Run OpenCV function */
|
||||
#define _KMEANS_TIME 0
|
||||
|
||||
#if _KMEANS_TIME
|
||||
//timing section
|
||||
trsTimerStart(0);
|
||||
__int64 tics = atsGetTickCount();
|
||||
#endif
|
||||
|
||||
cvKMeans( lNumClust, vectors, lNumVect, lVectSize,
|
||||
crit, output );
|
||||
|
||||
#if _KMEANS_TIME
|
||||
tics = atsGetTickCount() - tics;
|
||||
trsTimerStop(0);
|
||||
//output result
|
||||
//double dbUsecs =ATS_TICS_TO_USECS((double)tics);
|
||||
trsWrite( ATS_CON, "Tics per iteration %d\n", tics/ni );
|
||||
|
||||
#endif
|
||||
|
||||
//compare results
|
||||
for( j = 0; j < lNumVect; j++ )
|
||||
{
|
||||
if ( output[j] != etalon_output[j] )
|
||||
{
|
||||
lErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
//free memory
|
||||
for( i = 0; i < lNumVect; i++ )
|
||||
{
|
||||
cvFree( &(vectors[i]) );
|
||||
}
|
||||
cvFree(&vectors);
|
||||
cvFree(&output);
|
||||
cvFree(&etalon_output);
|
||||
|
||||
if( lErrors == 0 ) return trsResult( TRS_OK, "No errors fixed for this text" );
|
||||
else return trsResult( TRS_FAIL, "Detected %d errors", lErrors );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InitAKMeans()
|
||||
{
|
||||
/* Register test function */
|
||||
trsReg( func_name[0], test_desc, atsAlgoClass, fmaKMeans );
|
||||
|
||||
} /* InitAKMeans */
|
||||
|
||||
#endif
|
||||
@@ -1,192 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
/*#include "conio.h" */
|
||||
|
||||
static char cTestName[] = "Matching Contour trees";
|
||||
static char cTestClass[] = "Algorithm";
|
||||
static char cFuncName[] = "cvMatchContourTrees";
|
||||
|
||||
static int aMatchContourTrees(void)
|
||||
{
|
||||
CvSeqBlock contour_blk1, contour_blk2;
|
||||
CvContour contour_h1, contour_h2;
|
||||
CvContourTree *tree1, *tree2;
|
||||
CvMemStorage *storage; /* storage for contour and tree writing */
|
||||
int block_size = 10000;
|
||||
|
||||
CvRandState state;
|
||||
double lower, upper;
|
||||
int seed;
|
||||
float fr;
|
||||
int type_seq;
|
||||
int method;
|
||||
int nPoints1 = 12, nPoints2 = 12;
|
||||
int xc,yc,a1 = 10, b1 = 20, a2 = 10, b2 =20, fi = 0;
|
||||
int xmin,ymin,xmax,ymax;
|
||||
double error_test,rezult, eps_rez = 0.8;
|
||||
double pi = 3.1415926;
|
||||
double threshold = 1.e-7;
|
||||
double threshold2 = 5.;
|
||||
int i;
|
||||
int code = TRS_OK;
|
||||
|
||||
int width=256,height=256;
|
||||
CvPoint *cp1,*cp2;
|
||||
|
||||
/* read tests params */
|
||||
|
||||
if (!trsiRead(&nPoints1,"20","Number of points first contour"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&nPoints2,"20","Number of points second contour"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
if(nPoints1>0&&nPoints2>0)
|
||||
{
|
||||
if (!trsiRead(&a1,"10","first radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&b1,"20","second radius of the first elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&a2,"15","first radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&b2,"30","second radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
if (!trsiRead(&fi,"0","second radius of the second elipse"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
if (!trsdRead(&upper,"3","noise amplidude"))
|
||||
return TRS_UNDEF;
|
||||
|
||||
xc = (int)(width/2.);
|
||||
yc = (int)(height/2.);
|
||||
xmin = width;
|
||||
ymin = height;
|
||||
xmax = 0;
|
||||
ymax = 0;
|
||||
|
||||
cp1 = (CvPoint*) trsmAlloc(nPoints1*sizeof(CvPoint));
|
||||
cp2 = (CvPoint*) trsmAlloc(nPoints2*sizeof(CvPoint));
|
||||
|
||||
for(i=0;i<nPoints1;i++)
|
||||
{
|
||||
cp1[i].x = (int)(a1*cos(2*pi*i/nPoints1))+xc;
|
||||
cp1[i].y = (int)(b1*sin(2*pi*i/nPoints1))+yc;
|
||||
if(xmin> cp1[i].x) xmin = cp1[i].x;
|
||||
if(xmax< cp1[i].x) xmax = cp1[i].x;
|
||||
if(ymin> cp1[i].y) ymin = cp1[i].y;
|
||||
if(ymax< cp1[i].y) ymax = cp1[i].y;
|
||||
}
|
||||
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
|
||||
|
||||
lower = -upper;
|
||||
/* upper = 3;*/
|
||||
seed = 345753;
|
||||
cvRandInit(&state, (float)lower,(float)upper, seed );
|
||||
for(i=0;i<nPoints2;i++)
|
||||
{
|
||||
cvbRand( &state, &fr, 1 );
|
||||
cp2[i].x =(int)fr+(int)(a2*cos(2*pi*i/nPoints2)*cos(2*pi*fi/360.))-
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+xc;
|
||||
cvbRand( &state, &fr, 1 );
|
||||
cp2[i].y =(int)fr+(int)(a2*cos(2*pi*i/nPoints2)*sin(2*pi*fi/360.))+
|
||||
(int)(b2*sin(2*pi*i/nPoints2)*cos(2*pi*fi/360.))+yc;
|
||||
|
||||
if(xmin> cp2[i].x) xmin = cp2[i].x;
|
||||
if(xmax< cp2[i].x) xmax = cp2[i].x;
|
||||
if(ymin> cp2[i].y) ymin = cp2[i].y;
|
||||
if(ymax< cp2[i].y) ymax = cp2[i].y;
|
||||
}
|
||||
if(xmax>width||xmin<0||ymax>height||ymin<0) return TRS_FAIL;
|
||||
|
||||
/* contours initialazing */
|
||||
type_seq = CV_SEQ_POLYGON;
|
||||
cvMakeSeqHeaderForArray( type_seq, sizeof(CvContour), sizeof(CvPoint),
|
||||
(char*)cp1, nPoints1, (CvSeq*)&contour_h1, &contour_blk1);
|
||||
|
||||
cvMakeSeqHeaderForArray( type_seq, sizeof(CvContour), sizeof(CvPoint),
|
||||
(char*)cp2, nPoints2, (CvSeq*)&contour_h2, &contour_blk2);
|
||||
|
||||
/* contour trees created*/
|
||||
storage = cvCreateMemStorage( block_size );
|
||||
|
||||
tree1 = cvCreateContourTree ((CvSeq*)&contour_h1, storage, threshold);
|
||||
tree2 = cvCreateContourTree ((CvSeq*)&contour_h2, storage, threshold);
|
||||
|
||||
|
||||
/* countours matchig */
|
||||
error_test = 0.;
|
||||
method = 1;
|
||||
|
||||
rezult = cvMatchContourTrees (tree1, tree2, (CvContourTreesMatchMethod)method,threshold2);
|
||||
error_test+=rezult;
|
||||
|
||||
if(error_test > eps_rez ) code = TRS_FAIL;
|
||||
else code = TRS_OK;
|
||||
|
||||
trsWrite( ATS_CON | ATS_LST | ATS_SUM, "contours matching error_test =%f \n",
|
||||
error_test);
|
||||
|
||||
cvReleaseMemStorage ( &storage );
|
||||
|
||||
trsFree (cp2);
|
||||
trsFree (cp1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* _getch(); */
|
||||
return code;
|
||||
}
|
||||
|
||||
void InitAMatchContourTrees( void )
|
||||
{
|
||||
/* Test Registartion */
|
||||
trsReg(cFuncName,cTestName,cTestClass,aMatchContourTrees);
|
||||
|
||||
} /* InitAMatchContourTrees */
|
||||
|
||||
/* End of file. */
|
||||
|
||||
#endif
|
||||
@@ -1,425 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* moments_param_names[] = { "size", "depth", 0 };
|
||||
static const int moments_depths[] = { CV_8U, CV_32F, -1 };
|
||||
|
||||
static const CvSize moments_sizes[] = {{30,30}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const CvSize moments_whole_sizes[] = {{320,240}, {320, 240}, {720,480}, {-1,-1}};
|
||||
|
||||
// image moments
|
||||
class CV_MomentsTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_MomentsTest();
|
||||
|
||||
protected:
|
||||
|
||||
enum { MOMENT_COUNT = 25 };
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void prepare_to_validation( int /*test_case_idx*/ );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
int coi;
|
||||
bool is_binary;
|
||||
};
|
||||
|
||||
|
||||
CV_MomentsTest::CV_MomentsTest()
|
||||
: CvArrTest( "moments-raster", "cvMoments, cvGetNormalizedCentralMoment", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
coi = -1;
|
||||
is_binary = false;
|
||||
//element_wise_relative_error = false;
|
||||
|
||||
default_timing_param_names = moments_param_names;
|
||||
depth_list = moments_depths;
|
||||
size_list = moments_sizes;
|
||||
whole_size_list = moments_whole_sizes;
|
||||
|
||||
cn_list = 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CvArrTest::get_minmax_bounds( i, j, type, low, high );
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
|
||||
if( depth == CV_16U )
|
||||
{
|
||||
*low = cvScalarAll(0);
|
||||
*high = cvScalarAll(1000);
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
*low = cvScalarAll(-1000);
|
||||
*high = cvScalarAll(1000);
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
*low = cvScalarAll(-1);
|
||||
*high = cvScalarAll(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
int cn = cvTsRandInt(rng) % 4 + 1;
|
||||
int depth = cvTsRandInt(rng) % 4;
|
||||
depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F;
|
||||
if( cn == 2 )
|
||||
cn = 1;
|
||||
|
||||
types[INPUT][0] = CV_MAKETYPE(depth, cn);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1);
|
||||
|
||||
is_binary = cvTsRandInt(rng) % 2 != 0;
|
||||
coi = 0;
|
||||
cvmat_allowed = true;
|
||||
if( cn > 1 )
|
||||
{
|
||||
coi = cvTsRandInt(rng) % cn;
|
||||
cvmat_allowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
types[OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][0] = whole_sizes[OUTPUT][0] = cvSize(MOMENT_COUNT,1);
|
||||
}
|
||||
|
||||
|
||||
double CV_MomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(test_mat[INPUT][0].type);
|
||||
return depth != CV_32F ? FLT_EPSILON*10 : FLT_EPSILON*100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CV_MomentsTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
int cn = CV_MAT_CN(test_mat[INPUT][0].type);
|
||||
if( cn > 1 )
|
||||
cvSetImageCOI( (IplImage*)test_array[INPUT][0], coi + 1 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::run_func()
|
||||
{
|
||||
CvMoments* m = (CvMoments*)test_mat[OUTPUT][0].data.db;
|
||||
double* others = (double*)(m + 1);
|
||||
cvMoments( test_array[INPUT][0], m, is_binary );
|
||||
others[0] = cvGetNormalizedCentralMoment( m, 2, 0 );
|
||||
others[1] = cvGetNormalizedCentralMoment( m, 1, 1 );
|
||||
others[2] = cvGetNormalizedCentralMoment( m, 0, 2 );
|
||||
others[3] = cvGetNormalizedCentralMoment( m, 3, 0 );
|
||||
others[4] = cvGetNormalizedCentralMoment( m, 2, 1 );
|
||||
others[5] = cvGetNormalizedCentralMoment( m, 1, 2 );
|
||||
others[6] = cvGetNormalizedCentralMoment( m, 0, 3 );
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMat* src = &test_mat[INPUT][0];
|
||||
CvMoments m;
|
||||
double* mdata = test_mat[REF_OUTPUT][0].data.db;
|
||||
int depth = CV_MAT_DEPTH(src->type);
|
||||
int cn = CV_MAT_CN(src->type);
|
||||
int i, y, x, cols = src->cols;
|
||||
double xc = 0., yc = 0.;
|
||||
|
||||
memset( &m, 0, sizeof(m));
|
||||
|
||||
for( y = 0; y < src->rows; y++ )
|
||||
{
|
||||
double s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
||||
uchar* ptr = src->data.ptr + y*src->step;
|
||||
for( x = 0; x < cols; x++ )
|
||||
{
|
||||
double val;
|
||||
if( depth == CV_8U )
|
||||
val = ptr[x*cn + coi];
|
||||
else if( depth == CV_16U )
|
||||
val = ((ushort*)ptr)[x*cn + coi];
|
||||
else if( depth == CV_16S )
|
||||
val = ((short*)ptr)[x*cn + coi];
|
||||
else
|
||||
val = ((float*)ptr)[x*cn + coi];
|
||||
|
||||
if( is_binary )
|
||||
val = val != 0;
|
||||
|
||||
s0 += val;
|
||||
s1 += val*x;
|
||||
s2 += val*x*x;
|
||||
s3 += ((val*x)*x)*x;
|
||||
}
|
||||
|
||||
m.m00 += s0;
|
||||
m.m01 += s0*y;
|
||||
m.m02 += (s0*y)*y;
|
||||
m.m03 += ((s0*y)*y)*y;
|
||||
|
||||
m.m10 += s1;
|
||||
m.m11 += s1*y;
|
||||
m.m12 += (s1*y)*y;
|
||||
|
||||
m.m20 += s2;
|
||||
m.m21 += s2*y;
|
||||
|
||||
m.m30 += s3;
|
||||
}
|
||||
|
||||
if( m.m00 != 0 )
|
||||
{
|
||||
xc = m.m10/m.m00, yc = m.m01/m.m00;
|
||||
m.inv_sqrt_m00 = 1./sqrt(fabs(m.m00));
|
||||
}
|
||||
|
||||
for( y = 0; y < src->rows; y++ )
|
||||
{
|
||||
double s0 = 0, s1 = 0, s2 = 0, s3 = 0, y1 = y - yc;
|
||||
uchar* ptr = src->data.ptr + y*src->step;
|
||||
for( x = 0; x < cols; x++ )
|
||||
{
|
||||
double val, x1 = x - xc;
|
||||
if( depth == CV_8U )
|
||||
val = ptr[x*cn + coi];
|
||||
else if( depth == CV_16U )
|
||||
val = ((ushort*)ptr)[x*cn + coi];
|
||||
else if( depth == CV_16S )
|
||||
val = ((short*)ptr)[x*cn + coi];
|
||||
else
|
||||
val = ((float*)ptr)[x*cn + coi];
|
||||
|
||||
if( is_binary )
|
||||
val = val != 0;
|
||||
|
||||
s0 += val;
|
||||
s1 += val*x1;
|
||||
s2 += val*x1*x1;
|
||||
s3 += ((val*x1)*x1)*x1;
|
||||
}
|
||||
|
||||
m.mu02 += s0*y1*y1;
|
||||
m.mu03 += ((s0*y1)*y1)*y1;
|
||||
|
||||
m.mu11 += s1*y1;
|
||||
m.mu12 += (s1*y1)*y1;
|
||||
|
||||
m.mu20 += s2;
|
||||
m.mu21 += s2*y1;
|
||||
|
||||
m.mu30 += s3;
|
||||
}
|
||||
|
||||
memcpy( mdata, &m, sizeof(m));
|
||||
mdata += sizeof(m)/sizeof(m.m00);
|
||||
|
||||
/* calc normalized moments */
|
||||
{
|
||||
double inv_m00 = m.inv_sqrt_m00*m.inv_sqrt_m00;
|
||||
double s2 = inv_m00*inv_m00; /* 1./(m00 ^ (2/2 + 1)) */
|
||||
double s3 = s2*m.inv_sqrt_m00; /* 1./(m00 ^ (3/2 + 1)) */
|
||||
|
||||
mdata[0] = m.mu20 * s2;
|
||||
mdata[1] = m.mu11 * s2;
|
||||
mdata[2] = m.mu02 * s2;
|
||||
|
||||
mdata[3] = m.mu30 * s3;
|
||||
mdata[4] = m.mu21 * s3;
|
||||
mdata[5] = m.mu12 * s3;
|
||||
mdata[6] = m.mu03 * s3;
|
||||
}
|
||||
|
||||
{
|
||||
double* a = test_mat[REF_OUTPUT][0].data.db;
|
||||
double* b = test_mat[OUTPUT][0].data.db;
|
||||
for( i = 0; i < MOMENT_COUNT; i++ )
|
||||
{
|
||||
if( fabs(a[i]) < 1e-3 )
|
||||
a[i] = 0;
|
||||
if( fabs(b[i]) < 1e-3 )
|
||||
b[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_MomentsTest img_moments_test;
|
||||
|
||||
|
||||
// Hu invariants
|
||||
class CV_HuMomentsTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_HuMomentsTest();
|
||||
|
||||
protected:
|
||||
|
||||
enum { MOMENT_COUNT = 18, HU_MOMENT_COUNT = 7 };
|
||||
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void prepare_to_validation( int /*test_case_idx*/ );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
};
|
||||
|
||||
|
||||
CV_HuMomentsTest::CV_HuMomentsTest()
|
||||
: CvArrTest( "moments-hu", "cvHuMoments", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE; // for now disable the timing test
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CvArrTest::get_minmax_bounds( i, j, type, low, high );
|
||||
*low = cvScalarAll(-10000);
|
||||
*high = cvScalarAll(10000);
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[INPUT][0] = cvSize(MOMENT_COUNT,1);
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(HU_MOMENT_COUNT,1);
|
||||
}
|
||||
|
||||
|
||||
double CV_HuMomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return FLT_EPSILON;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CV_HuMomentsTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::run_func()
|
||||
{
|
||||
cvGetHuMoments( (CvMoments*)test_mat[INPUT][0].data.db,
|
||||
(CvHuMoments*)test_mat[OUTPUT][0].data.db );
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMoments* m = (CvMoments*)test_mat[INPUT][0].data.db;
|
||||
CvHuMoments* hu = (CvHuMoments*)test_mat[REF_OUTPUT][0].data.db;
|
||||
|
||||
double inv_m00 = m->inv_sqrt_m00*m->inv_sqrt_m00;
|
||||
double s2 = inv_m00*inv_m00; /* 1./(m00 ^ (2/2 + 1)) */
|
||||
double s3 = s2*m->inv_sqrt_m00; /* 1./(m00 ^ (3/2 + 1)) */
|
||||
|
||||
double nu20 = m->mu20 * s2;
|
||||
double nu11 = m->mu11 * s2;
|
||||
double nu02 = m->mu02 * s2;
|
||||
|
||||
double nu30 = m->mu30 * s3;
|
||||
double nu21 = m->mu21 * s3;
|
||||
double nu12 = m->mu12 * s3;
|
||||
double nu03 = m->mu03 * s3;
|
||||
|
||||
#undef sqr
|
||||
#define sqr(a) ((a)*(a))
|
||||
|
||||
hu->hu1 = nu20 + nu02;
|
||||
hu->hu2 = sqr(nu20 - nu02) + 4*sqr(nu11);
|
||||
hu->hu3 = sqr(nu30 - 3*nu12) + sqr(3*nu21 - nu03);
|
||||
hu->hu4 = sqr(nu30 + nu12) + sqr(nu21 + nu03);
|
||||
hu->hu5 = (nu30 - 3*nu12)*(nu30 + nu12)*(sqr(nu30 + nu12) - 3*sqr(nu21 + nu03)) +
|
||||
(3*nu21 - nu03)*(nu21 + nu03)*(3*sqr(nu30 + nu12) - sqr(nu21 + nu03));
|
||||
hu->hu6 = (nu20 - nu02)*(sqr(nu30 + nu12) - sqr(nu21 + nu03)) +
|
||||
4*nu11*(nu30 + nu12)*(nu21 + nu03);
|
||||
hu->hu7 = (3*nu21 - nu03)*(nu30 + nu12)*(sqr(nu30 + nu12) - 3*sqr(nu21 + nu03)) +
|
||||
(3*nu12 - nu30)*(nu21 + nu03)*(3*sqr(nu30 + nu12) - sqr(nu21 + nu03));
|
||||
}
|
||||
|
||||
|
||||
CV_HuMomentsTest hu_moments_test;
|
||||
@@ -1,642 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const int motempl_silh_ratio[] = { 10, 50 };
|
||||
static const int motempl_duration[] = { 200, 2000 };
|
||||
static const int motempl_gradient_aperture[] = { 3, 5 };
|
||||
static const char* motempl_update_param_names[] = { "silh_ratio", "duration", "size", 0 };
|
||||
static const char* motempl_gradient_param_names[] = { "silh_ratio", "duration", "aperture", "size", 0 };
|
||||
static const char* motempl_global_param_names[] = { "silh_ratio", "duration", "size", 0 };
|
||||
static const CvSize motempl_sizes[] = {{320, 240}, {720,480}, {-1,-1}};
|
||||
|
||||
///////////////////// base MHI class ///////////////////////
|
||||
class CV_MHIBaseTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_MHIBaseTest( const char* test_name, const char* test_funcs );
|
||||
|
||||
protected:
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
double timestamp, duration, max_log_duration;
|
||||
int mhi_i, mhi_ref_i;
|
||||
double silh_ratio;
|
||||
};
|
||||
|
||||
|
||||
CV_MHIBaseTest::CV_MHIBaseTest( const char* test_name, const char* test_funcs )
|
||||
: CvArrTest( test_name, test_funcs )
|
||||
{
|
||||
timestamp = duration = 0;
|
||||
max_log_duration = 9;
|
||||
mhi_i = mhi_ref_i = -1;
|
||||
|
||||
size_list = whole_size_list = strcmp( test_funcs, "" ) == 0 ? motempl_sizes : 0;
|
||||
depth_list = 0;
|
||||
cn_list = 0;
|
||||
default_timing_param_names = 0;
|
||||
|
||||
silh_ratio = 0.25;
|
||||
}
|
||||
|
||||
|
||||
int CV_MHIBaseTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::TIMING_MODE && strcmp(tested_functions, "") == 0 )
|
||||
{
|
||||
start_write_param( fs );
|
||||
write_int_list( fs, "silh_ratio", motempl_silh_ratio, CV_DIM(motempl_silh_ratio) );
|
||||
write_int_list( fs, "duration", motempl_duration, CV_DIM(motempl_duration) );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIBaseTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CvArrTest::get_minmax_bounds( i, j, type, low, high );
|
||||
if( i == INPUT && CV_MAT_DEPTH(type) == CV_8U )
|
||||
{
|
||||
*low = cvScalarAll(cvRound(-1./silh_ratio)+2.);
|
||||
*high = cvScalarAll(2);
|
||||
}
|
||||
else if( i == mhi_i || i == mhi_ref_i )
|
||||
{
|
||||
*low = cvScalarAll(-exp(max_log_duration));
|
||||
*high = cvScalarAll(0.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIBaseTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[mhi_i][0] = types[mhi_ref_i][0] = CV_32FC1;
|
||||
duration = exp(cvTsRandReal(rng)*max_log_duration);
|
||||
timestamp = duration + cvTsRandReal(rng)*30.-10.;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIBaseTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[mhi_i][0] = CV_32FC1;
|
||||
duration = cvReadInt( find_timing_param( "duration" ), 500 );
|
||||
silh_ratio = cvReadInt( find_timing_param( "silh_ratio" ), 25 )*0.01;
|
||||
timestamp = duration;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIBaseTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "ratio=%d%%,duration=%dms,", cvRound(silh_ratio*100), cvRound(duration) );
|
||||
ptr += strlen(ptr);
|
||||
params_left -= 2;
|
||||
|
||||
CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}
|
||||
|
||||
|
||||
int CV_MHIBaseTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
CvMat* mat = &test_mat[mhi_i][0];
|
||||
cvTsAdd( mat, cvScalarAll(1.), 0, cvScalarAll(0.), cvScalarAll(duration), mat, 0 );
|
||||
cvTsMinMaxS( mat, 0, mat, CV_TS_MAX );
|
||||
if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE && mhi_i != mhi_ref_i )
|
||||
{
|
||||
CvMat* mat0 = &test_mat[mhi_ref_i][0];
|
||||
cvTsCopy( mat, mat0 );
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_MHIBaseTest mhi_base_test( "mhi", "" );
|
||||
|
||||
|
||||
///////////////////// update motion history ////////////////////////////
|
||||
|
||||
static void cvTsUpdateMHI( const CvMat* silh, CvMat* mhi, double timestamp, double duration )
|
||||
{
|
||||
int i, j;
|
||||
float delbound = (float)(timestamp - duration);
|
||||
for( i = 0; i < mhi->rows; i++ )
|
||||
{
|
||||
const uchar* silh_row = silh->data.ptr + i*silh->step;
|
||||
float* mhi_row = (float*)(mhi->data.ptr + i*mhi->step);
|
||||
|
||||
for( j = 0; j < mhi->cols; j++ )
|
||||
{
|
||||
if( silh_row[j] )
|
||||
mhi_row[j] = (float)timestamp;
|
||||
else if( mhi_row[j] < delbound )
|
||||
mhi_row[j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CV_UpdateMHITest : public CV_MHIBaseTest
|
||||
{
|
||||
public:
|
||||
CV_UpdateMHITest();
|
||||
|
||||
protected:
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
};
|
||||
|
||||
|
||||
CV_UpdateMHITest::CV_UpdateMHITest()
|
||||
: CV_MHIBaseTest( "mhi-update", "cvUpdateMotionHistory" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[INPUT_OUTPUT].push(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push(NULL);
|
||||
mhi_i = INPUT_OUTPUT; mhi_ref_i = REF_INPUT_OUTPUT;
|
||||
|
||||
default_timing_param_names = motempl_update_param_names;
|
||||
}
|
||||
|
||||
|
||||
double CV_UpdateMHITest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_UpdateMHITest::run_func()
|
||||
{
|
||||
cvUpdateMotionHistory( test_array[INPUT][0], test_array[INPUT_OUTPUT][0], timestamp, duration );
|
||||
}
|
||||
|
||||
|
||||
void CV_UpdateMHITest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
cvTsUpdateMHI( &test_mat[INPUT][0], &test_mat[REF_INPUT_OUTPUT][0], timestamp, duration );
|
||||
}
|
||||
|
||||
|
||||
CV_UpdateMHITest mhi_update_test;
|
||||
|
||||
|
||||
///////////////////// calc motion gradient ////////////////////////////
|
||||
|
||||
static void cvTsMHIGradient( const CvMat* mhi, CvMat* mask, CvMat* orientation,
|
||||
double delta1, double delta2, int aperture_size )
|
||||
{
|
||||
CvPoint anchor = { aperture_size/2, aperture_size/2 };
|
||||
CvMat* src = cvCreateMat( mhi->rows + aperture_size - 1, mhi->cols + aperture_size - 1, CV_32FC1 );
|
||||
CvMat* kernel = cvCreateMat( aperture_size, aperture_size, CV_32FC1 );
|
||||
CvMat* dx = cvCreateMat( mhi->rows, mhi->cols, CV_32FC1 );
|
||||
CvMat* dy = cvCreateMat( mhi->rows, mhi->cols, CV_32FC1 );
|
||||
CvMat* min_mhi = cvCreateMat( mhi->rows, mhi->cols, CV_32FC1 );
|
||||
CvMat* max_mhi = cvCreateMat( mhi->rows, mhi->cols, CV_32FC1 );
|
||||
IplConvKernel* element = cvCreateStructuringElementEx( aperture_size, aperture_size,
|
||||
aperture_size/2, aperture_size/2, CV_SHAPE_RECT );
|
||||
int i, j;
|
||||
double limit = 1e-4*aperture_size*aperture_size;
|
||||
|
||||
cvTsPrepareToFilter( mhi, src, anchor );
|
||||
cvTsCalcSobelKernel2D( 1, 0, aperture_size, 0, kernel );
|
||||
cvTsConvolve2D( src, dx, kernel, anchor );
|
||||
cvTsCalcSobelKernel2D( 0, 1, aperture_size, 0, kernel );
|
||||
cvTsConvolve2D( src, dy, kernel, anchor );
|
||||
cvReleaseMat( &kernel );
|
||||
|
||||
cvTsMinMaxFilter( src, min_mhi, element, CV_TS_MIN );
|
||||
cvTsMinMaxFilter( src, max_mhi, element, CV_TS_MAX );
|
||||
cvReleaseMat( &src );
|
||||
cvReleaseStructuringElement( &element );
|
||||
|
||||
if( delta1 > delta2 )
|
||||
{
|
||||
double t;
|
||||
CV_SWAP( delta1, delta2, t );
|
||||
}
|
||||
|
||||
for( i = 0; i < mhi->rows; i++ )
|
||||
{
|
||||
uchar* mask_row = mask->data.ptr + i*mask->step;
|
||||
float* orient_row = (float*)(orientation->data.ptr + i*orientation->step);
|
||||
const float* dx_row = (float*)(dx->data.ptr + i*dx->step);
|
||||
const float* dy_row = (float*)(dy->data.ptr + i*dy->step);
|
||||
const float* min_row = (float*)(min_mhi->data.ptr + i*min_mhi->step);
|
||||
const float* max_row = (float*)(max_mhi->data.ptr + i*max_mhi->step);
|
||||
|
||||
for( j = 0; j < mhi->cols; j++ )
|
||||
{
|
||||
double delta = max_row[j] - min_row[j];
|
||||
double _dx = dx_row[j], _dy = dy_row[j];
|
||||
|
||||
if( delta1 <= delta && delta <= delta2 &&
|
||||
(fabs(_dx) > limit || fabs(_dy) > limit) )
|
||||
{
|
||||
mask_row[j] = 1;
|
||||
double angle = atan2( _dy, _dx ) * (180/CV_PI);
|
||||
if( angle < 0 )
|
||||
angle += 360.;
|
||||
orient_row[j] = (float)angle;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_row[j] = 0;
|
||||
orient_row[j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseMat( &dx );
|
||||
cvReleaseMat( &dy );
|
||||
cvReleaseMat( &min_mhi );
|
||||
cvReleaseMat( &max_mhi );
|
||||
}
|
||||
|
||||
|
||||
class CV_MHIGradientTest : public CV_MHIBaseTest
|
||||
{
|
||||
public:
|
||||
CV_MHIGradientTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
|
||||
double delta1, delta2, delta_range_log;
|
||||
int aperture_size;
|
||||
};
|
||||
|
||||
|
||||
CV_MHIGradientTest::CV_MHIGradientTest()
|
||||
: CV_MHIBaseTest( "mhi-gradient", "cvCalcMotionGradient" )
|
||||
{
|
||||
mhi_i = mhi_ref_i = INPUT;
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
delta1 = delta2 = 0;
|
||||
aperture_size = 0;
|
||||
delta_range_log = 4;
|
||||
|
||||
default_timing_param_names = motempl_gradient_param_names;
|
||||
}
|
||||
|
||||
|
||||
int CV_MHIGradientTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::TIMING_MODE )
|
||||
{
|
||||
start_write_param( fs );
|
||||
write_int_list( fs, "aperture", motempl_gradient_aperture, CV_DIM(motempl_gradient_aperture) );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGradientTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CV_MHIBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32FC1;
|
||||
delta1 = exp(cvTsRandReal(rng)*delta_range_log + 1.);
|
||||
delta2 = exp(cvTsRandReal(rng)*delta_range_log + 1.);
|
||||
aperture_size = (cvTsRandInt(rng)%3)*2+3;
|
||||
//duration = exp(cvTsRandReal(rng)*max_log_duration);
|
||||
//timestamp = duration + cvTsRandReal(rng)*30.-10.;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGradientTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CV_MHIBaseTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
types[OUTPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][1] = CV_32FC1;
|
||||
aperture_size = cvReadInt( find_timing_param( "aperture" ), 3 );
|
||||
delta1 = duration*0.02;
|
||||
delta2 = duration*0.2;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGradientTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "aperture=%d,", aperture_size );
|
||||
ptr += strlen(ptr);
|
||||
params_left--;
|
||||
|
||||
CV_MHIBaseTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}
|
||||
|
||||
|
||||
double CV_MHIGradientTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int j )
|
||||
{
|
||||
return j == 0 ? 0 : 2e-1;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGradientTest::run_func()
|
||||
{
|
||||
cvCalcMotionGradient( test_array[INPUT][0], test_array[OUTPUT][0],
|
||||
test_array[OUTPUT][1], delta1, delta2, aperture_size );
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGradientTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
cvTsMHIGradient( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0],
|
||||
&test_mat[REF_OUTPUT][1], delta1, delta2, aperture_size );
|
||||
cvTsAdd( &test_mat[REF_OUTPUT][1], cvScalarAll(1.), 0, cvScalarAll(0.),
|
||||
cvScalarAll(1.), &test_mat[REF_OUTPUT][1], 0 );
|
||||
cvTsAdd( &test_mat[OUTPUT][1], cvScalarAll(1.), 0, cvScalarAll(0.),
|
||||
cvScalarAll(1.), &test_mat[OUTPUT][1], 0 );
|
||||
}
|
||||
|
||||
|
||||
CV_MHIGradientTest mhi_gradient_test;
|
||||
|
||||
|
||||
////////////////////// calc global orientation /////////////////////////
|
||||
|
||||
static double
|
||||
cvTsCalcGlobalOrientation( const CvMat* orient, const CvMat* mask, const CvMat* mhi,
|
||||
double timestamp, double duration )
|
||||
{
|
||||
const int HIST_SIZE = 12;
|
||||
int y, x;
|
||||
int histogram[HIST_SIZE];
|
||||
int max_bin = 0;
|
||||
|
||||
double base_orientation = 0, delta_orientation = 0, weight = 0;
|
||||
double low_time, global_orientation;
|
||||
|
||||
memset( histogram, 0, sizeof( histogram ));
|
||||
timestamp = 0;
|
||||
|
||||
for( y = 0; y < orient->rows; y++ )
|
||||
{
|
||||
const float* orient_data = (const float*)(orient->data.ptr + y*orient->step);
|
||||
const uchar* mask_data = mask->data.ptr + y*mask->step;
|
||||
const float* mhi_data = (const float*)(mhi->data.ptr + y*mhi->step);
|
||||
for( x = 0; x < orient->cols; x++ )
|
||||
if( mask_data[x] )
|
||||
{
|
||||
int bin = cvFloor( (orient_data[x]*HIST_SIZE)/360 );
|
||||
histogram[bin < 0 ? 0 : bin >= HIST_SIZE ? HIST_SIZE-1 : bin]++;
|
||||
if( mhi_data[x] > timestamp )
|
||||
timestamp = mhi_data[x];
|
||||
}
|
||||
}
|
||||
|
||||
low_time = timestamp - duration;
|
||||
|
||||
for( x = 1; x < HIST_SIZE; x++ )
|
||||
{
|
||||
if( histogram[x] > histogram[max_bin] )
|
||||
max_bin = x;
|
||||
}
|
||||
|
||||
base_orientation = ((double)max_bin*360)/HIST_SIZE;
|
||||
|
||||
for( y = 0; y < orient->rows; y++ )
|
||||
{
|
||||
const float* orient_data = (const float*)(orient->data.ptr + y*orient->step);
|
||||
const float* mhi_data = (const float*)(mhi->data.ptr + y*mhi->step);
|
||||
const uchar* mask_data = mask->data.ptr + y*mask->step;
|
||||
|
||||
for( x = 0; x < orient->cols; x++ )
|
||||
{
|
||||
if( mask_data[x] && mhi_data[x] > low_time )
|
||||
{
|
||||
double diff = orient_data[x] - base_orientation;
|
||||
double delta_weight = (((mhi_data[x] - low_time)/duration)*254 + 1)/255;
|
||||
|
||||
if( diff < -180 ) diff += 360;
|
||||
if( diff > 180 ) diff -= 360;
|
||||
|
||||
if( delta_weight > 0 && fabs(diff) < 45 )
|
||||
{
|
||||
delta_orientation += diff*delta_weight;
|
||||
weight += delta_weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( weight == 0 )
|
||||
global_orientation = base_orientation;
|
||||
else
|
||||
{
|
||||
global_orientation = base_orientation + delta_orientation/weight;
|
||||
if( global_orientation < 0 ) global_orientation += 360;
|
||||
if( global_orientation > 360 ) global_orientation -= 360;
|
||||
}
|
||||
|
||||
return global_orientation;
|
||||
}
|
||||
|
||||
|
||||
class CV_MHIGlobalOrientTest : public CV_MHIBaseTest
|
||||
{
|
||||
public:
|
||||
CV_MHIGlobalOrientTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void run_func();
|
||||
double angle, min_angle, max_angle;
|
||||
};
|
||||
|
||||
|
||||
CV_MHIGlobalOrientTest::CV_MHIGlobalOrientTest()
|
||||
: CV_MHIBaseTest( "mhi-global", "cvCalcGlobalOrientation" )
|
||||
{
|
||||
mhi_i = mhi_ref_i = INPUT;
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[INPUT].push(NULL);
|
||||
min_angle = max_angle = 0;
|
||||
|
||||
default_timing_param_names = motempl_global_param_names;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGlobalOrientTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CV_MHIBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
CvSize size = sizes[INPUT][0];
|
||||
|
||||
size.width = MAX( size.width, 16 );
|
||||
size.height = MAX( size.height, 16 );
|
||||
sizes[INPUT][0] = sizes[INPUT][1] = sizes[INPUT][2] = size;
|
||||
|
||||
types[INPUT][1] = CV_8UC1; // mask
|
||||
types[INPUT][2] = CV_32FC1; // orientation
|
||||
|
||||
min_angle = cvTsRandReal(rng)*359.9;
|
||||
max_angle = cvTsRandReal(rng)*359.9;
|
||||
if( min_angle >= max_angle )
|
||||
{
|
||||
double t;
|
||||
CV_SWAP( min_angle, max_angle, t );
|
||||
}
|
||||
max_angle += 0.1;
|
||||
duration = exp(cvTsRandReal(rng)*max_log_duration);
|
||||
timestamp = duration + cvTsRandReal(rng)*30.-10.;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGlobalOrientTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CV_MHIBaseTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
types[INPUT][1] = CV_8UC1;
|
||||
types[INPUT][2] = CV_32FC1;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGlobalOrientTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CV_MHIBaseTest::get_minmax_bounds( i, j, type, low, high );
|
||||
if( i == INPUT && j == 2 )
|
||||
{
|
||||
*low = cvScalarAll(min_angle);
|
||||
*high = cvScalarAll(max_angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double CV_MHIGlobalOrientTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
|
||||
void CV_MHIGlobalOrientTest::run_func()
|
||||
{
|
||||
angle = cvCalcGlobalOrientation( test_array[INPUT][2], test_array[INPUT][1],
|
||||
test_array[INPUT][0], timestamp, duration );
|
||||
}
|
||||
|
||||
|
||||
int CV_MHIGlobalOrientTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
//printf("%d. rows=%d, cols=%d, nzmask=%d\n", test_case_idx, test_mat[INPUT][1].rows, test_mat[INPUT][1].cols,
|
||||
// cvCountNonZero(test_array[INPUT][1]));
|
||||
|
||||
double ref_angle = cvTsCalcGlobalOrientation( &test_mat[INPUT][2], &test_mat[INPUT][1],
|
||||
&test_mat[INPUT][0], timestamp, duration );
|
||||
double err_level = get_success_error_level( test_case_idx, 0, 0 );
|
||||
int code = CvTS::OK;
|
||||
int nz = cvCountNonZero( test_array[INPUT][1] );
|
||||
|
||||
if( nz > 32 && !(min_angle - err_level <= angle &&
|
||||
max_angle + err_level >= angle) &&
|
||||
!(min_angle - err_level <= angle+360 &&
|
||||
max_angle + err_level >= angle+360) )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The angle=%g is outside (%g,%g) range\n",
|
||||
angle, min_angle - err_level, max_angle + err_level );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
else if( fabs(angle - ref_angle) > err_level &&
|
||||
fabs(360 - fabs(angle - ref_angle)) > err_level )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The angle=%g differs too much from reference value=%g\n",
|
||||
angle, ref_angle );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
CV_MHIGlobalOrientTest mhi_global_orient_test;
|
||||
|
||||
@@ -1,314 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#define PUSHC(Y,X) { CurStack[CStIn].y=Y; \
|
||||
CurStack[CStIn].x=X; \
|
||||
CStIn++;}
|
||||
#define PUSHN(Y,X) { NextStack[NStIn].y=Y; \
|
||||
NextStack[NStIn].x=X; \
|
||||
NStIn++;}
|
||||
|
||||
#define POP(Y,X) { CStIn--; \
|
||||
Y=CurStack[CStIn].y; \
|
||||
X=CurStack[CStIn].x;}
|
||||
|
||||
void testFill( float* img,
|
||||
int step,
|
||||
CvSize imgSize,
|
||||
CvPoint seed_point,
|
||||
float nv,
|
||||
float* RP,
|
||||
int itsstep,
|
||||
float SegThresh,
|
||||
CvConnectedComp* region)
|
||||
{
|
||||
CvPoint* CurStack = (CvPoint*)cvAlloc(imgSize.height*imgSize.width*sizeof(CvPoint));
|
||||
CvPoint* NextStack = (CvPoint*)cvAlloc(imgSize.height*imgSize.width*sizeof(CvPoint));
|
||||
CvPoint* Temp;
|
||||
int ownstep=step/4;
|
||||
int RPstep=itsstep/4;
|
||||
float thr = -SegThresh;
|
||||
float nthr = thr*2;
|
||||
int CStIn=0;
|
||||
int NStIn=0;
|
||||
int TempIn;
|
||||
int x,y;
|
||||
int XMax=0;
|
||||
int YMax=0;
|
||||
int XMin = imgSize.width;
|
||||
int YMin = imgSize.height;
|
||||
int Sum=0;
|
||||
|
||||
PUSHC(seed_point.y,seed_point.x);
|
||||
again:
|
||||
while(CStIn)
|
||||
{
|
||||
POP(y,x);
|
||||
XMax = MAX(XMax,x);
|
||||
YMax = MAX(YMax,y);
|
||||
XMin = MIN(XMin,x);
|
||||
YMin = MIN(YMin,y);
|
||||
if((y>0)&&(!RP[(y-1)*RPstep+x])&&
|
||||
(((img[(y-1)*ownstep+x]-img[y*ownstep+x])<0)&&
|
||||
((img[(y-1)*ownstep+x]-img[y*ownstep+x])>=thr)))PUSHC(y-1,x);
|
||||
if((y>0)&&(!RP[(y-1)*RPstep+x])&&
|
||||
(((img[(y-1)*ownstep+x]-img[y*ownstep+x])<=thr)&&
|
||||
((img[(y-1)*ownstep+x]-img[y*ownstep+x])>=nthr)))PUSHN(y-1,x);
|
||||
if((y<imgSize.height-1)&&(!RP[(y+1)*RPstep+x])&&
|
||||
(((img[(y+1)*ownstep+x]-img[y*ownstep+x])<=0)&&
|
||||
((img[(y+1)*ownstep+x]-img[y*ownstep+x])>=thr)))PUSHC(y+1,x);
|
||||
if((y<imgSize.height-1)&&(!RP[(y+1)*RPstep+x])&&
|
||||
(((img[(y+1)*ownstep+x]-img[y*ownstep+x])<=thr)&&
|
||||
((img[(y+1)*ownstep+x]-img[y*ownstep+x])>=nthr)))PUSHN(y+1,x);
|
||||
if((x>0)&&(!RP[y*RPstep+x-1])&&
|
||||
(((img[y*ownstep+x-1]-img[y*ownstep+x])<=0)&&
|
||||
((img[y*ownstep+x-1]-img[y*ownstep+x])>=thr)))PUSHC(y,x-1);
|
||||
if((x>0)&&(!RP[y*RPstep+x-1])&&
|
||||
(((img[y*ownstep+x-1]-img[y*ownstep+x])<=thr)&&
|
||||
((img[y*ownstep+x-1]-img[y*ownstep+x])>=nthr)))PUSHN(y,x-1);
|
||||
if((x<imgSize.width-1)&&(!RP[y*RPstep+x+1])&&
|
||||
(((img[y*ownstep+x+1]-img[y*ownstep+x])<=0)&&
|
||||
((img[y*ownstep+x+1]-img[y*ownstep+x])>=thr)))PUSHC(y,x+1);
|
||||
if((x<imgSize.width-1)&&(!RP[y*RPstep+x+1])&&
|
||||
(((img[y*ownstep+x+1]-img[y*ownstep+x])<=thr)&&
|
||||
((img[y*ownstep+x+1]-img[y*ownstep+x])>=nthr)))PUSHN(y,x+1);
|
||||
Sum++;
|
||||
RP[y*RPstep+x]=nv;
|
||||
img[y*ownstep+x] = -255;
|
||||
}
|
||||
if(NStIn)
|
||||
{
|
||||
Temp=CurStack;
|
||||
CurStack=NextStack;
|
||||
NextStack=Temp;
|
||||
TempIn=CStIn;
|
||||
CStIn=NStIn;
|
||||
NStIn=TempIn;
|
||||
goto again;
|
||||
}
|
||||
region->area = Sum;
|
||||
region->rect.x = XMin;
|
||||
region->rect.y = YMin;
|
||||
region->rect.width = XMax - XMin + 1;
|
||||
region->rect.height = YMax - YMin + 1;
|
||||
region->value = cvScalar(nv);
|
||||
cvFree(&CurStack);
|
||||
cvFree(&NextStack);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Testing parameters */
|
||||
static char TestName[] = "Checking MotionSegmentation";
|
||||
static char TestClass[] = "Algorithm";
|
||||
static int lImageWidth;
|
||||
static int lImageHeight;
|
||||
|
||||
static int read_param = 0;
|
||||
static int data_types = 0;
|
||||
static float thresh = 0;
|
||||
static double EPSILON = 3;
|
||||
|
||||
|
||||
static int fcaMotSeg( void )
|
||||
{
|
||||
int step;
|
||||
float* src;
|
||||
AtsRandState state;
|
||||
double Error = 0;
|
||||
int color = 1;
|
||||
CvSize roi;
|
||||
|
||||
IplImage* mhi;
|
||||
IplImage* mask32f;
|
||||
IplImage* test32f;
|
||||
CvSeq* seq1 = NULL;
|
||||
CvSeq* seq2 = NULL;
|
||||
CvMemStorage* storage;
|
||||
CvSeqWriter writer;
|
||||
|
||||
CvConnectedComp ConComp;
|
||||
|
||||
storage = cvCreateMemStorage( 0 );
|
||||
cvClearMemStorage( storage );
|
||||
|
||||
/* Initialization global parameters */
|
||||
if( !read_param )
|
||||
{
|
||||
read_param = 1;
|
||||
/* Determining which test are needed to run */
|
||||
trsCaseRead( &data_types,"/u/s/f/a", "a",
|
||||
"u - unsigned char, s - signed char, f - float, a - all" );
|
||||
/* Reading test-parameters */
|
||||
trsiRead( &lImageHeight, "20", "Image height" );
|
||||
trsiRead( &lImageWidth, "20", "Image width" );
|
||||
trssRead( &thresh, "10", "Segmentation Threshold" );
|
||||
}
|
||||
if( data_types != 3 && data_types != 0 ) return TRS_UNDEF;
|
||||
|
||||
/* Creating images for testing */
|
||||
mhi = cvCreateImage(cvSize(lImageWidth, lImageHeight), IPL_DEPTH_32F, 1);
|
||||
mask32f = cvCreateImage(cvSize(lImageWidth, lImageHeight), IPL_DEPTH_32F, 1);
|
||||
test32f = cvCreateImage(cvSize(lImageWidth, lImageHeight), IPL_DEPTH_32F, 1);
|
||||
|
||||
atsRandInit(&state,40,100,60);
|
||||
atsFillRandomImageEx(mhi, &state );
|
||||
src = (float*)mhi->imageData;
|
||||
step = mhi->widthStep/4;
|
||||
int i;
|
||||
for(i=0; i<lImageHeight;i++)
|
||||
{
|
||||
for(int j=0; j<lImageWidth;j++)
|
||||
{
|
||||
if(src[i*step+j]>80)src[i*step+j]=80;
|
||||
}
|
||||
}
|
||||
cvZero(test32f);
|
||||
seq1 = cvSegmentMotion(mhi,mask32f,storage,80,thresh);
|
||||
cvStartWriteSeq( 0, sizeof( CvSeq ), sizeof( CvConnectedComp ), storage, &writer );
|
||||
roi.width = lImageWidth;
|
||||
roi.height = lImageHeight;
|
||||
for(i=1;i<lImageHeight-1;i++)
|
||||
{
|
||||
for(int j=1;j<lImageWidth-1;j++)
|
||||
{
|
||||
if(src[i*step+j]==80)
|
||||
{
|
||||
if((src[(i-1)*step+j]>=(80-thresh))&&(src[(i-1)*step+j]<80))
|
||||
{
|
||||
CvPoint MinPoint;
|
||||
MinPoint.x=j;
|
||||
MinPoint.y=i-1;
|
||||
testFill(src,
|
||||
step*4,
|
||||
roi,
|
||||
MinPoint,
|
||||
(float)color,
|
||||
(float*)test32f->imageData,
|
||||
test32f->widthStep,
|
||||
thresh,
|
||||
&ConComp);
|
||||
ConComp.value = cvScalar(color);
|
||||
CV_WRITE_SEQ_ELEM( ConComp, writer );
|
||||
color+=1;
|
||||
}
|
||||
|
||||
if((src[i*step+j-1]>=(80-thresh))&&(src[i*step+j-1]<80))
|
||||
{
|
||||
CvPoint MinPoint;
|
||||
MinPoint.x=j-1;
|
||||
MinPoint.y=i;
|
||||
testFill(src,
|
||||
step*4,
|
||||
roi,
|
||||
MinPoint,
|
||||
(float)color,
|
||||
(float*)test32f->imageData,
|
||||
test32f->widthStep,
|
||||
thresh,
|
||||
&ConComp);
|
||||
ConComp.value = cvScalar(color);
|
||||
CV_WRITE_SEQ_ELEM( ConComp, writer );
|
||||
color+=1;
|
||||
}
|
||||
if((src[i*step+j+1]>=(80-thresh))&&(src[i*step+j+1]<80))
|
||||
{
|
||||
CvPoint MinPoint;
|
||||
MinPoint.x=j+1;
|
||||
MinPoint.y=i;
|
||||
testFill(src,
|
||||
step*4,
|
||||
roi,
|
||||
MinPoint,
|
||||
(float)color,
|
||||
(float*)test32f->imageData,
|
||||
test32f->widthStep,
|
||||
thresh,
|
||||
&ConComp);
|
||||
ConComp.value = cvScalar(color);
|
||||
CV_WRITE_SEQ_ELEM( ConComp, writer );
|
||||
color+=1;
|
||||
}
|
||||
if((src[(i+1)*step+j]>=(80-thresh))&&(src[(i+1)*step+j]<80))
|
||||
{
|
||||
CvPoint MinPoint;
|
||||
MinPoint.x=j;
|
||||
MinPoint.y=i+1;
|
||||
testFill(src,
|
||||
step*4,
|
||||
roi,
|
||||
MinPoint,
|
||||
(float)color,
|
||||
(float*)test32f->imageData,
|
||||
test32f->widthStep,
|
||||
thresh,
|
||||
&ConComp);
|
||||
ConComp.value = cvScalar(color);
|
||||
CV_WRITE_SEQ_ELEM( ConComp, writer );
|
||||
color+=1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
seq2 = cvEndWriteSeq( &writer );
|
||||
Error += cvNorm(test32f,mask32f,CV_C);
|
||||
cvReleaseMemStorage(&storage);
|
||||
cvReleaseImage(&mhi);
|
||||
cvReleaseImage(&test32f);
|
||||
cvReleaseImage(&mask32f);
|
||||
/* Free Memory */
|
||||
|
||||
if(Error>=EPSILON)return TRS_FAIL;
|
||||
return TRS_OK;
|
||||
} /* fcaSobel8uC1R */
|
||||
|
||||
void InitAMotSeg(void)
|
||||
{
|
||||
trsReg( "cvMotSeg", TestName, TestClass, fcaMotSeg);
|
||||
} /* InitASobel */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,201 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class CV_MserTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_MserTest();
|
||||
protected:
|
||||
void run(int);
|
||||
int LoadBoxes(const char* path, vector<CvBox2D>& boxes);
|
||||
int SaveBoxes(const char* path, const vector<CvBox2D>& boxes);
|
||||
int CompareBoxes(const vector<CvBox2D>& boxes1,const vector<CvBox2D>& boxes2, float max_rel_diff = 0.01f);
|
||||
};
|
||||
|
||||
CV_MserTest::CV_MserTest() : CvTest("MSER","cvExtractMSER")
|
||||
{
|
||||
}
|
||||
|
||||
int CV_MserTest::LoadBoxes(const char* path, vector<CvBox2D>& boxes)
|
||||
{
|
||||
boxes.clear();
|
||||
FILE* f = fopen(path,"r");
|
||||
|
||||
if (f==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!feof(f))
|
||||
{
|
||||
CvBox2D box;
|
||||
fscanf(f,"%f,%f,%f,%f,%f\n",&box.angle,&box.center.x,&box.center.y,&box.size.width,&box.size.height);
|
||||
boxes.push_back(box);
|
||||
}
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CV_MserTest::SaveBoxes(const char* path, const vector<CvBox2D>& boxes)
|
||||
{
|
||||
FILE* f = fopen(path,"w");
|
||||
if (f==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for (int i=0;i<(int)boxes.size();i++)
|
||||
{
|
||||
fprintf(f,"%f,%f,%f,%f,%f\n",boxes[i].angle,boxes[i].center.x,boxes[i].center.y,boxes[i].size.width,boxes[i].size.height);
|
||||
}
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CV_MserTest::CompareBoxes(const vector<CvBox2D>& boxes1,const vector<CvBox2D>& boxes2, float max_rel_diff)
|
||||
{
|
||||
if (boxes1.size() != boxes2.size())
|
||||
return 0;
|
||||
|
||||
for (int i=0; i<(int)boxes1.size();i++)
|
||||
{
|
||||
float rel_diff;
|
||||
if (!((boxes1[i].angle == 0.0f) && (abs(boxes2[i].angle) < max_rel_diff)))
|
||||
{
|
||||
rel_diff = abs(boxes1[i].angle-boxes2[i].angle)/abs(boxes1[i].angle);
|
||||
if (rel_diff > max_rel_diff)
|
||||
return i;
|
||||
}
|
||||
|
||||
if (!((boxes1[i].center.x == 0.0f) && (abs(boxes2[i].center.x) < max_rel_diff)))
|
||||
{
|
||||
rel_diff = abs(boxes1[i].center.x-boxes2[i].center.x)/abs(boxes1[i].center.x);
|
||||
if (rel_diff > max_rel_diff)
|
||||
return i;
|
||||
}
|
||||
|
||||
if (!((boxes1[i].center.y == 0.0f) && (abs(boxes2[i].center.y) < max_rel_diff)))
|
||||
{
|
||||
rel_diff = abs(boxes1[i].center.y-boxes2[i].center.y)/abs(boxes1[i].center.y);
|
||||
if (rel_diff > max_rel_diff)
|
||||
return i;
|
||||
}
|
||||
if (!((boxes1[i].size.width == 0.0f) && (abs(boxes2[i].size.width) < max_rel_diff)))
|
||||
{
|
||||
rel_diff = abs(boxes1[i].size.width-boxes2[i].size.width)/abs(boxes1[i].size.width);
|
||||
if (rel_diff > max_rel_diff)
|
||||
return i;
|
||||
}
|
||||
|
||||
if (!((boxes1[i].size.height == 0.0f) && (abs(boxes2[i].size.height) < max_rel_diff)))
|
||||
{
|
||||
rel_diff = abs(boxes1[i].size.height-boxes2[i].size.height)/abs(boxes1[i].size.height);
|
||||
if (rel_diff > max_rel_diff)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CV_MserTest::run(int)
|
||||
{
|
||||
string image_path = string(ts->get_data_path()) + "mser/puzzle.png";
|
||||
|
||||
IplImage* img = cvLoadImage( image_path.c_str());
|
||||
if (!img)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Unable to open image mser/puzzle.png\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
CvSeq* contours;
|
||||
CvMemStorage* storage= cvCreateMemStorage();
|
||||
IplImage* hsv = cvCreateImage( cvGetSize( img ), IPL_DEPTH_8U, 3 );
|
||||
cvCvtColor( img, hsv, CV_BGR2YCrCb );
|
||||
CvMSERParams params = cvMSERParams();//cvMSERParams( 5, 60, cvRound(.2*img->width*img->height), .25, .2 );
|
||||
cvExtractMSER( hsv, NULL, &contours, storage, params );
|
||||
|
||||
vector<CvBox2D> boxes;
|
||||
vector<CvBox2D> boxes_orig;
|
||||
for ( int i = 0; i < contours->total; i++ )
|
||||
{
|
||||
CvContour* r = *(CvContour**)cvGetSeqElem( contours, i );
|
||||
CvBox2D box = cvFitEllipse2( r );
|
||||
box.angle=(float)CV_PI/2-box.angle;
|
||||
boxes.push_back(box);
|
||||
}
|
||||
|
||||
string boxes_path = string(ts->get_data_path()) + "mser/boxes.txt";
|
||||
|
||||
if (!LoadBoxes(boxes_path.c_str(),boxes_orig))
|
||||
{
|
||||
SaveBoxes(boxes_path.c_str(),boxes);
|
||||
ts->printf( CvTS::LOG, "Unable to open data file mser/boxes.txt\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
const float dissimularity = 0.01f;
|
||||
int n_box = CompareBoxes(boxes_orig,boxes,dissimularity);
|
||||
if (n_box < 0)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( CvTS::LOG, "Incorrect correspondence in %d box\n",n_box);
|
||||
}
|
||||
|
||||
cvReleaseMemStorage(&storage);
|
||||
cvReleaseImage(&hsv);
|
||||
cvReleaseImage(&img);
|
||||
}
|
||||
|
||||
CV_MserTest mser_test;
|
||||
@@ -1,526 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::flann;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class NearestNeighborTest : public CvTest
|
||||
{
|
||||
public:
|
||||
NearestNeighborTest( const char* test_name, const char* test_funcs )
|
||||
: CvTest( test_name, test_funcs ) {}
|
||||
protected:
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 1;
|
||||
static const int dims = 30;
|
||||
static const int featuresCount = 2000;
|
||||
static const int K = 1; // * should also test 2nd nn etc.?
|
||||
|
||||
|
||||
virtual void run( int start_from );
|
||||
virtual void createModel( const Mat& data ) = 0;
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) = 0;
|
||||
virtual int checkGetPoins( const Mat& data );
|
||||
virtual int checkFindBoxed();
|
||||
virtual int checkFind( const Mat& data );
|
||||
virtual void releaseModel() = 0;
|
||||
};
|
||||
|
||||
int NearestNeighborTest::checkGetPoins( const Mat& )
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int NearestNeighborTest::checkFindBoxed()
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int NearestNeighborTest::checkFind( const Mat& data )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
int pointsCount = 1000;
|
||||
float noise = 0.2f;
|
||||
|
||||
RNG rng;
|
||||
Mat points( pointsCount, dims, CV_32FC1 );
|
||||
Mat results( pointsCount, K, CV_32SC1 );
|
||||
|
||||
std::vector<int> fmap( pointsCount );
|
||||
for( int pi = 0; pi < pointsCount; pi++ )
|
||||
{
|
||||
int fi = rng.next() % featuresCount;
|
||||
fmap[pi] = fi;
|
||||
for( int d = 0; d < dims; d++ )
|
||||
points.at<float>(pi, d) = data.at<float>(fi, d) + rng.uniform(0.0f, 1.0f) * noise;
|
||||
}
|
||||
|
||||
code = findNeighbors( points, results );
|
||||
|
||||
if( code == CvTS::OK )
|
||||
{
|
||||
int correctMatches = 0;
|
||||
for( int pi = 0; pi < pointsCount; pi++ )
|
||||
{
|
||||
if( fmap[pi] == results.at<int>(pi, 0) )
|
||||
correctMatches++;
|
||||
}
|
||||
|
||||
double correctPerc = correctMatches / (double)pointsCount;
|
||||
if (correctPerc < .75)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "correct_perc = %d\n", correctPerc );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void NearestNeighborTest::run( int /*start_from*/ ) {
|
||||
int code = CvTS::OK, tempCode;
|
||||
Mat desc( featuresCount, dims, CV_32FC1 );
|
||||
randu( desc, Scalar(minValue), Scalar(maxValue) );
|
||||
|
||||
createModel( desc );
|
||||
|
||||
tempCode = checkGetPoins( desc );
|
||||
if( tempCode != CvTS::OK )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of GetPoints \n" );
|
||||
code = tempCode;
|
||||
}
|
||||
|
||||
tempCode = checkFindBoxed();
|
||||
if( tempCode != CvTS::OK )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of FindBoxed \n" );
|
||||
code = tempCode;
|
||||
}
|
||||
|
||||
tempCode = checkFind( desc );
|
||||
if( tempCode != CvTS::OK )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of Find \n" );
|
||||
code = tempCode;
|
||||
}
|
||||
|
||||
releaseModel();
|
||||
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class CV_LSHTest : public NearestNeighborTest
|
||||
{
|
||||
public:
|
||||
CV_LSHTest() : NearestNeighborTest( "lsh", "cvLSHQuery" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data );
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors );
|
||||
virtual void releaseModel();
|
||||
struct CvLSH* lsh;
|
||||
CvMat desc;
|
||||
};
|
||||
|
||||
void CV_LSHTest::createModel( const Mat& data )
|
||||
{
|
||||
desc = data;
|
||||
lsh = cvCreateMemoryLSH( data.cols, data.rows, 70, 20, CV_32FC1 );
|
||||
cvLSHAdd( lsh, &desc );
|
||||
}
|
||||
|
||||
int CV_LSHTest::findNeighbors( Mat& points, Mat& neighbors )
|
||||
{
|
||||
const int emax = 20;
|
||||
Mat dist( points.rows, neighbors.cols, CV_64FC1);
|
||||
CvMat _dist = dist, _points = points, _neighbors = neighbors;
|
||||
cvLSHQuery( lsh, &_points, &_neighbors, &_dist, neighbors.cols, emax );
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_LSHTest::releaseModel()
|
||||
{
|
||||
cvReleaseLSH( &lsh );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class CV_FeatureTreeTest_C : public NearestNeighborTest
|
||||
{
|
||||
public:
|
||||
CV_FeatureTreeTest_C( const char* test_name, const char* test_funcs )
|
||||
: NearestNeighborTest( test_name, test_funcs ) {}
|
||||
protected:
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors );
|
||||
virtual void releaseModel();
|
||||
CvFeatureTree* tr;
|
||||
CvMat desc;
|
||||
};
|
||||
|
||||
int CV_FeatureTreeTest_C::findNeighbors( Mat& points, Mat& neighbors )
|
||||
{
|
||||
const int emax = 20;
|
||||
Mat dist( points.rows, neighbors.cols, CV_64FC1);
|
||||
CvMat _dist = dist, _points = points, _neighbors = neighbors;
|
||||
cvFindFeatures( tr, &_points, &_neighbors, &_dist, neighbors.cols, emax );
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_FeatureTreeTest_C::releaseModel()
|
||||
{
|
||||
cvReleaseFeatureTree( tr );
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
class CV_SpillTreeTest_C : public CV_FeatureTreeTest_C
|
||||
{
|
||||
public:
|
||||
CV_SpillTreeTest_C(): CV_FeatureTreeTest_C( "spilltree_c", "cvFindFeatures-spill" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data );
|
||||
};
|
||||
|
||||
void CV_SpillTreeTest_C::createModel( const Mat& data )
|
||||
{
|
||||
desc = data;
|
||||
tr = cvCreateSpillTree( &desc );
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
class CV_KDTreeTest_C : public CV_FeatureTreeTest_C
|
||||
{
|
||||
public:
|
||||
CV_KDTreeTest_C(): CV_FeatureTreeTest_C( "kdtree_c", "cvFindFeatures-kd" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data );
|
||||
virtual int checkFindBoxed();
|
||||
};
|
||||
|
||||
void CV_KDTreeTest_C::createModel( const Mat& data )
|
||||
{
|
||||
desc = data;
|
||||
tr = cvCreateKDTree( &desc );
|
||||
}
|
||||
|
||||
int CV_KDTreeTest_C::checkFindBoxed()
|
||||
{
|
||||
Mat min(1, dims, CV_32FC1 ), max(1, dims, CV_32FC1 ), indices( 1, 1, CV_32SC1 );
|
||||
float l = minValue, r = maxValue;
|
||||
min.setTo(Scalar(l)), max.setTo(Scalar(r));
|
||||
CvMat _min = min, _max = max, _indices = indices;
|
||||
// TODO check indices
|
||||
if( cvFindFeaturesBoxed( tr, &_min, &_max, &_indices ) != featuresCount )
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class CV_KDTreeTest_CPP : public NearestNeighborTest
|
||||
{
|
||||
public:
|
||||
CV_KDTreeTest_CPP() : NearestNeighborTest( "kdtree_cpp", "cv::KDTree funcs" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data );
|
||||
virtual int checkGetPoins( const Mat& data );
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors );
|
||||
virtual int checkFindBoxed();
|
||||
virtual void releaseModel();
|
||||
KDTree* tr;
|
||||
};
|
||||
|
||||
|
||||
void CV_KDTreeTest_CPP::createModel( const Mat& data )
|
||||
{
|
||||
tr = new KDTree( data, false );
|
||||
}
|
||||
|
||||
int CV_KDTreeTest_CPP::checkGetPoins( const Mat& data )
|
||||
{
|
||||
Mat res1( data.size(), data.type() ),
|
||||
res2( data.size(), data.type() ),
|
||||
res3( data.size(), data.type() );
|
||||
Mat idxs( 1, data.rows, CV_32SC1 );
|
||||
for( int pi = 0; pi < data.rows; pi++ )
|
||||
{
|
||||
idxs.at<int>(0, pi) = pi;
|
||||
// 1st way
|
||||
const float* point = tr->getPoint(pi);
|
||||
for( int di = 0; di < data.cols; di++ )
|
||||
res1.at<float>(pi, di) = point[di];
|
||||
}
|
||||
// 2nd way
|
||||
tr->getPoints( idxs.ptr<int>(0), data.rows, res2 );
|
||||
|
||||
// 3d way
|
||||
tr->getPoints( idxs, res3 );
|
||||
|
||||
if( norm( res1, data, NORM_L1) != 0 ||
|
||||
norm( res2, data, NORM_L1) != 0 ||
|
||||
norm( res3, data, NORM_L1) != 0)
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int CV_KDTreeTest_CPP::checkFindBoxed()
|
||||
{
|
||||
vector<float> min( dims, minValue), max(dims, maxValue);
|
||||
vector<int> indices;
|
||||
tr->findOrthoRange( &min[0], &max[0], &indices );
|
||||
// TODO check indices
|
||||
if( (int)indices.size() != featuresCount)
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int CV_KDTreeTest_CPP::findNeighbors( Mat& points, Mat& neighbors )
|
||||
{
|
||||
const int emax = 20;
|
||||
Mat neighbors2( neighbors.size(), CV_32SC1 );
|
||||
int j;
|
||||
vector<float> min(points.cols, minValue);
|
||||
vector<float> max(points.cols, maxValue);
|
||||
for( int pi = 0; pi < points.rows; pi++ )
|
||||
{
|
||||
// 1st way
|
||||
tr->findNearest( points.ptr<float>(pi), neighbors.cols, emax, neighbors.ptr<int>(pi) );
|
||||
|
||||
// 2nd way
|
||||
vector<int> neighborsIdx2( neighbors2.cols, 0 );
|
||||
tr->findNearest( points.ptr<float>(pi), neighbors2.cols, emax, &neighborsIdx2 );
|
||||
vector<int>::const_iterator it2 = neighborsIdx2.begin();
|
||||
for( j = 0; it2 != neighborsIdx2.end(); ++it2, j++ )
|
||||
neighbors2.at<int>(pi,j) = *it2;
|
||||
}
|
||||
|
||||
// compare results
|
||||
if( norm( neighbors, neighbors2, NORM_L1 ) != 0 )
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_KDTreeTest_CPP::releaseModel()
|
||||
{
|
||||
delete tr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
class CV_FlannTest : public NearestNeighborTest
|
||||
{
|
||||
public:
|
||||
CV_FlannTest( const char* test_name, const char* test_funcs )
|
||||
: NearestNeighborTest( test_name, test_funcs ) {}
|
||||
protected:
|
||||
void createIndex( const Mat& data, const IndexParams& params );
|
||||
int knnSearch( Mat& points, Mat& neighbors );
|
||||
int radiusSearch( Mat& points, Mat& neighbors );
|
||||
virtual void releaseModel();
|
||||
Index* index;
|
||||
};
|
||||
|
||||
void CV_FlannTest::createIndex( const Mat& data, const IndexParams& params )
|
||||
{
|
||||
index = new Index( data, params );
|
||||
}
|
||||
|
||||
int CV_FlannTest::knnSearch( Mat& points, Mat& neighbors )
|
||||
{
|
||||
Mat dist( points.rows, neighbors.cols, CV_32FC1);
|
||||
int knn = 1, j;
|
||||
|
||||
// 1st way
|
||||
index->knnSearch( points, neighbors, dist, knn, SearchParams() );
|
||||
|
||||
// 2nd way
|
||||
Mat neighbors1( neighbors.size(), CV_32SC1 );
|
||||
for( int i = 0; i < points.rows; i++ )
|
||||
{
|
||||
float* fltPtr = points.ptr<float>(i);
|
||||
vector<float> query( fltPtr, fltPtr + points.cols );
|
||||
vector<int> indices( neighbors1.cols, 0 );
|
||||
vector<float> dists( dist.cols, 0 );
|
||||
index->knnSearch( query, indices, dists, knn, SearchParams() );
|
||||
vector<int>::const_iterator it = indices.begin();
|
||||
for( j = 0; it != indices.end(); ++it, j++ )
|
||||
neighbors1.at<int>(i,j) = *it;
|
||||
}
|
||||
|
||||
// compare results
|
||||
if( norm( neighbors, neighbors1, NORM_L1 ) != 0 )
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int CV_FlannTest::radiusSearch( Mat& points, Mat& neighbors )
|
||||
{
|
||||
Mat dist( 1, neighbors.cols, CV_32FC1);
|
||||
Mat neighbors1( neighbors.size(), CV_32SC1 );
|
||||
float radius = 10.0f;
|
||||
int j;
|
||||
|
||||
// radiusSearch can only search one feature at a time for range search
|
||||
for( int i = 0; i < points.rows; i++ )
|
||||
{
|
||||
// 1st way
|
||||
Mat p( 1, points.cols, CV_32FC1, points.ptr<float>(i) ),
|
||||
n( 1, neighbors.cols, CV_32SC1, neighbors.ptr<int>(i) );
|
||||
index->radiusSearch( p, n, dist, radius, SearchParams() );
|
||||
|
||||
// 2nd way
|
||||
float* fltPtr = points.ptr<float>(i);
|
||||
vector<float> query( fltPtr, fltPtr + points.cols );
|
||||
vector<int> indices( neighbors1.cols, 0 );
|
||||
vector<float> dists( dist.cols, 0 );
|
||||
index->radiusSearch( query, indices, dists, radius, SearchParams() );
|
||||
vector<int>::const_iterator it = indices.begin();
|
||||
for( j = 0; it != indices.end(); ++it, j++ )
|
||||
neighbors1.at<int>(i,j) = *it;
|
||||
}
|
||||
// compare results
|
||||
if( norm( neighbors, neighbors1, NORM_L1 ) != 0 )
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_FlannTest::releaseModel()
|
||||
{
|
||||
delete index;
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
class CV_FlannLinearIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannLinearIndexTest() : CV_FlannTest( "flann_linear", "LinearIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data ) { createIndex( data, LinearIndexParams() ); }
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return knnSearch( points, neighbors ); }
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
class CV_FlannKMeansIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannKMeansIndexTest() : CV_FlannTest( "flann_kmeans", "KMeansIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data ) { createIndex( data, KMeansIndexParams() ); }
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return radiusSearch( points, neighbors ); }
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
class CV_FlannKDTreeIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannKDTreeIndexTest() : CV_FlannTest( "flann_kdtree", "KDTreeIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data ) { createIndex( data, KDTreeIndexParams() ); }
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return radiusSearch( points, neighbors ); }
|
||||
};
|
||||
|
||||
//----------------------------------------
|
||||
class CV_FlannCompositeIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannCompositeIndexTest() : CV_FlannTest( "flann_composite", "CompositeIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data ) { createIndex( data, CompositeIndexParams() ); }
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return knnSearch( points, neighbors ); }
|
||||
};
|
||||
|
||||
//----------------------------------------
|
||||
class CV_FlannAutotunedIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannAutotunedIndexTest() : CV_FlannTest( "flann_autotuned", "AutotunedIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data ) { createIndex( data, AutotunedIndexParams() ); }
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return knnSearch( points, neighbors ); }
|
||||
};
|
||||
//----------------------------------------
|
||||
class CV_FlannSavedIndexTest : public CV_FlannTest
|
||||
{
|
||||
public:
|
||||
CV_FlannSavedIndexTest() : CV_FlannTest( "flann_saved", "SavedIndex" ) {}
|
||||
protected:
|
||||
virtual void createModel( const Mat& data );
|
||||
virtual int findNeighbors( Mat& points, Mat& neighbors ) { return knnSearch( points, neighbors ); }
|
||||
};
|
||||
|
||||
void CV_FlannSavedIndexTest::createModel(const cv::Mat &data)
|
||||
{
|
||||
switch ( cvRandInt(ts->get_rng()) % 2 )
|
||||
{
|
||||
//case 0: createIndex( data, LinearIndexParams() ); break; // nothing to save for linear search
|
||||
case 0: createIndex( data, KMeansIndexParams() ); break;
|
||||
case 1: createIndex( data, KDTreeIndexParams() ); break;
|
||||
//case 2: createIndex( data, CompositeIndexParams() ); break; // nothing to save for linear search
|
||||
//case 2: createIndex( data, AutotunedIndexParams() ); break; // possible linear index !
|
||||
default: assert(0);
|
||||
}
|
||||
char filename[50];
|
||||
tmpnam( filename );
|
||||
if(filename[0] == '\\') filename[0] = '_';
|
||||
index->save( filename );
|
||||
|
||||
createIndex( data, SavedIndexParams(filename));
|
||||
remove( filename );
|
||||
}
|
||||
|
||||
CV_LSHTest lsh_test;
|
||||
CV_SpillTreeTest_C spilltree_test_c;
|
||||
CV_KDTreeTest_C kdtree_test_c;
|
||||
CV_KDTreeTest_CPP kdtree_test_cpp;
|
||||
CV_FlannLinearIndexTest flann_linear_test;
|
||||
CV_FlannKMeansIndexTest flann_kmeans_test;
|
||||
CV_FlannKDTreeIndexTest flann_kdtree_test;
|
||||
CV_FlannCompositeIndexTest flann_composite_test;
|
||||
CV_FlannAutotunedIndexTest flann_autotuned_test;
|
||||
CV_FlannSavedIndexTest flann_saved_test;
|
||||
@@ -1,431 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
/* Testing parameters */
|
||||
static char FuncName[] = "cvCalcOpticalFlowHS";
|
||||
static char TestName[] = "Optical flow (Horn & Schunck)";
|
||||
static char TestClass[] = "Algorithm";
|
||||
|
||||
static long lImageWidth;
|
||||
static long lImageHeight;
|
||||
static float lambda;
|
||||
|
||||
#define EPSILON 0.0001f
|
||||
|
||||
static int fmaCalcOpticalFlowHS( void )
|
||||
{
|
||||
/* Some Variables */
|
||||
int i,j,k;
|
||||
|
||||
uchar* roiA;
|
||||
uchar* roiB;
|
||||
|
||||
float* VelocityX;
|
||||
float* VelocityY;
|
||||
|
||||
float* auxVelocityX;
|
||||
float* auxVelocityY;
|
||||
|
||||
float* DerX;
|
||||
float* DerY;
|
||||
float* DerT;
|
||||
|
||||
long lErrors = 0;
|
||||
|
||||
CvTermCriteria criteria;
|
||||
|
||||
int usePrevious;
|
||||
|
||||
int Stop = 0;
|
||||
int iteration = 0;
|
||||
float epsilon = 0;
|
||||
|
||||
static int read_param = 0;
|
||||
|
||||
/* Initialization global parameters */
|
||||
if( !read_param )
|
||||
{
|
||||
read_param = 1;
|
||||
/* Reading test-parameters */
|
||||
trslRead( &lImageHeight, "300", "Image height" );
|
||||
trslRead( &lImageWidth, "300", "Image width" );
|
||||
trssRead( &lambda, "20", "lambda" );
|
||||
}
|
||||
|
||||
/* initialization - for warning disable */
|
||||
criteria.epsilon = 0;
|
||||
criteria.max_iter = 0;
|
||||
criteria.type = 1;
|
||||
|
||||
/* Allocating memory for all frames */
|
||||
IplImage* imgA = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_8U, 1 );
|
||||
IplImage* imgB = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_8U, 1 );
|
||||
|
||||
IplImage* testVelocityX = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_32F, 1 );
|
||||
IplImage* testVelocityY = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_32F, 1 );
|
||||
|
||||
VelocityX = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
VelocityY = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
|
||||
auxVelocityX = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
auxVelocityY = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
|
||||
DerX = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
DerY = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
DerT = (float*)cvAlloc( lImageWidth*lImageHeight * sizeof(float) );
|
||||
|
||||
/* Filling images */
|
||||
ats1bInitRandom( 0, 255, (uchar*)imgA->imageData, lImageWidth * lImageHeight );
|
||||
ats1bInitRandom( 0, 255, (uchar*)imgB->imageData, lImageWidth * lImageHeight );
|
||||
|
||||
/* set ROI of images */
|
||||
roiA = (uchar*)imgA->imageData;
|
||||
roiB = (uchar*)imgB->imageData;
|
||||
|
||||
/* example of 3*3 ROI*/
|
||||
/*roiA[0] = 0;
|
||||
roiA[1] = 1;
|
||||
roiA[2] = 2;
|
||||
roiA[lImageWidth] = 0;
|
||||
roiA[lImageWidth+1] = 1;
|
||||
roiA[lImageWidth+2] = 2;
|
||||
roiA[2*lImageWidth] = 0;
|
||||
roiA[2*lImageWidth+1] = 1;
|
||||
roiA[2*lImageWidth+2] = 2;
|
||||
|
||||
roiB[0] = 1;
|
||||
roiB[1] = 2;
|
||||
roiB[2] = 3;
|
||||
roiB[lImageWidth] = 1;
|
||||
roiB[lImageWidth+1] = 2;
|
||||
roiB[lImageWidth+2] = 3;
|
||||
roiB[2*lImageWidth] = 1;
|
||||
roiB[2*lImageWidth+1] = 2;
|
||||
roiB[2*lImageWidth+2] = 3;*/
|
||||
/****************************************************************************************\
|
||||
* Calculate derivatives *
|
||||
\****************************************************************************************/
|
||||
for (i=0; i<lImageHeight; i++)
|
||||
{
|
||||
for(j=0; j<lImageWidth; j++)
|
||||
{
|
||||
int jr,jl,it,ib;
|
||||
|
||||
if ( j==lImageWidth-1 )
|
||||
jr = lImageWidth-1;
|
||||
else jr = j + 1;
|
||||
|
||||
if ( j==0 )
|
||||
jl = 0;
|
||||
else jl = j - 1;
|
||||
|
||||
if ( i==(lImageHeight - 1) )
|
||||
ib = lImageHeight - 1;
|
||||
else ib = i + 1;
|
||||
|
||||
if ( i==0 )
|
||||
it = 0;
|
||||
else it = i - 1;
|
||||
|
||||
DerX[ i*lImageWidth + j ] = (float)
|
||||
(roiA[ (it)*imgA->widthStep + jr ]
|
||||
- roiA[ (it)*imgA->widthStep + jl ]
|
||||
+ 2*roiA[ (i)*imgA->widthStep + jr ]
|
||||
- 2*roiA[ (i)*imgA->widthStep + jl ]
|
||||
+ roiA[ (ib)*imgA->widthStep + jr ]
|
||||
- roiA[ (ib)*imgA->widthStep + jl ])/8 ;
|
||||
|
||||
DerY[ i*lImageWidth + j ] = (float)
|
||||
( roiA[ (ib)*imgA->widthStep + jl ]
|
||||
+ 2*roiA[ (ib)*imgA->widthStep + j ]
|
||||
+ roiA[ (ib)*imgA->widthStep + jr ]
|
||||
- roiA[ (it)*imgA->widthStep + jl ]
|
||||
- 2*roiA[ (it)*imgA->widthStep + j ]
|
||||
- roiA[ (it)*imgA->widthStep + jr ])/8 ;
|
||||
|
||||
DerT[ i*lImageWidth + j ] = (float)
|
||||
(roiB[i*imgB->widthStep + j] - roiA[i*imgA->widthStep + j]);
|
||||
}
|
||||
}
|
||||
for( usePrevious = 0; usePrevious < 2; usePrevious++ )
|
||||
{
|
||||
/****************************************************************************************\
|
||||
* Cases *
|
||||
\****************************************************************************************/
|
||||
for ( k = 0; k < 4; k++ )
|
||||
{
|
||||
switch (k)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
criteria.type = CV_TERMCRIT_ITER;
|
||||
criteria.max_iter = 3;
|
||||
|
||||
trsWrite( ATS_LST|ATS_CON,
|
||||
"usePrevious = %d, criteria = ITER, max_iter = %d\n",
|
||||
usePrevious, criteria.max_iter);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
criteria.type = CV_TERMCRIT_EPS;
|
||||
criteria.epsilon = 0.001f;
|
||||
trsWrite( ATS_LST|ATS_CON,
|
||||
"usePrevious = %d, criteria = EPS, epsilon = %f\n",
|
||||
usePrevious, criteria.epsilon);
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
criteria.type = CV_TERMCRIT_EPS | CV_TERMCRIT_ITER;
|
||||
criteria.epsilon = 0.0001f;
|
||||
criteria.max_iter = 3;
|
||||
trsWrite( ATS_LST|ATS_CON,
|
||||
"usePrevious = %d,"
|
||||
"criteria = EPS|ITER,"
|
||||
"epsilon = %f, max_iter = %d\n",
|
||||
usePrevious, criteria.epsilon, criteria.max_iter);
|
||||
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
criteria.type = CV_TERMCRIT_EPS | CV_TERMCRIT_ITER;
|
||||
criteria.epsilon = 0.00001f;
|
||||
criteria.max_iter = 100;
|
||||
trsWrite( ATS_LST|ATS_CON,
|
||||
"usePrevious = %d,"
|
||||
"criteria = EPS|ITER,"
|
||||
"epsilon = %f, max_iter = %d\n",
|
||||
usePrevious, criteria.epsilon, criteria.max_iter);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
Stop = 0;
|
||||
|
||||
/* Run CVL function */
|
||||
cvCalcOpticalFlowHS( imgA , imgB, usePrevious,
|
||||
testVelocityX, testVelocityY,
|
||||
lambda, criteria );
|
||||
|
||||
/* Calc by other way */
|
||||
if (!usePrevious)
|
||||
{
|
||||
/* Filling initial velocity with zero */
|
||||
for (i = 0; i < lImageWidth * lImageHeight; i++ )
|
||||
{
|
||||
VelocityX[i] = 0 ;
|
||||
VelocityY[i] = 0 ;
|
||||
}
|
||||
}
|
||||
iteration = 0;
|
||||
while ( !Stop )
|
||||
{
|
||||
float* oldX;
|
||||
float* oldY;
|
||||
float* newX;
|
||||
float* newY;
|
||||
|
||||
iteration++;
|
||||
|
||||
if ( iteration & 1 )
|
||||
{
|
||||
oldX = VelocityX;
|
||||
oldY = VelocityY;
|
||||
newX = auxVelocityX;
|
||||
newY = auxVelocityY;
|
||||
}
|
||||
else
|
||||
{
|
||||
oldX = auxVelocityX;
|
||||
oldY = auxVelocityY;
|
||||
newX = VelocityX;
|
||||
newY = VelocityY;
|
||||
}
|
||||
|
||||
for( i = 0; i < lImageHeight; i++)
|
||||
{
|
||||
for(j = 0; j< lImageWidth; j++)
|
||||
{
|
||||
float aveX = 0;
|
||||
float aveY = 0;
|
||||
float dx,dy,dt;
|
||||
|
||||
aveX +=(j==0) ? oldX[ i*lImageWidth + j ] : oldX[ i*lImageWidth + j-1 ];
|
||||
aveX +=(j==lImageWidth-1) ? oldX[ i*lImageWidth + j ] :
|
||||
oldX[ i*lImageWidth + j+1 ];
|
||||
aveX +=(i==0) ? oldX[ i*lImageWidth + j ] : oldX[ (i-1)*lImageWidth + j ];
|
||||
aveX +=(i==lImageHeight-1) ? oldX[ i*lImageWidth + j ] :
|
||||
oldX[ (i+1)*lImageWidth + j ];
|
||||
aveX /=4;
|
||||
|
||||
aveY +=(j==0) ? oldY[ i*lImageWidth + j ] : oldY[ i*lImageWidth + j-1 ];
|
||||
aveY +=(j==lImageWidth-1) ? oldY[ i*lImageWidth + j ] :
|
||||
oldY[ i*lImageWidth + j+1 ];
|
||||
aveY +=(i==0) ? oldY[ i*lImageWidth + j ] : oldY[ (i-1)*lImageWidth + j ];
|
||||
aveY +=(i==lImageHeight-1) ? oldY[ i*lImageWidth + j ] :
|
||||
oldY[ (i+1)*lImageWidth + j ];
|
||||
aveY /=4;
|
||||
|
||||
dx = DerX[ i*lImageWidth + j ];
|
||||
dy = DerY[ i*lImageWidth + j ];
|
||||
dt = DerT[ i*lImageWidth + j ];
|
||||
|
||||
/* Horn & Schunck pure formulas */
|
||||
newX[ i*lImageWidth + j ] = aveX - ( dx * aveX +
|
||||
dy * aveY + dt ) * lambda * dx /
|
||||
(1 + lambda * ( dx*dx + dy*dy ));
|
||||
|
||||
newY[ i*lImageWidth + j ] = aveY - ( dx * aveX +
|
||||
dy * aveY + dt ) * lambda * dy /
|
||||
(1 + lambda * ( dx*dx + dy*dy ));
|
||||
}
|
||||
}
|
||||
/* evaluate epsilon */
|
||||
epsilon = 0;
|
||||
for ( i = 0; i < lImageHeight; i++)
|
||||
{
|
||||
for ( j = 0; j < lImageWidth; j++)
|
||||
{
|
||||
epsilon = MAX((float)fabs(newX[i*lImageWidth + j]
|
||||
- oldX[i*lImageWidth + j]), epsilon );
|
||||
epsilon = MAX((float)fabs(newY[i*lImageWidth + j]
|
||||
- oldY[i*lImageWidth + j]), epsilon );
|
||||
}
|
||||
}
|
||||
|
||||
switch (criteria.type)
|
||||
{
|
||||
case CV_TERMCRIT_ITER:
|
||||
Stop = (criteria.max_iter == iteration );break;
|
||||
case CV_TERMCRIT_EPS:
|
||||
Stop = (criteria.epsilon > epsilon );break;
|
||||
case CV_TERMCRIT_ITER|CV_TERMCRIT_EPS:
|
||||
Stop = ( ( criteria.epsilon > epsilon ) ||
|
||||
( criteria.max_iter == iteration ));
|
||||
break;
|
||||
}
|
||||
if (Stop)
|
||||
{
|
||||
if ( (newX != VelocityX) && (newY != VelocityY) )
|
||||
{
|
||||
memcpy( VelocityX, newX, lImageWidth * lImageHeight * sizeof(float) );
|
||||
memcpy( VelocityY, newY, lImageWidth * lImageHeight * sizeof(float) );
|
||||
}
|
||||
}
|
||||
}
|
||||
trsWrite( ATS_LST|ATS_CON,
|
||||
"%d iterations are made\n", iteration );
|
||||
|
||||
for( i = 0; i < lImageHeight; i++)
|
||||
{
|
||||
for(j = 0; j< lImageWidth; j++)
|
||||
{
|
||||
float tvx = ((float*)(testVelocityX->imageData + i*testVelocityX->widthStep))[j];
|
||||
float tvy = ((float*)(testVelocityY->imageData + i*testVelocityY->widthStep))[j];
|
||||
|
||||
if (( fabs( tvx - VelocityX[i*lImageWidth + j])>EPSILON )||
|
||||
( fabs( tvy - VelocityY[i*lImageWidth + j])>EPSILON ) )
|
||||
{
|
||||
//trsWrite( ATS_LST | ATS_CON, " ValueX %f \n",
|
||||
// testVelocityX[i*lROIWidth + j] );
|
||||
//trsWrite( ATS_LST | ATS_CON, " mustX %f \n",
|
||||
// VelocityX[i*lROIWidth + j] );
|
||||
|
||||
//trsWrite( ATS_LST | ATS_CON, " ValueY %f \n",
|
||||
// testVelocityY[i*lROIWidth + j] );
|
||||
//trsWrite( ATS_LST | ATS_CON, " mustY %f \n",
|
||||
// VelocityY[i*lROIWidth + j] );
|
||||
|
||||
//trsWrite( ATS_LST | ATS_CON, " Coordinates %d %d\n", i, j );
|
||||
|
||||
lErrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}/* for */
|
||||
/* Filling initial velocity with zero */
|
||||
cvZero( testVelocityX );
|
||||
cvZero( testVelocityY );
|
||||
for (i = 0; i < lImageWidth * lImageHeight; i++ )
|
||||
{
|
||||
VelocityX[i] = 0 ;
|
||||
VelocityY[i] = 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
/* Free memory */
|
||||
cvFree( &VelocityX );
|
||||
cvFree( &VelocityY );
|
||||
cvFree( &auxVelocityX );
|
||||
cvFree( &auxVelocityY );
|
||||
|
||||
|
||||
cvFree( &DerX );
|
||||
cvFree( &DerY );
|
||||
cvFree( &DerT );
|
||||
|
||||
cvReleaseImage( &imgA );
|
||||
cvReleaseImage( &imgB );
|
||||
cvReleaseImage( &testVelocityX );
|
||||
cvReleaseImage( &testVelocityY );
|
||||
|
||||
|
||||
if( lErrors == 0 ) return trsResult( TRS_OK, "No errors fixed for this text" );
|
||||
else return trsResult( TRS_FAIL, "Total fixed %d errors", lErrors );
|
||||
} /*fmaCalcOpticalFlowHS*/
|
||||
|
||||
void InitACalcOpticalFlowHS( void )
|
||||
{
|
||||
/* Registering test function */
|
||||
trsReg( FuncName, TestName, TestClass, fmaCalcOpticalFlowHS );
|
||||
} /* InitACalcOpticalFlowHS */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,304 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
/* Testing parameters */
|
||||
static char FuncName[] = "cvCalcOpticalFlowLK";
|
||||
static char TestName[] = "Optical flow (Lucas & Kanade)";
|
||||
static char TestClass[] = "Algorithm";
|
||||
|
||||
static long lImageWidth;
|
||||
static long lImageHeight;
|
||||
static long lWinWidth;
|
||||
static long lWinHeight;
|
||||
|
||||
#define EPSILON 0.00001f
|
||||
|
||||
static int fmaCalcOpticalFlowLK( void )
|
||||
{
|
||||
/* Some Variables */
|
||||
int* WH = NULL;
|
||||
int* WV = NULL;
|
||||
|
||||
int W3[3] = { 1, 2, 1 };
|
||||
int W5[5] = { 1, 4, 6, 4, 1 };
|
||||
int W7[7] = { 1, 6, 15, 20, 15, 6, 1 };
|
||||
int W9[9] = { 1, 8, 28, 56, 70, 56, 28, 8, 1 };
|
||||
int W11[11] = {1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1 };
|
||||
|
||||
int i,j,m,k;
|
||||
uchar* roiA;
|
||||
uchar* roiB;
|
||||
|
||||
float* VelocityX;
|
||||
float* VelocityY;
|
||||
|
||||
float* DerivativeX;
|
||||
float* DerivativeY;
|
||||
float* DerivativeT;
|
||||
|
||||
long lErrors = 0;
|
||||
CvSize winSize;
|
||||
|
||||
int HRad;
|
||||
int VRad;
|
||||
|
||||
float A1, A2, B1, B2, C1, C2;
|
||||
|
||||
static int read_param = 0;
|
||||
|
||||
/* Initialization global parameters */
|
||||
if( !read_param )
|
||||
{
|
||||
read_param = 1;
|
||||
/* Reading test-parameters */
|
||||
trslRead( &lImageHeight, "563", "Image height" );
|
||||
trslRead( &lImageWidth, "345", "Image width" );
|
||||
trslRead( &lWinHeight, "7", "win height 3/5/7/9/11 " );
|
||||
trslRead( &lWinWidth, "9", "win width 3/5/7/9/11 " );
|
||||
}
|
||||
|
||||
/* Checking all sizes of source histogram in ranges */
|
||||
IplImage* imgA = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_8U, 1 );
|
||||
IplImage* imgB = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_8U, 1 );
|
||||
|
||||
IplImage* testVelocityX = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_32F, 1 );
|
||||
IplImage* testVelocityY = cvCreateImage( cvSize(lImageWidth,lImageHeight), IPL_DEPTH_32F, 1 );
|
||||
|
||||
VelocityX = (float*)cvAlloc( lImageWidth * lImageHeight * sizeof(float) );
|
||||
VelocityY = (float*)cvAlloc( lImageWidth * lImageHeight * sizeof(float) );
|
||||
|
||||
DerivativeX = (float*)cvAlloc( lImageWidth * lImageHeight * sizeof(float) );
|
||||
DerivativeY = (float*)cvAlloc( lImageWidth * lImageHeight * sizeof(float) );
|
||||
DerivativeT = (float*)cvAlloc( lImageWidth * lImageHeight * sizeof(float) );
|
||||
|
||||
winSize.height = lWinHeight;
|
||||
winSize.width = lWinWidth;
|
||||
|
||||
switch (lWinHeight)
|
||||
{
|
||||
case 3:
|
||||
WV = W3; break;
|
||||
case 5:
|
||||
WV = W5; break;
|
||||
case 7:
|
||||
WV = W7; break;
|
||||
case 9:
|
||||
WV = W9; break;
|
||||
case 11:
|
||||
WV = W11; break;
|
||||
}
|
||||
switch (lWinWidth)
|
||||
{
|
||||
case 3:
|
||||
WH = W3; break;
|
||||
case 5:
|
||||
WH = W5; break;
|
||||
case 7:
|
||||
WH = W7; break;
|
||||
case 9:
|
||||
WH = W9; break;
|
||||
case 11:
|
||||
WH = W11; break;
|
||||
|
||||
}
|
||||
|
||||
HRad = (winSize.width - 1)/2;
|
||||
VRad = (winSize.height - 1)/2;
|
||||
|
||||
/* Filling images */
|
||||
ats1bInitRandom( 0, 255, (uchar*)imgA->imageData, lImageHeight * imgA->widthStep );
|
||||
ats1bInitRandom( 0, 255, (uchar*)imgB->imageData, imgA->widthStep * lImageHeight );
|
||||
|
||||
/* Run CVL function */
|
||||
cvCalcOpticalFlowLK( imgA , imgB, winSize,
|
||||
testVelocityX, testVelocityY );
|
||||
|
||||
|
||||
/* Calc by other way */
|
||||
roiA = (uchar*)imgA->imageData;
|
||||
roiB = (uchar*)imgB->imageData;
|
||||
|
||||
/* Calculate derivatives */
|
||||
for (i=0; i<imgA->height; i++)
|
||||
{
|
||||
for(j=0; j<imgA->width; j++)
|
||||
{
|
||||
int jr,jl,it,ib;
|
||||
|
||||
if ( j==imgA->width-1 )
|
||||
jr = imgA->width-1;
|
||||
else jr = j + 1;
|
||||
|
||||
if ( j==0 )
|
||||
jl = 0;
|
||||
else jl = j - 1;
|
||||
|
||||
if ( i==(imgA->height - 1) )
|
||||
ib = imgA->height - 1;
|
||||
else ib = i + 1;
|
||||
|
||||
if ( i==0 )
|
||||
it = 0;
|
||||
else it = i - 1;
|
||||
|
||||
DerivativeX[ i*lImageWidth + j ] = (float)
|
||||
(roiA[ (it)*imgA->widthStep + jr ]
|
||||
- roiA[ (it)*imgA->widthStep + jl ]
|
||||
+ 2*roiA[ (i)*imgA->widthStep + jr ]
|
||||
- 2*roiA[ (i)*imgA->widthStep + jl ]
|
||||
+ roiA[ (ib)*imgA->widthStep + jr ]
|
||||
- roiA[ (ib)*imgA->widthStep + jl ]) ;
|
||||
|
||||
DerivativeY[ i*lImageWidth + j ] = (float)
|
||||
( roiA[ (ib)*imgA->widthStep + jl ]
|
||||
+ 2*roiA[ (ib)*imgA->widthStep + j ]
|
||||
+ roiA[ (ib)*imgA->widthStep + jr ]
|
||||
- roiA[ (it)*imgA->widthStep + jl ]
|
||||
- 2*roiA[ (it)*imgA->widthStep + j ]
|
||||
- roiA[ (it)*imgA->widthStep + jr ]) ;
|
||||
|
||||
DerivativeT[ i*lImageWidth + j ] = (float)
|
||||
(roiB[i*imgB->widthStep + j] - roiA[i*imgA->widthStep + j])*8;
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < lImageHeight; i++)
|
||||
{
|
||||
for(j = 0; j< lImageWidth; j++)
|
||||
{
|
||||
A1 =0;
|
||||
A2 =0;
|
||||
B1 =0;
|
||||
B2 =0;
|
||||
C1= 0;
|
||||
C2= 0;
|
||||
|
||||
for( k = -VRad ; k <= VRad ; k++ )
|
||||
{
|
||||
for( m = - HRad; m <= HRad ; m++ )
|
||||
{
|
||||
int coord = (i+k)*lImageWidth + (j+m);
|
||||
if ( (j+m<0) ||
|
||||
(j+m >lImageWidth-1) ||
|
||||
( (k+i)<0 ) ||
|
||||
( (k+i)>lImageHeight-1) )
|
||||
{continue;}
|
||||
|
||||
A1+=WV[k+VRad]*WH[m+HRad]* DerivativeX[coord]*DerivativeY[coord];
|
||||
A2+=WV[k+VRad]*WH[m+HRad]* DerivativeX[coord]*DerivativeX[coord];
|
||||
B1+=WV[k+VRad]*WH[m+HRad]* DerivativeY[coord]*DerivativeY[coord];
|
||||
B2+=WV[k+VRad]*WH[m+HRad]* DerivativeX[coord]*DerivativeY[coord];
|
||||
C1+=WV[k+VRad]*WH[m+HRad]* DerivativeY[coord]*DerivativeT[coord];
|
||||
C2+=WV[k+VRad]*WH[m+HRad]* DerivativeX[coord]*DerivativeT[coord];
|
||||
}
|
||||
}
|
||||
if (A1*B2 - A2*B1)
|
||||
{
|
||||
VelocityX[i*lImageWidth + j] = - (C1*B2 - C2*B1)/(A1*B2 - A2*B1);
|
||||
VelocityY[i*lImageWidth + j] = - (A1*C2 - A2*C1)/(A1*B2 - A2*B1);
|
||||
}
|
||||
else if ( (A1+A2)*(A1+A2) + (B1+B2)*(B1+B2) )
|
||||
{ /* Calculate Normal flow */
|
||||
VelocityX[i*lImageWidth + j] = -(A1+A2)*(C1+C2)/((A1+A2)*(A1+A2)+(B1+B2)*(B1+B2));
|
||||
VelocityY[i*lImageWidth + j] = -(B1+B2)*(C1+C2)/((A1+A2)*(A1+A2)+(B1+B2)*(B1+B2));
|
||||
}
|
||||
else
|
||||
{
|
||||
VelocityX[i*lImageWidth + j] = 0;
|
||||
VelocityY[i*lImageWidth + j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < lImageHeight; i++)
|
||||
{
|
||||
for(j = 0; j< lImageWidth; j++)
|
||||
{
|
||||
float tvx = ((float*)(testVelocityX->imageData + i*testVelocityX->widthStep))[j];
|
||||
float tvy = ((float*)(testVelocityY->imageData + i*testVelocityY->widthStep))[j];
|
||||
|
||||
|
||||
|
||||
if (( fabs(tvx - VelocityX[i*lImageWidth + j])>EPSILON )||
|
||||
( fabs(tvy - VelocityY[i*lImageWidth + j])>EPSILON ) )
|
||||
{
|
||||
//trsWrite( ATS_LST | ATS_CON, " ValueX %f \n", tvx );
|
||||
//trsWrite( ATS_LST | ATS_CON, " mustX %f \n", VelocityX[i*lImageWidth + j] );
|
||||
|
||||
//trsWrite( ATS_LST | ATS_CON, " ValueY %f \n", tvy );
|
||||
//trsWrite( ATS_LST | ATS_CON, " mustY %f \n", VelocityY[i*lImageWidth + j] );
|
||||
|
||||
//trsWrite( ATS_LST | ATS_CON, " Coordinates %d %d\n", i, j );
|
||||
|
||||
lErrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cvFree( &VelocityX );
|
||||
cvFree( &VelocityY );
|
||||
|
||||
cvFree( &DerivativeX );
|
||||
cvFree( &DerivativeY );
|
||||
cvFree( &DerivativeT );
|
||||
|
||||
cvReleaseImage( &imgA );
|
||||
cvReleaseImage( &imgB );
|
||||
cvReleaseImage( &testVelocityX );
|
||||
cvReleaseImage( &testVelocityY );
|
||||
|
||||
|
||||
if( lErrors == 0 ) return trsResult( TRS_OK, "No errors fixed for this text" );
|
||||
else return trsResult( TRS_FAIL, "Total fixed %d errors", lErrors );
|
||||
} /*fmaCalcOpticalFlowLK*/
|
||||
|
||||
void InitACalcOpticalFlowLK( void )
|
||||
{
|
||||
/* Registering test function */
|
||||
trsReg( FuncName, TestName, TestClass, fmaCalcOpticalFlowLK );
|
||||
} /* InitAACalcOpticalFlowLK */
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,217 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
/* ///////////////////// pyrlk_test ///////////////////////// */
|
||||
|
||||
class CV_OptFlowPyrLKTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_OptFlowPyrLKTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_OptFlowPyrLKTest::CV_OptFlowPyrLKTest():
|
||||
CvTest( "optflow-pyrlk", "cvCalcOpticalFlowPyrLK" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_OptFlowPyrLKTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
const double success_error_level = 0.2;
|
||||
const int bad_points_max = 2;
|
||||
|
||||
/* test parameters */
|
||||
double max_err = 0., sum_err = 0;
|
||||
int pt_cmpd = 0;
|
||||
int pt_exceed = 0;
|
||||
int merr_i = 0, merr_j = 0, merr_k = 0;
|
||||
char filename[1000];
|
||||
|
||||
CvPoint2D32f *u = 0, *v = 0, *v2 = 0;
|
||||
CvMat *_u = 0, *_v = 0, *_v2 = 0;
|
||||
char* status = 0;
|
||||
|
||||
IplImage* imgI = 0;
|
||||
IplImage* imgJ = 0;
|
||||
|
||||
int n = 0, i = 0;
|
||||
|
||||
sprintf( filename, "%soptflow/%s", ts->get_data_path(), "lk_prev.dat" );
|
||||
_u = (CvMat*)cvLoad( filename );
|
||||
|
||||
if( !_u )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "could not read %s\n", filename );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
sprintf( filename, "%soptflow/%s", ts->get_data_path(), "lk_next.dat" );
|
||||
_v = (CvMat*)cvLoad( filename );
|
||||
|
||||
if( !_v )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "could not read %s\n", filename );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( _u->cols != 2 || CV_MAT_TYPE(_u->type) != CV_32F ||
|
||||
_v->cols != 2 || CV_MAT_TYPE(_v->type) != CV_32F || _v->rows != _u->rows )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the loaded matrices of points are not valid\n" );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
|
||||
}
|
||||
|
||||
u = (CvPoint2D32f*)_u->data.fl;
|
||||
v = (CvPoint2D32f*)_v->data.fl;
|
||||
|
||||
/* allocate adidtional buffers */
|
||||
_v2 = cvCloneMat( _u );
|
||||
v2 = (CvPoint2D32f*)_v2->data.fl;
|
||||
|
||||
/* read first image */
|
||||
sprintf( filename, "%soptflow/%s", ts->get_data_path(), "rock_1.bmp" );
|
||||
imgI = cvLoadImage( filename, -1 );
|
||||
|
||||
if( !imgI )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "could not read %s\n", filename );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
/* read second image */
|
||||
sprintf( filename, "%soptflow/%s", ts->get_data_path(), "rock_2.bmp" );
|
||||
imgJ = cvLoadImage( filename, -1 );
|
||||
|
||||
if( !imgJ )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "could not read %s\n", filename );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
n = _u->rows;
|
||||
status = (char*)cvAlloc(n*sizeof(status[0]));
|
||||
|
||||
/* calculate flow */
|
||||
cvCalcOpticalFlowPyrLK( imgI, imgJ, 0, 0, u, v2, n, cvSize( 20, 20 ),
|
||||
4, status, 0, cvTermCriteria( CV_TERMCRIT_ITER|
|
||||
CV_TERMCRIT_EPS, 30, 0.01f ), 0 );
|
||||
|
||||
/* compare results */
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
if( status[i] != 0 )
|
||||
{
|
||||
double err;
|
||||
if( cvIsNaN(v[i].x) )
|
||||
{
|
||||
merr_j++;
|
||||
continue;
|
||||
}
|
||||
|
||||
err = fabs(v2[i].x - v[i].x) + fabs(v2[i].y - v[i].y);
|
||||
if( err > max_err )
|
||||
{
|
||||
max_err = err;
|
||||
merr_i = i;
|
||||
}
|
||||
|
||||
pt_exceed += err > success_error_level;
|
||||
if( pt_exceed > bad_points_max )
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The number of poorly tracked points is too big (>=%d)\n", pt_exceed );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
sum_err += err;
|
||||
pt_cmpd++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !cvIsNaN( v[i].x ))
|
||||
{
|
||||
merr_i = i;
|
||||
merr_k++;
|
||||
ts->printf( CvTS::LOG, "The algorithm lost the point #%d\n", i );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( max_err > 1 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Maximum tracking error is too big (=%g)\n", max_err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
cvFree( &status );
|
||||
cvReleaseMat( &_u );
|
||||
cvReleaseMat( &_v );
|
||||
cvReleaseMat( &_v2 );
|
||||
|
||||
cvReleaseImage( &imgI );
|
||||
cvReleaseImage( &imgJ );
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_OptFlowPyrLKTest optflow_pyr_lk_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,221 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
|
||||
class CV_POSITTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_POSITTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_POSITTest::CV_POSITTest():
|
||||
CvTest( "posit", "cvPOSIT" )
|
||||
{
|
||||
test_case_count = 20;
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_POSITTest::run( int start_from )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
/* fixed parameters output */
|
||||
/*float rot[3][3]={ 0.49010f, 0.85057f, 0.19063f,
|
||||
-0.56948f, 0.14671f, 0.80880f,
|
||||
0.65997f, -0.50495f, 0.55629f };
|
||||
|
||||
float trans[3] = { 0.0f, 0.0f, 40.02637f };
|
||||
*/
|
||||
|
||||
/* Some variables */
|
||||
int i, counter;
|
||||
|
||||
CvTermCriteria criteria;
|
||||
CvPoint3D32f* obj_points;
|
||||
CvPoint2D32f* img_points;
|
||||
CvPOSITObject* object;
|
||||
|
||||
float angleX, angleY, angleZ;
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int progress = 0;
|
||||
|
||||
CvMat* true_rotationX = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* true_rotationY = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* true_rotationZ = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* tmp_matrix = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* true_rotation = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* rotation = cvCreateMat( 3, 3, CV_32F );
|
||||
CvMat* translation = cvCreateMat( 3, 1, CV_32F );
|
||||
CvMat* true_translation = cvCreateMat( 3, 1, CV_32F );
|
||||
|
||||
const float flFocalLength = 760.f;
|
||||
const float flEpsilon = 0.5f;
|
||||
|
||||
/* Initilization */
|
||||
criteria.type = CV_TERMCRIT_EPS|CV_TERMCRIT_ITER;
|
||||
criteria.epsilon = flEpsilon;
|
||||
criteria.max_iter = 10000;
|
||||
|
||||
/* Allocating source arrays; */
|
||||
obj_points = (CvPoint3D32f*)cvAlloc( 8 * sizeof(CvPoint3D32f) );
|
||||
img_points = (CvPoint2D32f*)cvAlloc( 8 * sizeof(CvPoint2D32f) );
|
||||
|
||||
/* Fill points arrays with values */
|
||||
|
||||
/* cube model with edge size 10 */
|
||||
obj_points[0].x = 0; obj_points[0].y = 0; obj_points[0].z = 0;
|
||||
obj_points[1].x = 10; obj_points[1].y = 0; obj_points[1].z = 0;
|
||||
obj_points[2].x = 10; obj_points[2].y = 10; obj_points[2].z = 0;
|
||||
obj_points[3].x = 0; obj_points[3].y = 10; obj_points[3].z = 0;
|
||||
obj_points[4].x = 0; obj_points[4].y = 0; obj_points[4].z = 10;
|
||||
obj_points[5].x = 10; obj_points[5].y = 0; obj_points[5].z = 10;
|
||||
obj_points[6].x = 10; obj_points[6].y = 10; obj_points[6].z = 10;
|
||||
obj_points[7].x = 0; obj_points[7].y = 10; obj_points[7].z = 10;
|
||||
|
||||
/* Loop for test some random object positions */
|
||||
for( counter = start_from; counter < test_case_count; counter++ )
|
||||
{
|
||||
ts->update_context( this, counter, true );
|
||||
progress = update_progress( progress, counter, test_case_count, 0 );
|
||||
|
||||
/* set all rotation matrix to zero */
|
||||
cvZero( true_rotationX );
|
||||
cvZero( true_rotationY );
|
||||
cvZero( true_rotationZ );
|
||||
|
||||
/* fill random rotation matrix */
|
||||
angleX = (float)(cvTsRandReal(rng)*2*CV_PI);
|
||||
angleY = (float)(cvTsRandReal(rng)*2*CV_PI);
|
||||
angleZ = (float)(cvTsRandReal(rng)*2*CV_PI);
|
||||
|
||||
true_rotationX->data.fl[0 *3+ 0] = 1;
|
||||
true_rotationX->data.fl[1 *3+ 1] = (float)cos(angleX);
|
||||
true_rotationX->data.fl[2 *3+ 2] = true_rotationX->data.fl[1 *3+ 1];
|
||||
true_rotationX->data.fl[1 *3+ 2] = -(float)sin(angleX);
|
||||
true_rotationX->data.fl[2 *3+ 1] = -true_rotationX->data.fl[1 *3+ 2];
|
||||
|
||||
true_rotationY->data.fl[1 *3+ 1] = 1;
|
||||
true_rotationY->data.fl[0 *3+ 0] = (float)cos(angleY);
|
||||
true_rotationY->data.fl[2 *3+ 2] = true_rotationY->data.fl[0 *3+ 0];
|
||||
true_rotationY->data.fl[0 *3+ 2] = -(float)sin(angleY);
|
||||
true_rotationY->data.fl[2 *3+ 0] = -true_rotationY->data.fl[0 *3+ 2];
|
||||
|
||||
true_rotationZ->data.fl[2 *3+ 2] = 1;
|
||||
true_rotationZ->data.fl[0 *3+ 0] = (float)cos(angleZ);
|
||||
true_rotationZ->data.fl[1 *3+ 1] = true_rotationZ->data.fl[0 *3+ 0];
|
||||
true_rotationZ->data.fl[0 *3+ 1] = -(float)sin(angleZ);
|
||||
true_rotationZ->data.fl[1 *3+ 0] = -true_rotationZ->data.fl[0 *3+ 1];
|
||||
|
||||
cvMatMul( true_rotationX, true_rotationY, tmp_matrix);
|
||||
cvMatMul( tmp_matrix, true_rotationZ, true_rotation);
|
||||
|
||||
/* fill translation vector */
|
||||
true_translation->data.fl[2] = (float)(cvRandReal(rng)*(2*flFocalLength-40) + 60);
|
||||
true_translation->data.fl[0] = (float)((cvRandReal(rng)*2-1)*true_translation->data.fl[2]);
|
||||
true_translation->data.fl[1] = (float)((cvRandReal(rng)*2-1)*true_translation->data.fl[2]);
|
||||
|
||||
/* calculate perspective projection */
|
||||
for ( i = 0; i < 8; i++ )
|
||||
{
|
||||
float vec[3];
|
||||
CvMat Vec = cvMat( 3, 1, CV_32F, vec );
|
||||
CvMat Obj_point = cvMat( 3, 1, CV_32F, &obj_points[i].x );
|
||||
|
||||
cvMatMul( true_rotation, &Obj_point, &Vec );
|
||||
|
||||
vec[0] += true_translation->data.fl[0];
|
||||
vec[1] += true_translation->data.fl[1];
|
||||
vec[2] += true_translation->data.fl[2];
|
||||
|
||||
img_points[i].x = flFocalLength * vec[0] / vec[2];
|
||||
img_points[i].y = flFocalLength * vec[1] / vec[2];
|
||||
}
|
||||
|
||||
/*img_points[0].x = 0 ; img_points[0].y = 0;
|
||||
img_points[1].x = 80; img_points[1].y = -93;
|
||||
img_points[2].x = 245;img_points[2].y = -77;
|
||||
img_points[3].x = 185;img_points[3].y = 32;
|
||||
img_points[4].x = 32; img_points[4].y = 135;
|
||||
img_points[5].x = 99; img_points[5].y = 35;
|
||||
img_points[6].x = 247; img_points[6].y = 62;
|
||||
img_points[7].x = 195; img_points[7].y = 179;
|
||||
*/
|
||||
|
||||
object = cvCreatePOSITObject( obj_points, 8 );
|
||||
cvPOSIT( object, img_points, flFocalLength, criteria,
|
||||
rotation->data.fl, translation->data.fl );
|
||||
cvReleasePOSITObject( &object );
|
||||
|
||||
code = cvTsCmpEps2( ts, rotation, true_rotation, flEpsilon, false, "rotation matrix" );
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
|
||||
code = cvTsCmpEps2( ts, translation, true_translation, flEpsilon, false, "translation vector" );
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
cvFree( &obj_points );
|
||||
cvFree( &img_points );
|
||||
|
||||
cvReleaseMat( &true_rotationX );
|
||||
cvReleaseMat( &true_rotationY );
|
||||
cvReleaseMat( &true_rotationZ );
|
||||
cvReleaseMat( &tmp_matrix );
|
||||
cvReleaseMat( &true_rotation );
|
||||
cvReleaseMat( &rotation );
|
||||
cvReleaseMat( &translation );
|
||||
cvReleaseMat( &true_translation );
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_POSITTest posit_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,199 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_PyrSegmentationTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_PyrSegmentationTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
#define SCAN 0
|
||||
|
||||
CV_PyrSegmentationTest::CV_PyrSegmentationTest():
|
||||
CvTest( "segmentation-pyramid", "cvPyrSegmentation" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_PyrSegmentationTest::run( int /*start_from*/ )
|
||||
{
|
||||
const int level = 5;
|
||||
const double range = 15;
|
||||
|
||||
int code = CvTS::OK;
|
||||
|
||||
CvPoint _cp[] ={{33,33}, {43,33}, {43,43}, {33,43}};
|
||||
CvPoint _cp2[] ={{50,50}, {70,50}, {70,70}, {50,70}};
|
||||
CvPoint* cp = _cp;
|
||||
CvPoint* cp2 = _cp2;
|
||||
CvConnectedComp *dst_comp[3];
|
||||
CvRect rect[3] = {{50,50,21,21}, {0,0,128,128}, {33,33,11,11}};
|
||||
double a[3] = {441.0, 15822.0, 121.0};
|
||||
|
||||
/* ippiPoint cp3[] ={130,130, 150,130, 150,150, 130,150}; */
|
||||
/* CvPoint cp[] ={0,0, 5,5, 5,0, 10,5, 10,0, 15,5, 15,0}; */
|
||||
int nPoints = 4;
|
||||
int block_size = 1000;
|
||||
|
||||
CvMemStorage *storage; /* storage for connected component writing */
|
||||
CvSeq *comp;
|
||||
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int i, j, iter;
|
||||
|
||||
IplImage *image, *image_f, *image_s;
|
||||
CvSize size = {128, 128};
|
||||
const int threshold1 = 50, threshold2 = 50;
|
||||
|
||||
rect[1].width = size.width;
|
||||
rect[1].height = size.height;
|
||||
a[1] = size.width*size.height - a[0] - a[2];
|
||||
|
||||
OPENCV_CALL( storage = cvCreateMemStorage( block_size ) );
|
||||
|
||||
for( iter = 0; iter < 2; iter++ )
|
||||
{
|
||||
int channels = iter == 0 ? 1 : 3;
|
||||
int mask[] = {0,0,0};
|
||||
|
||||
image = cvCreateImage(size, 8, channels );
|
||||
image_s = cvCloneImage( image );
|
||||
image_f = cvCloneImage( image );
|
||||
|
||||
if( channels == 1 )
|
||||
{
|
||||
int color1 = 30, color2 = 110, color3 = 190;
|
||||
|
||||
cvSet( image, cvScalarAll(color1));
|
||||
cvFillPoly( image, &cp, &nPoints, 1, cvScalar(color2));
|
||||
cvFillPoly( image, &cp2, &nPoints, 1, cvScalar(color3));
|
||||
}
|
||||
else
|
||||
{
|
||||
CvScalar color1 = CV_RGB(30,30,30), color2 = CV_RGB(255,0,0), color3 = CV_RGB(0,255,0);
|
||||
|
||||
assert( channels == 3 );
|
||||
cvSet( image, color1 );
|
||||
cvFillPoly( image, &cp, &nPoints, 1, color2);
|
||||
cvFillPoly( image, &cp2, &nPoints, 1, color3);
|
||||
}
|
||||
|
||||
cvRandArr( rng, image_f, CV_RAND_UNI, cvScalarAll(0), cvScalarAll(range*2) );
|
||||
cvAddWeighted( image, 1, image_f, 1, -range, image_f );
|
||||
|
||||
cvPyrSegmentation( image_f, image_s,
|
||||
storage, &comp,
|
||||
level, threshold1, threshold2 );
|
||||
|
||||
if(comp->total != 3)
|
||||
{
|
||||
ts->printf( CvTS::LOG,
|
||||
"The segmentation function returned %d (not 3) components\n", comp->total );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
/* read the connected components */
|
||||
dst_comp[0] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 0 );
|
||||
dst_comp[1] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 1 );
|
||||
dst_comp[2] = (CvConnectedComp*)CV_GET_SEQ_ELEM( CvConnectedComp, comp, 2 );
|
||||
|
||||
/*{
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
CvRect r = dst_comp[i]->rect;
|
||||
cvRectangle( image_s, cvPoint(r.x,r.y), cvPoint(r.x+r.width,r.y+r.height),
|
||||
CV_RGB(255,255,255), 3, 8, 0 );
|
||||
}
|
||||
|
||||
cvNamedWindow( "test", 1 );
|
||||
cvShowImage( "test", image_s );
|
||||
cvWaitKey(0);
|
||||
}*/
|
||||
|
||||
code = cvTsCmpEps2( ts, image, image_s, 10, false, "the output image" );
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
|
||||
for( i = 0; i < 3; i++)
|
||||
{
|
||||
for( j = 0; j < 3; j++ )
|
||||
{
|
||||
if( !mask[j] && dst_comp[i]->area == a[j] &&
|
||||
dst_comp[i]->rect.x == rect[j].x &&
|
||||
dst_comp[i]->rect.y == rect[j].y &&
|
||||
dst_comp[i]->rect.width == rect[j].width &&
|
||||
dst_comp[i]->rect.height == rect[j].height )
|
||||
{
|
||||
mask[j] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( j == 3 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The component #%d is incorrect\n", i );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseImage(&image_f);
|
||||
cvReleaseImage(&image);
|
||||
cvReleaseImage(&image_s);
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
cvReleaseImage(&image_f);
|
||||
cvReleaseImage(&image);
|
||||
cvReleaseImage(&image_s);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_PyrSegmentationTest pyr_segmentation_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,178 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
template<class T> double thres() { return 1.0; }
|
||||
template<> double thres<float>() { return 1e-5; }
|
||||
|
||||
class CV_ReprojectImageTo3DTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ReprojectImageTo3DTest()
|
||||
: CvTest( "reprojectImageTo3D", "cvReprojectImageTo3D")
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
~CV_ReprojectImageTo3DTest() {}
|
||||
protected:
|
||||
|
||||
|
||||
void run(int)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
int progress = 0;
|
||||
int caseId = 0;
|
||||
|
||||
progress = update_progress( progress, 1, 14, 0 );
|
||||
runCase<float, float>(++caseId, -100.f, 100.f);
|
||||
progress = update_progress( progress, 2, 14, 0 );
|
||||
runCase<int, float>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 3, 14, 0 );
|
||||
runCase<short, float>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 4, 14, 0 );
|
||||
runCase<unsigned char, float>(++caseId, 10, 100);
|
||||
progress = update_progress( progress, 5, 14, 0 );
|
||||
|
||||
runCase<float, int>(++caseId, -100.f, 100.f);
|
||||
progress = update_progress( progress, 6, 14, 0 );
|
||||
runCase<int, int>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 7, 14, 0 );
|
||||
runCase<short, int>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 8, 14, 0 );
|
||||
runCase<unsigned char, int>(++caseId, 10, 100);
|
||||
progress = update_progress( progress, 10, 14, 0 );
|
||||
|
||||
runCase<float, short>(++caseId, -100.f, 100.f);
|
||||
progress = update_progress( progress, 11, 14, 0 );
|
||||
runCase<int, short>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 12, 14, 0 );
|
||||
runCase<short, short>(++caseId, -100, 100);
|
||||
progress = update_progress( progress, 13, 14, 0 );
|
||||
runCase<unsigned char, short>(++caseId, 10, 100);
|
||||
progress = update_progress( progress, 14, 14, 0 );
|
||||
}
|
||||
|
||||
template<class U, class V> double error(const Vec<U, 3>& v1, const Vec<V, 3>& v2) const
|
||||
{
|
||||
double tmp, sum = 0;
|
||||
double nsum = 0;
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
tmp = v1[i];
|
||||
nsum += tmp * tmp;
|
||||
|
||||
tmp = tmp - v2[i];
|
||||
sum += tmp * tmp;
|
||||
|
||||
}
|
||||
return sqrt(sum)/(sqrt(nsum)+1.);
|
||||
}
|
||||
|
||||
template<class InT, class OutT> void runCase(int caseId, InT min, InT max)
|
||||
{
|
||||
typedef Vec<OutT, 3> out3d_t;
|
||||
|
||||
bool handleMissingValues = (unsigned)theRNG() % 2 == 0;
|
||||
|
||||
Mat_<InT> disp(Size(320, 240));
|
||||
randu(disp, Scalar(min), Scalar(max));
|
||||
|
||||
if (handleMissingValues)
|
||||
disp(disp.rows/2, disp.cols/2) = min - 1;
|
||||
|
||||
Mat_<double> Q(4, 4);
|
||||
randu(Q, Scalar(-5), Scalar(5));
|
||||
|
||||
Mat_<out3d_t> _3dImg(disp.size());
|
||||
|
||||
CvMat cvdisp = disp; CvMat cv_3dImg = _3dImg; CvMat cvQ = Q;
|
||||
cvReprojectImageTo3D( &cvdisp, &cv_3dImg, &cvQ, handleMissingValues );
|
||||
|
||||
if (numeric_limits<OutT>::max() == numeric_limits<float>::max())
|
||||
reprojectImageTo3D(disp, _3dImg, Q, handleMissingValues);
|
||||
|
||||
for(int y = 0; y < disp.rows; ++y)
|
||||
for(int x = 0; x < disp.cols; ++x)
|
||||
{
|
||||
InT d = disp(y, x);
|
||||
|
||||
double from[4] = { x, y, d, 1 };
|
||||
Mat_<double> res = Q * Mat_<double>(4, 1, from);
|
||||
res /= res(3, 0);
|
||||
|
||||
out3d_t pixel_exp = *(Vec3d*)res.data;
|
||||
out3d_t pixel_out = _3dImg(y, x);
|
||||
|
||||
const int largeZValue = 10000; /* see documentation */
|
||||
|
||||
if (handleMissingValues && y == disp.rows/2 && x == disp.cols/2)
|
||||
{
|
||||
if (pixel_out[2] == largeZValue)
|
||||
continue;
|
||||
|
||||
ts->printf(CvTS::LOG, "Missing values are handled improperly\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
double err = error(pixel_out, pixel_exp), t = thres<OutT>();
|
||||
if ( err > t )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "case %d. too big error at (%d, %d): %g vs expected %g: res = (%g, %g, %g, w=%g) vs pixel_out = (%g, %g, %g)\n",
|
||||
caseId, x, y, err, t, res(0,0), res(1,0), res(2,0), res(3,0),
|
||||
(double)pixel_out[0], (double)pixel_out[1], (double)pixel_out[2]);
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CV_ReprojectImageTo3DTest reprojectImageTo3D_test;
|
||||
@@ -1,233 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
/* This is regression test for Snakes functions of OpenCV.
|
||||
// This test will generate fixed figure, read initial position
|
||||
// of snake from file, run OpenCV function and compare result
|
||||
// position of snake with position(from file) which must be resulting.
|
||||
//
|
||||
// Test is considered to be succesfull if resultant positions
|
||||
// are identical.
|
||||
*/
|
||||
|
||||
class CV_SnakeTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_SnakeTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
#define SCAN 0
|
||||
|
||||
CV_SnakeTest::CV_SnakeTest():
|
||||
CvTest( "snakes", "cvSnakeImage" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_SnakeTest::run( int /*start_from*/ )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
static const char* file_name[] =
|
||||
{
|
||||
"ring",
|
||||
"square"
|
||||
};
|
||||
|
||||
const int numfig_image = 1;
|
||||
const int numfig_grad = 1;
|
||||
|
||||
FILE* file = 0;
|
||||
#ifndef _MAX_PATH
|
||||
#define _MAX_PATH 1024
|
||||
#endif
|
||||
char abs_file_name[_MAX_PATH];
|
||||
char rel_path[_MAX_PATH];
|
||||
|
||||
int i,j;
|
||||
|
||||
/* source image */
|
||||
IplImage* iplSrc = NULL;
|
||||
CvSize win;
|
||||
int length;
|
||||
|
||||
float alpha,beta,gamma;
|
||||
CvTermCriteria criteria;
|
||||
long lErrors = 0;
|
||||
int progress = 0, test_case_count = numfig_image + numfig_grad;
|
||||
CvPoint* Pts = 0;
|
||||
CvPoint* resPts = 0;
|
||||
|
||||
sprintf( rel_path, "%ssnakes/", ts->get_data_path() );
|
||||
|
||||
criteria.type = CV_TERMCRIT_ITER;
|
||||
win.height = win.width = 3;
|
||||
|
||||
for( i = 0; i < test_case_count; i++ )
|
||||
{
|
||||
progress = update_progress( progress, i, test_case_count, 0 );
|
||||
int num_pos;
|
||||
int k;
|
||||
|
||||
char tmp[_MAX_PATH];
|
||||
|
||||
ts->update_context( this, i, false );
|
||||
|
||||
/* create full name of bitmap file */
|
||||
strcpy(tmp, rel_path);
|
||||
strcat(tmp, file_name[i]);
|
||||
strcpy( abs_file_name, tmp );
|
||||
strcat( abs_file_name, ".bmp" );
|
||||
|
||||
/* read bitmap with 8u image */
|
||||
iplSrc = cvLoadImage( abs_file_name, -1 );
|
||||
|
||||
if (!iplSrc)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "can not load %s\n", abs_file_name );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
/* init snake reading file with snake */
|
||||
strcpy(tmp, rel_path);
|
||||
strcat(tmp, file_name[i]);
|
||||
strcpy( abs_file_name, tmp );
|
||||
strcat( abs_file_name, ".txt" );
|
||||
|
||||
#if !SCAN
|
||||
file = fopen( abs_file_name, "r" );
|
||||
#else
|
||||
file = fopen( abs_file_name, "r+" );
|
||||
#endif
|
||||
|
||||
if (!file)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "can not load %s\n", abs_file_name );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
/* read snake parameters */
|
||||
fscanf(file, "%d", &length );
|
||||
fscanf(file, "%f", &alpha );
|
||||
fscanf(file, "%f", &beta );
|
||||
fscanf(file, "%f", &gamma );
|
||||
|
||||
/* allocate memory for snakes */
|
||||
Pts = (CvPoint*)cvAlloc( length * sizeof(Pts[0]) );
|
||||
resPts = (CvPoint*)cvAlloc( length * sizeof(resPts[0]) );
|
||||
|
||||
/* get number of snake positions */
|
||||
fscanf(file, "%d", &num_pos );
|
||||
|
||||
/* get number iterations between two positions */
|
||||
fscanf(file, "%d", &criteria.max_iter );
|
||||
|
||||
/* read initial snake position */
|
||||
for ( j = 0; j < length; j++ )
|
||||
{
|
||||
fscanf(file, "%d%d", &Pts[j].x, &Pts[j].y );
|
||||
}
|
||||
|
||||
for ( k = 0; k < num_pos; k++ )
|
||||
{
|
||||
/* Run CVL function to check it */
|
||||
if(i<numfig_image)
|
||||
{
|
||||
cvSnakeImage( iplSrc, Pts, length,
|
||||
&alpha, &beta, &gamma, CV_VALUE, win, criteria, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
cvSnakeImage( iplSrc, Pts, length,
|
||||
&alpha, &beta, &gamma, CV_VALUE, win, criteria, 1 /*usegrad*/ );
|
||||
}
|
||||
|
||||
#if !SCAN
|
||||
for ( j = 0; j < length; j++ )
|
||||
{
|
||||
fscanf(file, "%d%d", &resPts[j].x, &resPts[j].y );
|
||||
|
||||
lErrors += (Pts[j].x != resPts[j].x);
|
||||
lErrors += (Pts[j].y != resPts[j].y);
|
||||
}
|
||||
#else
|
||||
fseek( file, 0, SEEK_CUR );
|
||||
fprintf(file, "\n");
|
||||
for ( j = 0; j < length; j++ )
|
||||
{
|
||||
fprintf(file, "\n%d %d", Pts[j].x, Pts[j].y );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
fclose(file);
|
||||
file = 0;
|
||||
cvFree(&Pts);
|
||||
cvFree(&resPts);
|
||||
cvReleaseImage(&iplSrc);
|
||||
}
|
||||
|
||||
if( lErrors > 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Total fixed %d errors", lErrors );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
if( file )
|
||||
fclose(file);
|
||||
cvFree(&Pts);
|
||||
cvFree(&resPts);
|
||||
cvReleaseImage(&iplSrc);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_SnakeTest snake_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,297 +0,0 @@
|
||||
#include "cvtest.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#define debug //enables showing images.
|
||||
#define CONSOLEOUTPUT //enables printing rms error and percentage of bad pixels to console.
|
||||
|
||||
//#define LOAD //enables skipping computing disparities and load them from images.
|
||||
//#define SAVEIMAGES //enables saving computed disparity and red-marked disparity images.
|
||||
|
||||
void MarkPixel(const IplImage* markedDisparity, const int h, const int w)
|
||||
{
|
||||
uchar* data = (uchar*)&markedDisparity->imageData[h*markedDisparity->widthStep + w*3];
|
||||
data[0] = 0;
|
||||
data[1] = 0;
|
||||
data[2] = 255;
|
||||
}
|
||||
|
||||
int CalculateErrors(const IplImage* disparity,const IplImage* groundTruth, IplImage* markedDisparity,
|
||||
double &rms_error, double &percentage_of_bad_pixels,
|
||||
const int maxDisparity CV_DEFAULT(16), const int eval_ignore_border CV_DEFAULT(10))
|
||||
{
|
||||
if (disparity->width != groundTruth->width)
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
if (disparity->height != groundTruth->height)
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
|
||||
const double eval_bad_thresh = 1.0;
|
||||
|
||||
char* DC = disparity->imageData;
|
||||
char* DT = groundTruth->imageData;
|
||||
|
||||
double currSum = 0;
|
||||
unsigned int bad_pixels_counter=0;
|
||||
|
||||
double diff=0;
|
||||
|
||||
int w = disparity->width;
|
||||
int h = disparity->height;
|
||||
unsigned int numPixels = w*h;
|
||||
|
||||
for(int i=eval_ignore_border; i<h-eval_ignore_border; i++)
|
||||
for(int j=eval_ignore_border; j<w-eval_ignore_border; j++)
|
||||
{
|
||||
diff = (double)abs(DC[i*disparity->widthStep+j] - DT[i*groundTruth->widthStep+j])/(double)maxDisparity;
|
||||
currSum += diff*diff;
|
||||
|
||||
if ( diff > eval_bad_thresh )
|
||||
{
|
||||
bad_pixels_counter++;
|
||||
MarkPixel(markedDisparity, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
currSum /=(double)numPixels;
|
||||
rms_error = sqrt(currSum);
|
||||
|
||||
percentage_of_bad_pixels = (double)bad_pixels_counter/(double)numPixels * 100;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
class CV_StereoCorrespondenceTestGC : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_StereoCorrespondenceTestGC();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_StereoCorrespondenceTestGC::CV_StereoCorrespondenceTestGC():
|
||||
CvTest( "stereo-gc", "cvFindStereoCorrespondenceGC" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
/* ///////////////////// stereo_correspondece_test ///////////////////////// */
|
||||
void CV_StereoCorrespondenceTestGC::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
const double rms_error_thresh = 1000.0;
|
||||
const double percentage_of_bad_pixels_thresh = 90.0;
|
||||
|
||||
double rms_error[2];
|
||||
double percentage_of_bad_pixels[2];
|
||||
|
||||
/* test parameters */
|
||||
char filepath[1000];
|
||||
char filename[1000];
|
||||
//char extension[5];
|
||||
|
||||
IplImage* left ;
|
||||
IplImage* right;
|
||||
IplImage* disparity_left;
|
||||
IplImage* disparity_right;
|
||||
IplImage* groundTruthLeft;
|
||||
IplImage* groundTruthRight;
|
||||
|
||||
sprintf( filepath, "%sstereocorrespondence/", ts->get_data_path() );
|
||||
sprintf( filename, "%sstereocorrespondence_list.txt", filepath );
|
||||
|
||||
FILE* f = fopen(filename,"r");
|
||||
int numImages=0;
|
||||
fscanf(f,"%d\n",&numImages);
|
||||
|
||||
for(int i=0; i<numImages; i++)
|
||||
{
|
||||
/*Load left and right image from the storage*/
|
||||
char dataName[100];
|
||||
int maxDisparity=0;
|
||||
|
||||
fscanf(f,"%s %d\n",dataName,&maxDisparity);
|
||||
sprintf(filename,"%s%sL.png",filepath,dataName);
|
||||
left = cvLoadImage(filename,0);
|
||||
sprintf(filename,"%s%sR.png",filepath,dataName);
|
||||
right = cvLoadImage(filename,0);
|
||||
|
||||
if (!left || !right)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Left or right image doesn't exist" );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
if ((cvGetSize(left).height != cvGetSize(right).height)
|
||||
|| ((cvGetSize(left).width != cvGetSize(right).width)))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Left and right image sizes aren't equal" );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
sprintf(filename,"%s%s_gtL.png",filepath,dataName);
|
||||
groundTruthLeft = cvLoadImage(filename,0);
|
||||
sprintf(filename,"%s%s_gtR.png",filepath,dataName);
|
||||
groundTruthRight = cvLoadImage(filename,0);
|
||||
|
||||
if (!groundTruthLeft && !groundTruthRight)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Left and right ground truth images don't exist" );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
IplImage*& groundTruth = (i == 0) ? groundTruthLeft : groundTruthRight;
|
||||
if (groundTruth)
|
||||
if (groundTruth->nChannels != 1)
|
||||
{
|
||||
IplImage* tmp = groundTruth;
|
||||
groundTruth = cvCreateImage(cvGetSize(left),IPL_DEPTH_8U,1);
|
||||
cvCvtColor(tmp, groundTruth,CV_BGR2GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
/*Find disparity map for current image pair*/
|
||||
#ifndef LOAD
|
||||
disparity_left = cvCreateImage( cvGetSize(left), IPL_DEPTH_32S, 1 );
|
||||
disparity_right = cvCreateImage( cvGetSize(left), IPL_DEPTH_32S, 1 );
|
||||
|
||||
CvStereoGCState* state = cvCreateStereoGCState(maxDisparity, 2);
|
||||
cvFindStereoCorrespondenceGC( left, right,
|
||||
disparity_left, disparity_right, state);
|
||||
|
||||
double scale = 256/maxDisparity ;
|
||||
if (!strcmp(dataName,"sawtooth") || !strcmp(dataName,"map") || !strcmp(dataName,"poster")
|
||||
|| !strcmp(dataName,"bull") || !strcmp(dataName,"barn1") || !strcmp(dataName,"barn2"))
|
||||
scale = 8.0;
|
||||
|
||||
IplImage* temp;
|
||||
temp = disparity_left;
|
||||
disparity_left = cvCreateImage(cvGetSize(temp), IPL_DEPTH_8U,1);
|
||||
cvConvertScale(temp, disparity_left, -scale);
|
||||
temp = disparity_right;
|
||||
disparity_right = cvCreateImage(cvGetSize(temp), IPL_DEPTH_8U,1);
|
||||
cvConvertScale(temp, disparity_right, scale );
|
||||
#endif
|
||||
#ifdef LOAD
|
||||
disparity_left;
|
||||
disparity_right;
|
||||
sprintf(filename,"%s%s_dLgc.png",filepath,dataName);
|
||||
disparity_left = cvLoadImage(filename,0);
|
||||
sprintf(filename,"%s%s_dRgc.png",filepath,dataName);
|
||||
disparity_right = cvLoadImage(filename,0);
|
||||
#endif
|
||||
#ifdef debug
|
||||
cvNamedWindow("disparity_left");
|
||||
cvNamedWindow("disparity_right");
|
||||
cvNamedWindow("ground_truth_left");
|
||||
cvNamedWindow("ground_truth_right");
|
||||
|
||||
cvShowImage("disparity_left",disparity_left);
|
||||
cvShowImage("disparity_right",disparity_right);
|
||||
cvShowImage("ground_truth_left", groundTruthLeft);
|
||||
cvShowImage("ground_truth_right", groundTruthRight);
|
||||
#endif
|
||||
|
||||
/*Calculate RMS error and percentage of bad pixels*/
|
||||
IplImage* markedDisparity_left = cvCreateImage(cvGetSize(left), IPL_DEPTH_8U, 3);
|
||||
IplImage* markedDisparity_right = cvCreateImage(cvGetSize(left), IPL_DEPTH_8U, 3);
|
||||
cvCvtColor(disparity_left,markedDisparity_left,CV_GRAY2RGB);
|
||||
cvCvtColor(disparity_right,markedDisparity_right,CV_GRAY2RGB);
|
||||
|
||||
int eval_ignore_border = 10;
|
||||
if (strcmp(dataName,"tsukuba") == 0)
|
||||
eval_ignore_border = 18;
|
||||
|
||||
/*Left*/
|
||||
int retcode[2] = {0,0};
|
||||
if (groundTruthLeft)
|
||||
retcode[0] = CalculateErrors(disparity_left,groundTruthLeft, markedDisparity_left,
|
||||
rms_error[0], percentage_of_bad_pixels[0], maxDisparity, eval_ignore_border);
|
||||
/*Right*/
|
||||
if (groundTruthRight)
|
||||
retcode[1] = CalculateErrors(disparity_right,groundTruthRight, markedDisparity_right,
|
||||
rms_error[1], percentage_of_bad_pixels[1], maxDisparity, eval_ignore_border);
|
||||
|
||||
#ifdef SAVEIMAGES
|
||||
#ifndef LOAD
|
||||
sprintf(filename,"%s%s_dLgc.png",filepath,dataName);
|
||||
cvSaveImage(filename,disparity_left);
|
||||
sprintf(filename,"%s%s_dRgc.png",filepath,dataName);
|
||||
cvSaveImage(filename,disparity_right);
|
||||
|
||||
sprintf(filename,"%s%s_mdLgc.png",filepath,dataName);
|
||||
cvSaveImage(filename,markedDisparity_left);
|
||||
sprintf(filename,"%s%s_mdRgc.png",filepath,dataName);
|
||||
cvSaveImage(filename,markedDisparity_right);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef debug
|
||||
cvNamedWindow("markedDisparity_left");
|
||||
cvNamedWindow("markedDisparity_right");
|
||||
cvShowImage("markedDisparity_left",markedDisparity_left);
|
||||
cvShowImage("markedDisparity_right",markedDisparity_right);
|
||||
cvWaitKey(1000);
|
||||
#endif
|
||||
if (retcode[0])
|
||||
{
|
||||
ts->printf(CvTS::LOG,"Calculation error");
|
||||
code = retcode[0];
|
||||
//goto _exit_;
|
||||
}
|
||||
if (retcode[1])
|
||||
{
|
||||
ts->printf(CvTS::LOG,"Calculation error");
|
||||
code = retcode[1];
|
||||
//goto _exit_;
|
||||
}
|
||||
#ifdef CONSOLEOUTPUT
|
||||
printf("\n%s\n",dataName);
|
||||
if (groundTruthLeft)
|
||||
printf("L rms error = %f\npercentage of bad pixels = %f\n",
|
||||
rms_error[0], percentage_of_bad_pixels[0]);
|
||||
if(groundTruthRight)
|
||||
printf("R rms error = %f\npercentage of bad pixels = %f\n",
|
||||
rms_error[1], percentage_of_bad_pixels[1]);
|
||||
#endif
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
IplImage* groundTruth = (i == 0) ? groundTruthLeft : groundTruthRight;
|
||||
if (groundTruth)
|
||||
{
|
||||
if (rms_error[i] > rms_error_thresh)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Big RMS error" );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
//goto _exit_;
|
||||
}
|
||||
if (percentage_of_bad_pixels[i] > percentage_of_bad_pixels_thresh)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Big percentage of bad pixels" );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
//goto _exit_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_exit_:
|
||||
cvReleaseImage(&left);
|
||||
cvReleaseImage(&right);
|
||||
cvReleaseImage(&disparity_left);
|
||||
cvReleaseImage(&disparity_right);
|
||||
cvReleaseImage(&groundTruthLeft);
|
||||
cvReleaseImage(&groundTruthRight);
|
||||
#ifndef LOAD
|
||||
//cvReleaseStereoCorrespondenceGCState(&stereoMatcher);
|
||||
#endif
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_StereoCorrespondenceTestGC stereo_correspondece_test_gc;
|
||||
|
||||
#endif
|
||||
@@ -1,823 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
/*
|
||||
This is a regression test for stereo matching algorithms. This test gets some quality metrics
|
||||
discribed in "A Taxonomy and Evaluation of Dense Two-Frame Stereo Correspondence Algorithms".
|
||||
Daniel Scharstein, Richard Szeliski
|
||||
*/
|
||||
|
||||
#include "cvtest.h"
|
||||
#include <limits>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
const float EVAL_BAD_THRESH = 1.f;
|
||||
const int EVAL_TEXTURELESS_WIDTH = 3;
|
||||
const float EVAL_TEXTURELESS_THRESH = 4.f;
|
||||
const float EVAL_DISP_THRESH = 1.f;
|
||||
const float EVAL_DISP_GAP = 2.f;
|
||||
const int EVAL_DISCONT_WIDTH = 9;
|
||||
const int EVAL_IGNORE_BORDER = 10;
|
||||
|
||||
const int ERROR_KINDS_COUNT = 6;
|
||||
|
||||
//============================== quality measuring functions =================================================
|
||||
|
||||
/*
|
||||
Calculate textureless regions of image (regions where the squared horizontal intensity gradient averaged over
|
||||
a square window of size=evalTexturelessWidth is below a threshold=evalTexturelessThresh) and textured regions.
|
||||
*/
|
||||
void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* texturedMask,
|
||||
int texturelessWidth = EVAL_TEXTURELESS_WIDTH, float texturelessThresh = EVAL_TEXTURELESS_THRESH )
|
||||
{
|
||||
if( !texturelessMask && !texturedMask )
|
||||
return;
|
||||
if( _img.empty() )
|
||||
CV_Error( CV_StsBadArg, "img is empty" );
|
||||
|
||||
Mat img = _img;
|
||||
if( _img.channels() > 1)
|
||||
{
|
||||
Mat tmp; cvtColor( _img, tmp, CV_BGR2GRAY ); img = tmp;
|
||||
}
|
||||
Mat dxI; Sobel( img, dxI, CV_32FC1, 1, 0, 3 );
|
||||
Mat dxI2; pow( dxI / 8.f/*normalize*/, 2, dxI2 );
|
||||
Mat avgDxI2; boxFilter( dxI2, avgDxI2, CV_32FC1, Size(texturelessWidth,texturelessWidth) );
|
||||
|
||||
if( texturelessMask )
|
||||
*texturelessMask = avgDxI2 < texturelessThresh;
|
||||
if( texturedMask )
|
||||
*texturedMask = avgDxI2 >= texturelessThresh;
|
||||
}
|
||||
|
||||
void checkTypeAndSizeOfDisp( const Mat& dispMap, const Size* sz )
|
||||
{
|
||||
if( dispMap.empty() )
|
||||
CV_Error( CV_StsBadArg, "dispMap is empty" );
|
||||
if( dispMap.type() != CV_32FC1 )
|
||||
CV_Error( CV_StsBadArg, "dispMap must have CV_32FC1 type" );
|
||||
if( sz && (dispMap.rows != sz->height || dispMap.cols != sz->width) )
|
||||
CV_Error( CV_StsBadArg, "dispMap has incorrect size" );
|
||||
}
|
||||
|
||||
void checkTypeAndSizeOfMask( const Mat& mask, Size sz )
|
||||
{
|
||||
if( mask.empty() )
|
||||
CV_Error( CV_StsBadArg, "mask is empty" );
|
||||
if( mask.type() != CV_8UC1 )
|
||||
CV_Error( CV_StsBadArg, "mask must have CV_8UC1 type" );
|
||||
if( mask.rows != sz.height || mask.cols != sz.width )
|
||||
CV_Error( CV_StsBadArg, "mask has incorrect size" );
|
||||
}
|
||||
|
||||
void checkDispMapsAndUnknDispMasks( const Mat& leftDispMap, const Mat& rightDispMap,
|
||||
const Mat& leftUnknDispMask, const Mat& rightUnknDispMask )
|
||||
{
|
||||
// check type and size of disparity maps
|
||||
checkTypeAndSizeOfDisp( leftDispMap, 0 );
|
||||
if( !rightDispMap.empty() )
|
||||
{
|
||||
Size sz = leftDispMap.size();
|
||||
checkTypeAndSizeOfDisp( rightDispMap, &sz );
|
||||
}
|
||||
|
||||
// check size and type of unknown disparity maps
|
||||
if( !leftUnknDispMask.empty() )
|
||||
checkTypeAndSizeOfMask( leftUnknDispMask, leftDispMap.size() );
|
||||
if( !rightUnknDispMask.empty() )
|
||||
checkTypeAndSizeOfMask( rightUnknDispMask, rightDispMap.size() );
|
||||
|
||||
// check values of disparity maps (known disparity values musy be positive)
|
||||
double leftMinVal = 0, rightMinVal = 0;
|
||||
if( leftUnknDispMask.empty() )
|
||||
minMaxLoc( leftDispMap, &leftMinVal );
|
||||
else
|
||||
minMaxLoc( leftDispMap, &leftMinVal, 0, 0, 0, ~leftUnknDispMask );
|
||||
if( !rightDispMap.empty() )
|
||||
{
|
||||
if( rightUnknDispMask.empty() )
|
||||
minMaxLoc( rightDispMap, &rightMinVal );
|
||||
else
|
||||
minMaxLoc( rightDispMap, &rightMinVal, 0, 0, 0, ~rightUnknDispMask );
|
||||
}
|
||||
if( leftMinVal < 0 || rightMinVal < 0)
|
||||
CV_Error( CV_StsBadArg, "known disparity values must be positive" );
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate occluded regions of reference image (left image) (regions that are occluded in the matching image (right image),
|
||||
i.e., where the forward-mapped disparity lands at a location with a larger (nearer) disparity) and non occluded regions.
|
||||
*/
|
||||
void computeOcclusionBasedMasks( const Mat& leftDisp, const Mat& _rightDisp,
|
||||
Mat* occludedMask, Mat* nonOccludedMask,
|
||||
const Mat& leftUnknDispMask = Mat(), const Mat& rightUnknDispMask = Mat(),
|
||||
float dispThresh = EVAL_DISP_THRESH )
|
||||
{
|
||||
if( !occludedMask && !nonOccludedMask )
|
||||
return;
|
||||
checkDispMapsAndUnknDispMasks( leftDisp, _rightDisp, leftUnknDispMask, rightUnknDispMask );
|
||||
|
||||
Mat rightDisp;
|
||||
if( _rightDisp.empty() )
|
||||
{
|
||||
if( !rightUnknDispMask.empty() )
|
||||
CV_Error( CV_StsBadArg, "rightUnknDispMask must be empty if _rightDisp is empty" );
|
||||
rightDisp.create(leftDisp.size(), CV_32FC1);
|
||||
rightDisp.setTo(Scalar::all(0) );
|
||||
for( int leftY = 0; leftY < leftDisp.rows; leftY++ )
|
||||
{
|
||||
for( int leftX = 0; leftX < leftDisp.cols; leftX++ )
|
||||
{
|
||||
if( !leftUnknDispMask.empty() && leftUnknDispMask.at<uchar>(leftY,leftX) )
|
||||
continue;
|
||||
float leftDispVal = leftDisp.at<float>(leftY, leftX);
|
||||
int rightX = leftX - cvRound(leftDispVal), rightY = leftY;
|
||||
if( rightX >= 0)
|
||||
rightDisp.at<float>(rightY,rightX) = max(rightDisp.at<float>(rightY,rightX), leftDispVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
_rightDisp.copyTo(rightDisp);
|
||||
|
||||
if( occludedMask )
|
||||
{
|
||||
occludedMask->create(leftDisp.size(), CV_8UC1);
|
||||
occludedMask->setTo(Scalar::all(0) );
|
||||
}
|
||||
if( nonOccludedMask )
|
||||
{
|
||||
nonOccludedMask->create(leftDisp.size(), CV_8UC1);
|
||||
nonOccludedMask->setTo(Scalar::all(0) );
|
||||
}
|
||||
for( int leftY = 0; leftY < leftDisp.rows; leftY++ )
|
||||
{
|
||||
for( int leftX = 0; leftX < leftDisp.cols; leftX++ )
|
||||
{
|
||||
if( !leftUnknDispMask.empty() && leftUnknDispMask.at<uchar>(leftY,leftX) )
|
||||
continue;
|
||||
float leftDispVal = leftDisp.at<float>(leftY, leftX);
|
||||
int rightX = leftX - cvRound(leftDispVal), rightY = leftY;
|
||||
if( rightX < 0 && occludedMask )
|
||||
occludedMask->at<uchar>(leftY, leftX) = 255;
|
||||
else
|
||||
{
|
||||
if( !rightUnknDispMask.empty() && rightUnknDispMask.at<uchar>(rightY,rightX) )
|
||||
continue;
|
||||
float rightDispVal = rightDisp.at<float>(rightY, rightX);
|
||||
if( rightDispVal > leftDispVal + dispThresh )
|
||||
{
|
||||
if( occludedMask )
|
||||
occludedMask->at<uchar>(leftY, leftX) = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nonOccludedMask )
|
||||
nonOccludedMask->at<uchar>(leftY, leftX) = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate depth discontinuty regions: pixels whose neiboring disparities differ by more than
|
||||
dispGap, dilated by window of width discontWidth.
|
||||
*/
|
||||
void computeDepthDiscontMask( const Mat& disp, Mat& depthDiscontMask, const Mat& unknDispMask = Mat(),
|
||||
float dispGap = EVAL_DISP_GAP, int discontWidth = EVAL_DISCONT_WIDTH )
|
||||
{
|
||||
if( disp.empty() )
|
||||
CV_Error( CV_StsBadArg, "disp is empty" );
|
||||
if( disp.type() != CV_32FC1 )
|
||||
CV_Error( CV_StsBadArg, "disp must have CV_32FC1 type" );
|
||||
if( !unknDispMask.empty() )
|
||||
checkTypeAndSizeOfMask( unknDispMask, disp.size() );
|
||||
|
||||
Mat curDisp; disp.copyTo( curDisp );
|
||||
if( !unknDispMask.empty() )
|
||||
curDisp.setTo( Scalar(-numeric_limits<float>::max()), unknDispMask );
|
||||
Mat maxNeighbDisp; dilate( curDisp, maxNeighbDisp, Mat(3, 3, CV_8UC1, Scalar(1)) );
|
||||
if( !unknDispMask.empty() )
|
||||
curDisp.setTo( Scalar(numeric_limits<float>::max()), unknDispMask );
|
||||
Mat minNeighbDisp; erode( curDisp, minNeighbDisp, Mat(3, 3, CV_8UC1, Scalar(1)) );
|
||||
depthDiscontMask = max( (Mat)(maxNeighbDisp-disp), (Mat)(disp-minNeighbDisp) ) > dispGap;
|
||||
if( !unknDispMask.empty() )
|
||||
depthDiscontMask &= ~unknDispMask;
|
||||
dilate( depthDiscontMask, depthDiscontMask, Mat(discontWidth, discontWidth, CV_8UC1, Scalar(1)) );
|
||||
}
|
||||
|
||||
/*
|
||||
Get evaluation masks excluding a border.
|
||||
*/
|
||||
Mat getBorderedMask( Size maskSize, int border = EVAL_IGNORE_BORDER )
|
||||
{
|
||||
CV_Assert( border >= 0 );
|
||||
Mat mask(maskSize, CV_8UC1, Scalar(0));
|
||||
int w = maskSize.width - 2*border, h = maskSize.height - 2*border;
|
||||
if( w < 0 || h < 0 )
|
||||
mask.setTo(Scalar(0));
|
||||
else
|
||||
mask( Rect(Point(border,border),Size(w,h)) ).setTo(Scalar(255));
|
||||
return mask;
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate root-mean-squared error between the computed disparity map (computedDisp) and ground truth map (groundTruthDisp).
|
||||
*/
|
||||
float dispRMS( const Mat& computedDisp, const Mat& groundTruthDisp, const Mat& mask )
|
||||
{
|
||||
checkTypeAndSizeOfDisp( groundTruthDisp, 0 );
|
||||
Size sz = groundTruthDisp.size();
|
||||
checkTypeAndSizeOfDisp( computedDisp, &sz );
|
||||
|
||||
int pointsCount = sz.height*sz.width;
|
||||
if( !mask.empty() )
|
||||
{
|
||||
checkTypeAndSizeOfMask( mask, sz );
|
||||
pointsCount = countNonZero(mask);
|
||||
}
|
||||
return 1.f/sqrt((float)pointsCount) * (float)norm(computedDisp, groundTruthDisp, NORM_L2, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
Calculate fraction of bad matching pixels.
|
||||
*/
|
||||
float badMatchPxlsFraction( const Mat& computedDisp, const Mat& groundTruthDisp, const Mat& mask,
|
||||
float _badThresh = EVAL_BAD_THRESH )
|
||||
{
|
||||
int badThresh = cvRound(_badThresh);
|
||||
checkTypeAndSizeOfDisp( groundTruthDisp, 0 );
|
||||
Size sz = groundTruthDisp.size();
|
||||
checkTypeAndSizeOfDisp( computedDisp, &sz );
|
||||
|
||||
Mat badPxlsMap;
|
||||
absdiff( computedDisp, groundTruthDisp, badPxlsMap );
|
||||
badPxlsMap = badPxlsMap > badThresh;
|
||||
int pointsCount = sz.height*sz.width;
|
||||
if( !mask.empty() )
|
||||
{
|
||||
checkTypeAndSizeOfMask( mask, sz );
|
||||
badPxlsMap = badPxlsMap & mask;
|
||||
pointsCount = countNonZero(mask);
|
||||
}
|
||||
return 1.f/pointsCount * countNonZero(badPxlsMap);
|
||||
}
|
||||
|
||||
//===================== regression test for stereo matching algorithms ==============================
|
||||
|
||||
const string ALGORITHMS_DIR = "stereomatching/algorithms/";
|
||||
const string DATASETS_DIR = "stereomatching/datasets/";
|
||||
const string DATASETS_FILE = "datasets.xml";
|
||||
|
||||
const string RUN_PARAMS_FILE = "_params.xml";
|
||||
const string RESULT_FILE = "_res.xml";
|
||||
|
||||
const string LEFT_IMG_NAME = "im2.png";
|
||||
const string RIGHT_IMG_NAME = "im6.png";
|
||||
const string TRUE_LEFT_DISP_NAME = "disp2.png";
|
||||
const string TRUE_RIGHT_DISP_NAME = "disp6.png";
|
||||
|
||||
string ERROR_PREFIXES[] = { "borderedAll",
|
||||
"borderedNoOccl",
|
||||
"borderedOccl",
|
||||
"borderedTextured",
|
||||
"borderedTextureless",
|
||||
"borderedDepthDiscont" }; // size of ERROR_KINDS_COUNT
|
||||
|
||||
|
||||
const string RMS_STR = "RMS";
|
||||
const string BAD_PXLS_FRACTION_STR = "BadPxlsFraction";
|
||||
|
||||
class QualityEvalParams
|
||||
{
|
||||
public:
|
||||
QualityEvalParams() { setDefaults(); }
|
||||
QualityEvalParams( int _ignoreBorder )
|
||||
{
|
||||
setDefaults();
|
||||
ignoreBorder = _ignoreBorder;
|
||||
}
|
||||
void setDefaults()
|
||||
{
|
||||
badThresh = EVAL_BAD_THRESH;
|
||||
texturelessWidth = EVAL_TEXTURELESS_WIDTH;
|
||||
texturelessThresh = EVAL_TEXTURELESS_THRESH;
|
||||
dispThresh = EVAL_DISP_THRESH;
|
||||
dispGap = EVAL_DISP_GAP;
|
||||
discontWidth = EVAL_DISCONT_WIDTH;
|
||||
ignoreBorder = EVAL_IGNORE_BORDER;
|
||||
}
|
||||
float badThresh;
|
||||
int texturelessWidth;
|
||||
float texturelessThresh;
|
||||
float dispThresh;
|
||||
float dispGap;
|
||||
int discontWidth;
|
||||
int ignoreBorder;
|
||||
};
|
||||
|
||||
class CV_StereoMatchingTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_StereoMatchingTest( const char* testName ) : CvTest( testName, "stereo-matching" )
|
||||
{ rmsEps.resize( ERROR_KINDS_COUNT, 0.01f ); fracEps.resize( ERROR_KINDS_COUNT, 1.e-6f ); }
|
||||
protected:
|
||||
// assumed that left image is a reference image
|
||||
virtual int runStereoMatchingAlgorithm( const Mat& leftImg, const Mat& rightImg,
|
||||
Mat& leftDisp, Mat& rightDisp, int caseIdx ) = 0; // return ignored border width
|
||||
|
||||
int readDatasetsParams( FileStorage& fs );
|
||||
virtual int readRunParams( FileStorage& fs );
|
||||
void writeErrors( const string& errName, const vector<float>& errors, FileStorage* fs = 0 );
|
||||
void readErrors( FileNode& fn, const string& errName, vector<float>& errors );
|
||||
int compareErrors( const vector<float>& calcErrors, const vector<float>& validErrors,
|
||||
const vector<float>& eps, const string& errName );
|
||||
int processStereoMatchingResults( FileStorage& fs, int caseIdx, bool isWrite,
|
||||
const Mat& leftImg, const Mat& rightImg,
|
||||
const Mat& trueLeftDisp, const Mat& trueRightDisp,
|
||||
const Mat& leftDisp, const Mat& rightDisp,
|
||||
const QualityEvalParams& qualityEvalParams );
|
||||
void run( int );
|
||||
|
||||
vector<float> rmsEps;
|
||||
vector<float> fracEps;
|
||||
|
||||
struct DatasetParams
|
||||
{
|
||||
int dispScaleFactor;
|
||||
int dispUnknVal;
|
||||
};
|
||||
map<string, DatasetParams> datasetsParams;
|
||||
|
||||
vector<string> caseNames;
|
||||
vector<string> caseDatasets;
|
||||
};
|
||||
|
||||
void CV_StereoMatchingTest::run(int)
|
||||
{
|
||||
string dataPath = ts->get_data_path();
|
||||
string algorithmName = name;
|
||||
assert( !algorithmName.empty() );
|
||||
if( dataPath.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "dataPath is empty" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ARG_CHECK );
|
||||
return;
|
||||
}
|
||||
|
||||
FileStorage datasetsFS( dataPath + DATASETS_DIR + DATASETS_FILE, FileStorage::READ );
|
||||
int code = readDatasetsParams( datasetsFS );
|
||||
if( code != CvTS::OK )
|
||||
{
|
||||
ts->set_failed_test_info( code );
|
||||
return;
|
||||
}
|
||||
FileStorage runParamsFS( dataPath + ALGORITHMS_DIR + algorithmName + RUN_PARAMS_FILE, FileStorage::READ );
|
||||
code = readRunParams( runParamsFS );
|
||||
if( code != CvTS::OK )
|
||||
{
|
||||
ts->set_failed_test_info( code );
|
||||
return;
|
||||
}
|
||||
|
||||
string fullResultFilename = dataPath + ALGORITHMS_DIR + algorithmName + RESULT_FILE;
|
||||
FileStorage resFS( fullResultFilename, FileStorage::READ );
|
||||
bool isWrite = true; // write or compare results
|
||||
if( resFS.isOpened() )
|
||||
isWrite = false;
|
||||
else
|
||||
{
|
||||
resFS.open( fullResultFilename, FileStorage::WRITE );
|
||||
if( !resFS.isOpened() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "file %s can not be read or written\n", fullResultFilename.c_str() );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ARG_CHECK );
|
||||
return;
|
||||
}
|
||||
resFS << "stereo_matching" << "{";
|
||||
}
|
||||
|
||||
int progress = 0, caseCount = (int)caseNames.size();
|
||||
for( int ci = 0; ci < caseCount; ci++)
|
||||
{
|
||||
progress = update_progress( progress, ci, caseCount, 0 );
|
||||
|
||||
string datasetName = caseDatasets[ci];
|
||||
string datasetFullDirName = dataPath + DATASETS_DIR + datasetName + "/";
|
||||
Mat leftImg = imread(datasetFullDirName + LEFT_IMG_NAME);
|
||||
Mat rightImg = imread(datasetFullDirName + RIGHT_IMG_NAME);
|
||||
Mat trueLeftDisp = imread(datasetFullDirName + TRUE_LEFT_DISP_NAME, 0);
|
||||
Mat trueRightDisp = imread(datasetFullDirName + TRUE_RIGHT_DISP_NAME, 0);
|
||||
|
||||
if( leftImg.empty() || rightImg.empty() || trueLeftDisp.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "images or left ground-truth disparities of dataset %s can not be read", datasetName.c_str() );
|
||||
code = CvTS::FAIL_INVALID_TEST_DATA;
|
||||
continue;
|
||||
}
|
||||
int dispScaleFactor = datasetsParams[datasetName].dispScaleFactor;
|
||||
Mat tmp; trueLeftDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor ); trueLeftDisp = tmp; tmp.release();
|
||||
if( !trueRightDisp.empty() )
|
||||
trueRightDisp.convertTo( tmp, CV_32FC1, 1.f/dispScaleFactor ); trueRightDisp = tmp; tmp.release();
|
||||
|
||||
Mat leftDisp, rightDisp;
|
||||
int ignBorder = max(runStereoMatchingAlgorithm(leftImg, rightImg, leftDisp, rightDisp, ci), EVAL_IGNORE_BORDER);
|
||||
leftDisp.convertTo( tmp, CV_32FC1 ); leftDisp = tmp; tmp.release();
|
||||
rightDisp.convertTo( tmp, CV_32FC1 ); rightDisp = tmp; tmp.release();
|
||||
|
||||
int tempCode = processStereoMatchingResults( resFS, ci, isWrite,
|
||||
leftImg, rightImg, trueLeftDisp, trueRightDisp, leftDisp, rightDisp, QualityEvalParams(ignBorder));
|
||||
code = tempCode==CvTS::OK ? code : tempCode;
|
||||
}
|
||||
|
||||
if( isWrite )
|
||||
resFS << "}"; // "stereo_matching"
|
||||
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
void calcErrors( const Mat& leftImg, const Mat& /*rightImg*/,
|
||||
const Mat& trueLeftDisp, const Mat& trueRightDisp,
|
||||
const Mat& trueLeftUnknDispMask, const Mat& trueRightUnknDispMask,
|
||||
const Mat& calcLeftDisp, const Mat& /*calcRightDisp*/,
|
||||
vector<float>& rms, vector<float>& badPxlsFractions,
|
||||
const QualityEvalParams& qualityEvalParams )
|
||||
{
|
||||
Mat texturelessMask, texturedMask;
|
||||
computeTextureBasedMasks( leftImg, &texturelessMask, &texturedMask,
|
||||
qualityEvalParams.texturelessWidth, qualityEvalParams.texturelessThresh );
|
||||
Mat occludedMask, nonOccludedMask;
|
||||
computeOcclusionBasedMasks( trueLeftDisp, trueRightDisp, &occludedMask, &nonOccludedMask,
|
||||
trueLeftUnknDispMask, trueRightUnknDispMask, qualityEvalParams.dispThresh);
|
||||
Mat depthDiscontMask;
|
||||
computeDepthDiscontMask( trueLeftDisp, depthDiscontMask, trueLeftUnknDispMask,
|
||||
qualityEvalParams.dispGap, qualityEvalParams.discontWidth);
|
||||
|
||||
Mat borderedKnownMask = getBorderedMask( leftImg.size(), qualityEvalParams.ignoreBorder ) & ~trueLeftUnknDispMask;
|
||||
|
||||
nonOccludedMask &= borderedKnownMask;
|
||||
occludedMask &= borderedKnownMask;
|
||||
texturedMask &= nonOccludedMask; // & borderedKnownMask
|
||||
texturelessMask &= nonOccludedMask; // & borderedKnownMask
|
||||
depthDiscontMask &= nonOccludedMask; // & borderedKnownMask
|
||||
|
||||
rms.resize(ERROR_KINDS_COUNT);
|
||||
rms[0] = dispRMS( calcLeftDisp, trueLeftDisp, borderedKnownMask );
|
||||
rms[1] = dispRMS( calcLeftDisp, trueLeftDisp, nonOccludedMask );
|
||||
rms[2] = dispRMS( calcLeftDisp, trueLeftDisp, occludedMask );
|
||||
rms[3] = dispRMS( calcLeftDisp, trueLeftDisp, texturedMask );
|
||||
rms[4] = dispRMS( calcLeftDisp, trueLeftDisp, texturelessMask );
|
||||
rms[5] = dispRMS( calcLeftDisp, trueLeftDisp, depthDiscontMask );
|
||||
|
||||
badPxlsFractions.resize(ERROR_KINDS_COUNT);
|
||||
badPxlsFractions[0] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, borderedKnownMask, qualityEvalParams.badThresh );
|
||||
badPxlsFractions[1] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, nonOccludedMask, qualityEvalParams.badThresh );
|
||||
badPxlsFractions[2] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, occludedMask, qualityEvalParams.badThresh );
|
||||
badPxlsFractions[3] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, texturedMask, qualityEvalParams.badThresh );
|
||||
badPxlsFractions[4] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, texturelessMask, qualityEvalParams.badThresh );
|
||||
badPxlsFractions[5] = badMatchPxlsFraction( calcLeftDisp, trueLeftDisp, depthDiscontMask, qualityEvalParams.badThresh );
|
||||
}
|
||||
|
||||
int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int caseIdx, bool isWrite,
|
||||
const Mat& leftImg, const Mat& rightImg,
|
||||
const Mat& trueLeftDisp, const Mat& trueRightDisp,
|
||||
const Mat& leftDisp, const Mat& rightDisp,
|
||||
const QualityEvalParams& qualityEvalParams )
|
||||
{
|
||||
// rightDisp is not used in current test virsion
|
||||
int code = CvTS::OK;
|
||||
assert( fs.isOpened() );
|
||||
assert( trueLeftDisp.type() == CV_32FC1 && trueRightDisp.type() == CV_32FC1 );
|
||||
assert( leftDisp.type() == CV_32FC1 && rightDisp.type() == CV_32FC1 );
|
||||
|
||||
// get masks for unknown ground truth disparity values
|
||||
Mat leftUnknMask, rightUnknMask;
|
||||
DatasetParams params = datasetsParams[caseDatasets[caseIdx]];
|
||||
absdiff( trueLeftDisp, Scalar(params.dispUnknVal), leftUnknMask );
|
||||
leftUnknMask = leftUnknMask < numeric_limits<float>::epsilon();
|
||||
assert(leftUnknMask.type() == CV_8UC1);
|
||||
if( !trueRightDisp.empty() )
|
||||
{
|
||||
absdiff( trueRightDisp, Scalar(params.dispUnknVal), rightUnknMask );
|
||||
rightUnknMask = rightUnknMask < numeric_limits<float>::epsilon();
|
||||
assert(leftUnknMask.type() == CV_8UC1);
|
||||
}
|
||||
|
||||
// calculate errors
|
||||
vector<float> rmss, badPxlsFractions;
|
||||
calcErrors( leftImg, rightImg, trueLeftDisp, trueRightDisp, leftUnknMask, rightUnknMask,
|
||||
leftDisp, rightDisp, rmss, badPxlsFractions, qualityEvalParams );
|
||||
|
||||
if( isWrite )
|
||||
{
|
||||
fs << caseNames[caseIdx] << "{";
|
||||
cvWriteComment( fs.fs, RMS_STR.c_str(), 0 );
|
||||
writeErrors( RMS_STR, rmss, &fs );
|
||||
cvWriteComment( fs.fs, BAD_PXLS_FRACTION_STR.c_str(), 0 );
|
||||
writeErrors( BAD_PXLS_FRACTION_STR, badPxlsFractions, &fs );
|
||||
fs << "}"; // datasetName
|
||||
}
|
||||
else // compare
|
||||
{
|
||||
ts->printf( CvTS::LOG, "\nquality of case named %s\n", caseNames[caseIdx].c_str() );
|
||||
ts->printf( CvTS::LOG, "%s\n", RMS_STR.c_str() );
|
||||
writeErrors( RMS_STR, rmss );
|
||||
ts->printf( CvTS::LOG, "%s\n", BAD_PXLS_FRACTION_STR.c_str() );
|
||||
writeErrors( BAD_PXLS_FRACTION_STR, badPxlsFractions );
|
||||
|
||||
FileNode fn = fs.getFirstTopLevelNode()[caseNames[caseIdx]];
|
||||
vector<float> validRmss, validBadPxlsFractions;
|
||||
|
||||
readErrors( fn, RMS_STR, validRmss );
|
||||
readErrors( fn, BAD_PXLS_FRACTION_STR, validBadPxlsFractions );
|
||||
int tempCode = compareErrors( rmss, validRmss, rmsEps, RMS_STR );
|
||||
code = tempCode==CvTS::OK ? code : tempCode;
|
||||
tempCode = compareErrors( badPxlsFractions, validBadPxlsFractions, fracEps, BAD_PXLS_FRACTION_STR );
|
||||
code = tempCode==CvTS::OK ? code : tempCode;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int CV_StereoMatchingTest::readDatasetsParams( FileStorage& fs )
|
||||
{
|
||||
if( !fs.isOpened() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "datasetsParams can not be read " );
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
datasetsParams.clear();
|
||||
FileNode fn = fs.getFirstTopLevelNode();
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=3 )
|
||||
{
|
||||
string name = fn[i];
|
||||
DatasetParams params;
|
||||
string sf = fn[i+1]; params.dispScaleFactor = atoi(sf.c_str());
|
||||
string uv = fn[i+2]; params.dispUnknVal = atoi(uv.c_str());
|
||||
datasetsParams[name] = params;
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int CV_StereoMatchingTest::readRunParams( FileStorage& fs )
|
||||
{
|
||||
if( !fs.isOpened() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "runParams can not be read " );
|
||||
return CvTS::FAIL_INVALID_TEST_DATA;
|
||||
}
|
||||
caseNames.clear();;
|
||||
caseDatasets.clear();
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_StereoMatchingTest::writeErrors( const string& errName, const vector<float>& errors, FileStorage* fs )
|
||||
{
|
||||
assert( (int)errors.size() == ERROR_KINDS_COUNT );
|
||||
vector<float>::const_iterator it = errors.begin();
|
||||
if( fs )
|
||||
for( int i = 0; i < ERROR_KINDS_COUNT; i++, ++it )
|
||||
*fs << ERROR_PREFIXES[i] + errName << *it;
|
||||
else
|
||||
for( int i = 0; i < ERROR_KINDS_COUNT; i++, ++it )
|
||||
ts->printf( CvTS::LOG, "%s = %f\n", string(ERROR_PREFIXES[i]+errName).c_str(), *it );
|
||||
}
|
||||
|
||||
void CV_StereoMatchingTest::readErrors( FileNode& fn, const string& errName, vector<float>& errors )
|
||||
{
|
||||
errors.resize( ERROR_KINDS_COUNT );
|
||||
vector<float>::iterator it = errors.begin();
|
||||
for( int i = 0; i < ERROR_KINDS_COUNT; i++, ++it )
|
||||
fn[ERROR_PREFIXES[i]+errName] >> *it;
|
||||
}
|
||||
|
||||
int CV_StereoMatchingTest::compareErrors( const vector<float>& calcErrors, const vector<float>& validErrors,
|
||||
const vector<float>& eps, const string& errName )
|
||||
{
|
||||
assert( (int)calcErrors.size() == ERROR_KINDS_COUNT );
|
||||
assert( (int)validErrors.size() == ERROR_KINDS_COUNT );
|
||||
assert( (int)eps.size() == ERROR_KINDS_COUNT );
|
||||
vector<float>::const_iterator calcIt = calcErrors.begin(),
|
||||
validIt = validErrors.begin(),
|
||||
epsIt = eps.begin();
|
||||
bool ok = true;
|
||||
for( int i = 0; i < ERROR_KINDS_COUNT; i++, ++calcIt, ++validIt, ++epsIt )
|
||||
if( *calcIt - *validIt > *epsIt )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of %s (valid=%f; calc=%f)\n", string(ERROR_PREFIXES[i]+errName).c_str(), *validIt, *calcIt );
|
||||
ok = false;
|
||||
}
|
||||
return ok ? CvTS::OK : CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
//----------------------------------- StereoBM test -----------------------------------------------------
|
||||
|
||||
class CV_StereoBMTest : public CV_StereoMatchingTest
|
||||
{
|
||||
public:
|
||||
CV_StereoBMTest() : CV_StereoMatchingTest( "stereobm" )
|
||||
{ fill(rmsEps.begin(), rmsEps.end(), 0.4f); fill(fracEps.begin(), fracEps.end(), 0.022f); }
|
||||
|
||||
protected:
|
||||
struct RunParams
|
||||
{
|
||||
int ndisp;
|
||||
int winSize;
|
||||
};
|
||||
vector<RunParams> caseRunParams;
|
||||
|
||||
virtual int readRunParams( FileStorage& fs )
|
||||
{
|
||||
int code = CV_StereoMatchingTest::readRunParams( fs );
|
||||
FileNode fn = fs.getFirstTopLevelNode();
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=4 )
|
||||
{
|
||||
string caseName = fn[i], datasetName = fn[i+1];
|
||||
RunParams params;
|
||||
string ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
string winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
caseNames.push_back( caseName );
|
||||
caseDatasets.push_back( datasetName );
|
||||
caseRunParams.push_back( params );
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
virtual int runStereoMatchingAlgorithm( const Mat& _leftImg, const Mat& _rightImg,
|
||||
Mat& leftDisp, Mat& /*rightDisp*/, int caseIdx )
|
||||
{
|
||||
RunParams params = caseRunParams[caseIdx];
|
||||
assert( params.ndisp%16 == 0 );
|
||||
assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 );
|
||||
Mat leftImg; cvtColor( _leftImg, leftImg, CV_BGR2GRAY );
|
||||
Mat rightImg; cvtColor( _rightImg, rightImg, CV_BGR2GRAY );
|
||||
|
||||
StereoBM bm( StereoBM::BASIC_PRESET, params.ndisp, params.winSize );
|
||||
bm( leftImg, rightImg, leftDisp, CV_32F );
|
||||
return params.winSize/2;
|
||||
}
|
||||
};
|
||||
|
||||
CV_StereoBMTest stereoBM;
|
||||
|
||||
//----------------------------------- StereoGC test -----------------------------------------------------
|
||||
|
||||
class CV_StereoGCTest : public CV_StereoMatchingTest
|
||||
{
|
||||
public:
|
||||
CV_StereoGCTest() : CV_StereoMatchingTest( "stereogc" )
|
||||
{
|
||||
fill(rmsEps.begin(), rmsEps.end(), 3.f);
|
||||
fracEps[0] = 0.05f; // all
|
||||
fracEps[1] = 0.05f; // noOccl
|
||||
fracEps[2] = 0.25f; // occl
|
||||
fracEps[3] = 0.05f; // textured
|
||||
fracEps[4] = 0.10f; // textureless
|
||||
fracEps[5] = 0.10f; // borderedDepthDiscont
|
||||
}
|
||||
protected:
|
||||
struct RunParams
|
||||
{
|
||||
int ndisp;
|
||||
int iterCount;
|
||||
};
|
||||
vector<RunParams> caseRunParams;
|
||||
|
||||
virtual int readRunParams( FileStorage& fs )
|
||||
{
|
||||
int code = CV_StereoMatchingTest::readRunParams(fs);
|
||||
FileNode fn = fs.getFirstTopLevelNode();
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=4 )
|
||||
{
|
||||
string caseName = fn[i], datasetName = fn[i+1];
|
||||
RunParams params;
|
||||
string ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
string iterCount = fn[i+3]; params.iterCount = atoi(iterCount.c_str());
|
||||
caseNames.push_back( caseName );
|
||||
caseDatasets.push_back( datasetName );
|
||||
caseRunParams.push_back( params );
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
virtual int runStereoMatchingAlgorithm( const Mat& _leftImg, const Mat& _rightImg,
|
||||
Mat& leftDisp, Mat& rightDisp, int caseIdx )
|
||||
{
|
||||
RunParams params = caseRunParams[caseIdx];
|
||||
assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 );
|
||||
Mat leftImg, rightImg, tmp;
|
||||
cvtColor( _leftImg, leftImg, CV_BGR2GRAY );
|
||||
cvtColor( _rightImg, rightImg, CV_BGR2GRAY );
|
||||
|
||||
leftDisp.create( leftImg.size(), CV_16SC1 );
|
||||
rightDisp.create( rightImg.size(), CV_16SC1 );
|
||||
|
||||
CvMat _limg = leftImg, _rimg = rightImg, _ldisp = leftDisp, _rdisp = rightDisp;
|
||||
CvStereoGCState *state = cvCreateStereoGCState( params.ndisp, params.iterCount );
|
||||
cvFindStereoCorrespondenceGC( &_limg, &_rimg, &_ldisp, &_rdisp, state );
|
||||
cvReleaseStereoGCState( &state );
|
||||
|
||||
leftDisp = - leftDisp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CV_StereoGCTest stereoGC;
|
||||
|
||||
//----------------------------------- StereoSGBM test -----------------------------------------------------
|
||||
|
||||
class CV_StereoSGBMTest : public CV_StereoMatchingTest
|
||||
{
|
||||
public:
|
||||
CV_StereoSGBMTest() : CV_StereoMatchingTest( "stereosgbm" )
|
||||
{ fill(rmsEps.begin(), rmsEps.end(), 0.25f); fill(fracEps.begin(), fracEps.end(), 0.01f); }
|
||||
|
||||
protected:
|
||||
struct RunParams
|
||||
{
|
||||
int ndisp;
|
||||
int winSize;
|
||||
bool fullDP;
|
||||
};
|
||||
vector<RunParams> caseRunParams;
|
||||
|
||||
virtual int readRunParams( FileStorage& fs )
|
||||
{
|
||||
int code = CV_StereoMatchingTest::readRunParams(fs);
|
||||
FileNode fn = fs.getFirstTopLevelNode();
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=5 )
|
||||
{
|
||||
string caseName = fn[i], datasetName = fn[i+1];
|
||||
RunParams params;
|
||||
string ndisp = fn[i+2]; params.ndisp = atoi(ndisp.c_str());
|
||||
string winSize = fn[i+3]; params.winSize = atoi(winSize.c_str());
|
||||
string fullDP = fn[i+4]; params.fullDP = atoi(fullDP.c_str()) == 0 ? false : true;
|
||||
caseNames.push_back( caseName );
|
||||
caseDatasets.push_back( datasetName );
|
||||
caseRunParams.push_back( params );
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
virtual int runStereoMatchingAlgorithm( const Mat& leftImg, const Mat& rightImg,
|
||||
Mat& leftDisp, Mat& /*rightDisp*/, int caseIdx )
|
||||
{
|
||||
RunParams params = caseRunParams[caseIdx];
|
||||
assert( params.ndisp%16 == 0 );
|
||||
StereoSGBM sgbm( 0, params.ndisp, params.winSize, 10*params.winSize*params.winSize, 40*params.winSize*params.winSize,
|
||||
1, 63, 10, 100, 32, params.fullDP );
|
||||
sgbm( leftImg, rightImg, leftDisp );
|
||||
assert( leftDisp.type() == CV_16SC1 );
|
||||
leftDisp/=16;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
CV_StereoSGBMTest stereoSGBM;
|
||||
|
||||
@@ -1,299 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
|
||||
class CV_SubdivTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_SubdivTest();
|
||||
~CV_SubdivTest();
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
int read_params( CvFileStorage* fs );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void run_func();
|
||||
|
||||
int min_log_img_size, max_log_img_size;
|
||||
CvSize img_size;
|
||||
int min_log_point_count;
|
||||
int max_log_point_count;
|
||||
int point_count;
|
||||
CvSubdiv2D* subdiv;
|
||||
CvMemStorage* storage;
|
||||
};
|
||||
|
||||
|
||||
CV_SubdivTest::CV_SubdivTest() :
|
||||
CvTest( "subdiv",
|
||||
"cvCreateSubdivDelaunay2D, cvSubdivDelaunay2DInsert, cvSubdiv2DLocate, "
|
||||
"cvCalcSubdivVoronoi2D, cvFindNearestPoint2D" )
|
||||
{
|
||||
test_case_count = 100;
|
||||
min_log_point_count = 1;
|
||||
max_log_point_count = 10;
|
||||
min_log_img_size = 1;
|
||||
max_log_img_size = 10;
|
||||
|
||||
storage = 0;
|
||||
}
|
||||
|
||||
|
||||
CV_SubdivTest::~CV_SubdivTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_SubdivTest::clear()
|
||||
{
|
||||
CvTest::clear();
|
||||
cvReleaseMemStorage( &storage );
|
||||
}
|
||||
|
||||
|
||||
int CV_SubdivTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
CvTest::write_default_params( fs );
|
||||
if( ts->get_testing_mode() != CvTS::TIMING_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
write_param( fs, "min_log_point_count", min_log_point_count );
|
||||
write_param( fs, "max_log_point_count", max_log_point_count );
|
||||
write_param( fs, "min_log_img_size", min_log_img_size );
|
||||
write_param( fs, "max_log_img_size", max_log_img_size );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_SubdivTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvTest::read_params( fs );
|
||||
int t;
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
test_case_count = cvReadInt( find_param( fs, "test_case_count" ), test_case_count );
|
||||
min_log_point_count = cvReadInt( find_param( fs, "min_log_point_count" ), min_log_point_count );
|
||||
max_log_point_count = cvReadInt( find_param( fs, "max_log_point_count" ), max_log_point_count );
|
||||
min_log_img_size = cvReadInt( find_param( fs, "min_log_img_size" ), min_log_img_size );
|
||||
max_log_img_size = cvReadInt( find_param( fs, "max_log_img_size" ), max_log_img_size );
|
||||
|
||||
min_log_point_count = cvTsClipInt( min_log_point_count, 1, 10 );
|
||||
max_log_point_count = cvTsClipInt( max_log_point_count, 1, 10 );
|
||||
if( min_log_point_count > max_log_point_count )
|
||||
CV_SWAP( min_log_point_count, max_log_point_count, t );
|
||||
|
||||
min_log_img_size = cvTsClipInt( min_log_img_size, 1, 10 );
|
||||
max_log_img_size = cvTsClipInt( max_log_img_size, 1, 10 );
|
||||
if( min_log_img_size > max_log_img_size )
|
||||
CV_SWAP( min_log_img_size, max_log_img_size, t );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_SubdivTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int code = CvTest::prepare_test_case( test_case_idx );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
clear();
|
||||
|
||||
point_count = cvRound(exp((cvTsRandReal(rng)*
|
||||
(max_log_point_count - min_log_point_count) + min_log_point_count)*CV_LOG2));
|
||||
img_size.width = cvRound(exp((cvTsRandReal(rng)*
|
||||
(max_log_img_size - min_log_img_size) + min_log_img_size)*CV_LOG2));
|
||||
img_size.height = cvRound(exp((cvTsRandReal(rng)*
|
||||
(max_log_img_size - min_log_img_size) + min_log_img_size)*CV_LOG2));
|
||||
|
||||
storage = cvCreateMemStorage( 1 << 10 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_SubdivTest::run_func()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// the whole testing is done here, run_func() is not utilized in this test
|
||||
int CV_SubdivTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int j, k, real_count = point_count;
|
||||
double xrange = img_size.width*(1 - FLT_EPSILON);
|
||||
double yrange = img_size.height*(1 - FLT_EPSILON);
|
||||
|
||||
subdiv = subdiv = cvCreateSubdivDelaunay2D(
|
||||
cvRect( 0, 0, img_size.width, img_size.height ), storage );
|
||||
|
||||
CvSeq* seq = cvCreateSeq( 0, sizeof(*seq), sizeof(CvPoint2D32f), storage );
|
||||
CvSeqWriter writer;
|
||||
cvStartAppendToSeq( seq, &writer );
|
||||
|
||||
// insert random points
|
||||
for( j = 0; j < point_count; j++ )
|
||||
{
|
||||
CvPoint2D32f pt;
|
||||
CvSubdiv2DPoint* point;
|
||||
|
||||
pt.x = (float)(cvTsRandReal(rng)*xrange);
|
||||
pt.y = (float)(cvTsRandReal(rng)*yrange);
|
||||
|
||||
CvSubdiv2DPointLocation loc =
|
||||
cvSubdiv2DLocate( subdiv, pt, 0, &point );
|
||||
|
||||
if( loc == CV_PTLOC_VERTEX )
|
||||
{
|
||||
int index = cvSeqElemIdx( (CvSeq*)subdiv, point );
|
||||
CvPoint2D32f* pt1;
|
||||
cvFlushSeqWriter( &writer );
|
||||
pt1 = (CvPoint2D32f*)cvGetSeqElem( seq, index - 3 );
|
||||
|
||||
if( !pt1 ||
|
||||
fabs(pt1->x - pt.x) > FLT_EPSILON ||
|
||||
fabs(pt1->y - pt.y) > FLT_EPSILON )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The point #%d: (%.1f,%.1f) is said to coinside with a subdivision vertex, "
|
||||
"however it could be found in a sequence of inserted points\n", j, pt.x, pt.y );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
real_count--;
|
||||
}
|
||||
|
||||
point = cvSubdivDelaunay2DInsert( subdiv, pt );
|
||||
if( point->pt.x != pt.x || point->pt.y != pt.y )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The point #%d: (%.1f,%.1f) has been incorrectly added\n", j, pt.x, pt.y );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( (j + 1) % 10 == 0 || j == point_count - 1 )
|
||||
{
|
||||
if( !icvSubdiv2DCheck( subdiv ))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Subdivision consistency check failed after inserting the point #%d\n", j );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
|
||||
if( loc != CV_PTLOC_VERTEX )
|
||||
{
|
||||
CV_WRITE_SEQ_ELEM( pt, writer );
|
||||
}
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
|
||||
cvCalcSubdivVoronoi2D( subdiv );
|
||||
seq = cvEndWriteSeq( &writer );
|
||||
|
||||
if( !icvSubdiv2DCheck( subdiv ))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The subdivision failed consistency check after building the Voronoi tesselation\n" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
for( j = 0; j < MAX((point_count - 5)/10 + 5, 10); j++ )
|
||||
{
|
||||
CvPoint2D32f pt;
|
||||
double minDistance;
|
||||
|
||||
pt.x = (float)(cvTsRandReal(rng)*xrange);
|
||||
pt.y = (float)(cvTsRandReal(rng)*yrange);
|
||||
|
||||
CvSubdiv2DPoint* point = cvFindNearestPoint2D( subdiv, pt );
|
||||
CvSeqReader reader;
|
||||
|
||||
if( !point )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "There is no nearest point (?!) for the point (%.1f, %.1f) in the subdivision\n",
|
||||
pt.x, pt.y );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
cvStartReadSeq( seq, &reader );
|
||||
minDistance = icvSqDist2D32f( pt, point->pt );
|
||||
|
||||
for( k = 0; k < seq->total; k++ )
|
||||
{
|
||||
CvPoint2D32f ptt;
|
||||
CV_READ_SEQ_ELEM( ptt, reader );
|
||||
|
||||
double distance = icvSqDist2D32f( pt, ptt );
|
||||
if( minDistance > distance && icvSqDist2D32f(ptt, point->pt) > FLT_EPSILON*1000 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "The triangulation vertex (%.3f,%.3f) was said to be nearest to (%.3f,%.3f),\n"
|
||||
"whereas another vertex (%.3f,%.3f) is closer\n",
|
||||
point->pt.x, point->pt.y, pt.x, pt.y, ptt.x, ptt.y );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exit_:
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
CV_SubdivTest subdiv_test;
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -1,431 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* templmatch_param_names[] = { "template_size", "method", "size", "channels", "depth", 0 };
|
||||
static const int templmatch_depths[] = { CV_8U, CV_32F, -1 };
|
||||
static const int templmatch_channels[] = { 1, 3, -1 };
|
||||
|
||||
static const CvSize templmatch_sizes[] = {{320, 240}, {1024,768}, {-1,-1}};
|
||||
static const CvSize templmatch_whole_sizes[] = {{320,240}, {1024,768}, {-1,-1}};
|
||||
static const CvSize templmatch_template_sizes[] = {{15,15}, {60,60}, {-1,-1}};
|
||||
static const char* templmatch_methods[] = { "sqdiff", "sqdiff_norm", "ccorr", "ccorr_normed", "ccoeff", "ccoeff_normed", 0 };
|
||||
|
||||
class CV_TemplMatchTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_TemplMatchTest();
|
||||
|
||||
protected:
|
||||
int read_params( CvFileStorage* fs );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );
|
||||
|
||||
int max_template_size;
|
||||
int method;
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
CV_TemplMatchTest::CV_TemplMatchTest()
|
||||
: CvArrTest( "match-template", "cvMatchTemplate", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
element_wise_relative_error = false;
|
||||
max_template_size = 100;
|
||||
method = 0;
|
||||
|
||||
size_list = templmatch_sizes;
|
||||
whole_size_list = templmatch_whole_sizes;
|
||||
cn_list = templmatch_channels;
|
||||
depth_list = templmatch_depths;
|
||||
|
||||
default_timing_param_names = templmatch_param_names;
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
int CV_TemplMatchTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE )
|
||||
{
|
||||
max_template_size = cvReadInt( find_param( fs, "max_template_size" ), max_template_size );
|
||||
max_template_size = cvTsClipInt( max_template_size, 1, 100 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
int CV_TemplMatchTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE )
|
||||
{
|
||||
write_param( fs, "max_template_size", max_template_size );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
start_write_param( fs );
|
||||
|
||||
cvStartWriteStruct( fs, "template_size", CV_NODE_SEQ+CV_NODE_FLOW );
|
||||
for( i = 0; templmatch_template_sizes[i].width >= 0; i++ )
|
||||
{
|
||||
cvStartWriteStruct( fs, 0, CV_NODE_SEQ+CV_NODE_FLOW );
|
||||
cvWriteInt( fs, 0, templmatch_template_sizes[i].width );
|
||||
cvWriteInt( fs, 0, templmatch_template_sizes[i].height );
|
||||
cvEndWriteStruct(fs);
|
||||
}
|
||||
cvEndWriteStruct(fs);
|
||||
|
||||
write_string_list( fs, "method", templmatch_methods );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
CvArrTest::get_minmax_bounds( i, j, type, low, high );
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
if( depth == CV_32F )
|
||||
{
|
||||
*low = cvScalarAll(-10.);
|
||||
*high = cvScalarAll(10.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int depth = cvTsRandInt(rng) % 2, cn = cvTsRandInt(rng) & 1 ? 3 : 1;
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
depth = depth == 0 ? CV_8U : CV_32F;
|
||||
|
||||
types[INPUT][0] = types[INPUT][1] = CV_MAKETYPE(depth,cn);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_32FC1;
|
||||
|
||||
sizes[INPUT][1].width = cvTsRandInt(rng)%MIN(sizes[INPUT][1].width,max_template_size) + 1;
|
||||
sizes[INPUT][1].height = cvTsRandInt(rng)%MIN(sizes[INPUT][1].height,max_template_size) + 1;
|
||||
sizes[OUTPUT][0].width = sizes[INPUT][0].width - sizes[INPUT][1].width + 1;
|
||||
sizes[OUTPUT][0].height = sizes[INPUT][0].height - sizes[INPUT][1].height + 1;
|
||||
sizes[REF_OUTPUT][0] = sizes[OUTPUT][0];
|
||||
|
||||
method = cvTsRandInt(rng)%6;
|
||||
test_cpp = (cvTsRandInt(rng) & 256) == 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
const char* method_str = cvReadString( find_timing_param( "method" ), "ccorr" );
|
||||
const CvFileNode* node = find_timing_param( "template_size" );
|
||||
CvSize templ_size, result_size;
|
||||
|
||||
assert( node && CV_NODE_IS_SEQ( node->tag ));
|
||||
|
||||
method = strncmp( method_str, "sqdiff", 6 ) == 0 ? CV_TM_SQDIFF :
|
||||
strncmp( method_str, "ccorr", 5 ) == 0 ? CV_TM_CCORR : CV_TM_CCOEFF;
|
||||
method += strstr( method_str, "_normed" ) != 0;
|
||||
|
||||
cvReadRawData( ts->get_file_storage(), node, &templ_size, "2i" );
|
||||
|
||||
sizes[INPUT][1] = whole_sizes[INPUT][1] = templ_size;
|
||||
result_size.width = sizes[INPUT][0].width - templ_size.width + 1;
|
||||
result_size.height = sizes[INPUT][0].height - templ_size.height + 1;
|
||||
assert( result_size.width > 0 && result_size.height > 0 );
|
||||
sizes[OUTPUT][0] = whole_sizes[OUTPUT][0] = result_size;
|
||||
|
||||
types[OUTPUT][0] = CV_32FC1;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "%s,", cvReadString( find_timing_param( "method" ), "ccorr" ) );
|
||||
ptr += strlen(ptr);
|
||||
sprintf( ptr, "templ_size=%dx%d,", test_mat[INPUT][1].width, test_mat[INPUT][1].height );
|
||||
ptr += strlen(ptr);
|
||||
params_left -= 2;
|
||||
|
||||
CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}
|
||||
|
||||
|
||||
double CV_TemplMatchTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
if( CV_MAT_DEPTH(test_mat[INPUT][1].type) == CV_8U ||
|
||||
(method >= CV_TM_CCOEFF && test_mat[INPUT][1].cols*test_mat[INPUT][1].rows <= 2) )
|
||||
return 1e-2;
|
||||
else
|
||||
return 1e-3;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::run_func()
|
||||
{
|
||||
if(!test_cpp)
|
||||
cvMatchTemplate( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0], method );
|
||||
else
|
||||
{
|
||||
cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
|
||||
cv::matchTemplate(cv::cvarrToMat(test_array[INPUT][0]), cv::cvarrToMat(test_array[INPUT][1]), _out, method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void cvTsMatchTemplate( const CvMat* img, const CvMat* templ, CvMat* result, int method )
|
||||
{
|
||||
int i, j, k, l;
|
||||
int depth = CV_MAT_DEPTH(img->type), cn = CV_MAT_CN(img->type);
|
||||
int width_n = templ->cols*cn, height = templ->rows;
|
||||
int a_step = img->step / CV_ELEM_SIZE(img->type & CV_MAT_DEPTH_MASK);
|
||||
int b_step = templ->step / CV_ELEM_SIZE(templ->type & CV_MAT_DEPTH_MASK);
|
||||
CvScalar b_mean, b_sdv;
|
||||
double b_denom = 1., b_sum2 = 0;
|
||||
int area = templ->rows*templ->cols;
|
||||
|
||||
cvTsMeanStdDevNonZero( templ, 0, &b_mean, &b_sdv, 0 );
|
||||
|
||||
for( i = 0; i < cn; i++ )
|
||||
b_sum2 += (b_sdv.val[i]*b_sdv.val[i] + b_mean.val[i]*b_mean.val[i])*area;
|
||||
|
||||
if( CV_SQR(b_sdv.val[0]) + CV_SQR(b_sdv.val[1]) +
|
||||
CV_SQR(b_sdv.val[2]) + CV_SQR(b_sdv.val[3]) < DBL_EPSILON &&
|
||||
method == CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
cvSet( result, cvScalarAll(1.) );
|
||||
return;
|
||||
}
|
||||
|
||||
if( method & 1 )
|
||||
{
|
||||
b_denom = 0;
|
||||
if( method != CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
b_denom = b_sum2;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < cn; i++ )
|
||||
b_denom += b_sdv.val[i]*b_sdv.val[i]*area;
|
||||
}
|
||||
b_denom = sqrt(b_denom);
|
||||
if( b_denom == 0 )
|
||||
b_denom = 1.;
|
||||
}
|
||||
|
||||
assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED );
|
||||
|
||||
for( i = 0; i < result->rows; i++ )
|
||||
{
|
||||
for( j = 0; j < result->cols; j++ )
|
||||
{
|
||||
CvScalar a_sum = {{ 0, 0, 0, 0 }}, a_sum2 = {{ 0, 0, 0, 0 }};
|
||||
CvScalar ccorr = {{ 0, 0, 0, 0 }};
|
||||
double value = 0.;
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* a = img->data.ptr + i*img->step + j*cn;
|
||||
const uchar* b = templ->data.ptr;
|
||||
|
||||
if( cn == 1 || method < CV_TM_CCOEFF )
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l++ )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l += 3 )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
ccorr.val[1] += a[l+1]*b[l+1];
|
||||
ccorr.val[2] += a[l+2]*b[l+2];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum.val[1] += a[l+1];
|
||||
a_sum.val[2] += a[l+2];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
a_sum2.val[1] += a[l+1]*a[l+1];
|
||||
a_sum2.val[2] += a[l+2]*a[l+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const float* a = (const float*)(img->data.ptr + i*img->step) + j*cn;
|
||||
const float* b = (const float*)templ->data.ptr;
|
||||
|
||||
if( cn == 1 || method < CV_TM_CCOEFF )
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l++ )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l += 3 )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
ccorr.val[1] += a[l+1]*b[l+1];
|
||||
ccorr.val[2] += a[l+2]*b[l+2];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum.val[1] += a[l+1];
|
||||
a_sum.val[2] += a[l+2];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
a_sum2.val[1] += a[l+1]*a[l+1];
|
||||
a_sum2.val[2] += a[l+2]*a[l+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch( method )
|
||||
{
|
||||
case CV_TM_CCORR:
|
||||
case CV_TM_CCORR_NORMED:
|
||||
value = ccorr.val[0];
|
||||
break;
|
||||
case CV_TM_SQDIFF:
|
||||
case CV_TM_SQDIFF_NORMED:
|
||||
value = (a_sum2.val[0] + b_sum2 - 2*ccorr.val[0]);
|
||||
break;
|
||||
default:
|
||||
value = (ccorr.val[0] - a_sum.val[0]*b_mean.val[0]+
|
||||
ccorr.val[1] - a_sum.val[1]*b_mean.val[1]+
|
||||
ccorr.val[2] - a_sum.val[2]*b_mean.val[2]);
|
||||
}
|
||||
|
||||
if( method & 1 )
|
||||
{
|
||||
double denom;
|
||||
|
||||
// calc denominator
|
||||
if( method != CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
denom = a_sum2.val[0] + a_sum2.val[1] + a_sum2.val[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
denom = a_sum2.val[0] - (a_sum.val[0]*a_sum.val[0])/area;
|
||||
denom += a_sum2.val[1] - (a_sum.val[1]*a_sum.val[1])/area;
|
||||
denom += a_sum2.val[2] - (a_sum.val[2]*a_sum.val[2])/area;
|
||||
}
|
||||
denom = sqrt(MAX(denom,0))*b_denom;
|
||||
if( fabs(value) < denom )
|
||||
value /= denom;
|
||||
else if( fabs(value) < denom*1.125 )
|
||||
value = value > 0 ? 1 : -1;
|
||||
else
|
||||
value = method != CV_TM_SQDIFF_NORMED ? 0 : 1;
|
||||
}
|
||||
|
||||
((float*)(result->data.ptr + result->step*i))[j] = (float)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
cvTsMatchTemplate( &test_mat[INPUT][0], &test_mat[INPUT][1],
|
||||
&test_mat[REF_OUTPUT][0], method );
|
||||
|
||||
//if( ts->get_current_test_info()->test_case_idx == 0 )
|
||||
/*{
|
||||
CvFileStorage* fs = cvOpenFileStorage( "_match_template.yml", 0, CV_STORAGE_WRITE );
|
||||
cvWrite( fs, "image", &test_mat[INPUT][0] );
|
||||
cvWrite( fs, "template", &test_mat[INPUT][1] );
|
||||
cvWrite( fs, "ref", &test_mat[REF_OUTPUT][0] );
|
||||
cvWrite( fs, "opencv", &test_mat[OUTPUT][0] );
|
||||
cvWriteInt( fs, "method", method );
|
||||
cvReleaseFileStorage( &fs );
|
||||
}*/
|
||||
|
||||
if( method >= CV_TM_CCOEFF )
|
||||
{
|
||||
// avoid numerical stability problems in singular cases (when the results are near to 0)
|
||||
const double delta = 10.;
|
||||
cvTsAdd( &test_mat[REF_OUTPUT][0], cvScalar(1.), 0, cvScalar(0.),
|
||||
cvScalar(delta), &test_mat[REF_OUTPUT][0], 0 );
|
||||
cvTsAdd( &test_mat[OUTPUT][0], cvScalar(1.), 0, cvScalar(0.),
|
||||
cvScalar(delta), &test_mat[OUTPUT][0], 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_TemplMatchTest templ_match;
|
||||
@@ -1,283 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
static const char* thresh_param_names[] = { "size", "depth", "thresh_type", 0 };
|
||||
static const CvSize thresh_sizes[] = {{30,30}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const CvSize thresh_whole_sizes[] = {{320,240}, {320, 240}, {720,480}, {-1,-1}};
|
||||
static const int thresh_depths[] = { CV_8U, CV_32F, -1 };
|
||||
static const char* thresh_types[] = { "binary", "binary_inv", "trunc", "tozero", "tozero_inv", 0 };
|
||||
|
||||
class CV_ThreshTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_ThreshTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
int write_default_params(CvFileStorage* fs);
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );
|
||||
|
||||
int thresh_type;
|
||||
float thresh_val;
|
||||
float max_val;
|
||||
};
|
||||
|
||||
|
||||
CV_ThreshTest::CV_ThreshTest()
|
||||
: CvArrTest( "thresh-simple", "cvThreshold", "" )
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
|
||||
default_timing_param_names = thresh_param_names;
|
||||
depth_list = thresh_depths;
|
||||
size_list = thresh_sizes;
|
||||
whole_size_list = thresh_whole_sizes;
|
||||
cn_list = 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int depth = cvTsRandInt(rng) % 2, cn = cvTsRandInt(rng) % 4 + 1;
|
||||
CvArrTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
depth = depth == 0 ? CV_8U : CV_32F;
|
||||
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_MAKETYPE(depth,cn);
|
||||
thresh_type = cvTsRandInt(rng) % 5;
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
thresh_val = (float)(cvTsRandReal(rng)*350. - 50.);
|
||||
max_val = (float)(cvTsRandReal(rng)*350. - 50.);
|
||||
if( cvTsRandInt(rng)%4 == 0 )
|
||||
max_val = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
thresh_val = (float)(cvTsRandReal(rng)*1000. - 500.);
|
||||
max_val = (float)(cvTsRandReal(rng)*1000. - 500.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double CV_ThreshTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return FLT_EPSILON*10;
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::run_func()
|
||||
{
|
||||
cvThreshold( test_array[INPUT][0], test_array[OUTPUT][0],
|
||||
thresh_val, max_val, thresh_type );
|
||||
}
|
||||
|
||||
|
||||
static void cvTsThreshold( const CvMat* _src, CvMat* _dst,
|
||||
float thresh, float maxval, int thresh_type )
|
||||
{
|
||||
int i, j;
|
||||
int depth = CV_MAT_DEPTH(_src->type), cn = CV_MAT_CN(_src->type);
|
||||
int width_n = _src->cols*cn, height = _src->rows;
|
||||
int ithresh = cvFloor(thresh), ithresh2, imaxval = cvRound(maxval);
|
||||
const uchar* src = _src->data.ptr;
|
||||
uchar* dst = _dst->data.ptr;
|
||||
|
||||
ithresh2 = CV_CAST_8U(ithresh);
|
||||
imaxval = CV_CAST_8U(imaxval);
|
||||
|
||||
assert( depth == CV_8U || depth == CV_32F );
|
||||
|
||||
switch( thresh_type )
|
||||
{
|
||||
case CV_THRESH_BINARY:
|
||||
for( i = 0; i < height; i++, src += _src->step, dst += _dst->step )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (uchar)(src[j] > ithresh ? imaxval : 0);
|
||||
else
|
||||
for( j = 0; j < width_n; j++ )
|
||||
((float*)dst)[j] = ((const float*)src)[j] > thresh ? maxval : 0.f;
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_BINARY_INV:
|
||||
for( i = 0; i < height; i++, src += _src->step, dst += _dst->step )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (uchar)(src[j] > ithresh ? 0 : imaxval);
|
||||
else
|
||||
for( j = 0; j < width_n; j++ )
|
||||
((float*)dst)[j] = ((const float*)src)[j] > thresh ? 0.f : maxval;
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TRUNC:
|
||||
for( i = 0; i < height; i++, src += _src->step, dst += _dst->step )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? ithresh2 : s);
|
||||
}
|
||||
else
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = ((const float*)src)[j];
|
||||
((float*)dst)[j] = s > thresh ? thresh : s;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TOZERO:
|
||||
for( i = 0; i < height; i++, src += _src->step, dst += _dst->step )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? s : 0);
|
||||
}
|
||||
else
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = ((const float*)src)[j];
|
||||
((float*)dst)[j] = s > thresh ? s : 0.f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TOZERO_INV:
|
||||
for( i = 0; i < height; i++, src += _src->step, dst += _dst->step )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? 0 : s);
|
||||
}
|
||||
else
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = ((const float*)src)[j];
|
||||
((float*)dst)[j] = s > thresh ? 0.f : s;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
cvTsThreshold( &test_mat[INPUT][0], &test_mat[REF_OUTPUT][0],
|
||||
thresh_val, max_val, thresh_type );
|
||||
}
|
||||
|
||||
|
||||
int CV_ThreshTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvArrTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::TIMING_MODE )
|
||||
{
|
||||
start_write_param( fs );
|
||||
write_string_list( fs, "thresh_type", thresh_types );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::get_timing_test_array_types_and_sizes( int test_case_idx,
|
||||
CvSize** sizes, int** types, CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
CvArrTest::get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, are_images );
|
||||
const char* thresh_str = cvReadString( find_timing_param( "thresh_type" ), "binary" );
|
||||
thresh_type = strcmp( thresh_str, "binary" ) == 0 ? CV_THRESH_BINARY :
|
||||
strcmp( thresh_str, "binary_inv" ) == 0 ? CV_THRESH_BINARY_INV :
|
||||
strcmp( thresh_str, "trunc" ) == 0 ? CV_THRESH_TRUNC :
|
||||
strcmp( thresh_str, "tozero" ) == 0 ? CV_THRESH_TOZERO :
|
||||
CV_THRESH_TOZERO_INV;
|
||||
|
||||
if( CV_MAT_DEPTH(types[INPUT][0]) == CV_8U )
|
||||
{
|
||||
thresh_val = 128;
|
||||
max_val = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
thresh_val = 500.;
|
||||
max_val = 1.;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::print_timing_params( int test_case_idx, char* ptr, int params_left )
|
||||
{
|
||||
sprintf( ptr, "%s,", cvReadString( find_timing_param( "thresh_type" ), "binary" ) );
|
||||
ptr += strlen(ptr);
|
||||
params_left--;
|
||||
|
||||
CvArrTest::print_timing_params( test_case_idx, ptr, params_left );
|
||||
}
|
||||
|
||||
|
||||
CV_ThreshTest thresh_test;
|
||||
|
||||
@@ -1,907 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
|
||||
class CV_DefaultNewCameraMatrixTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_DefaultNewCameraMatrixTest();
|
||||
protected:
|
||||
int prepare_test_case (int test_case_idx);
|
||||
void prepare_to_validation( int test_case_idx );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
void run_func();
|
||||
|
||||
private:
|
||||
cv::Size img_size;
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat new_camera_mat;
|
||||
|
||||
int matrix_type;
|
||||
|
||||
bool center_principal_point;
|
||||
|
||||
static const int MAX_X = 2048;
|
||||
static const int MAX_Y = 2048;
|
||||
static const int MAX_VAL = 10000;
|
||||
};
|
||||
|
||||
CV_DefaultNewCameraMatrixTest::CV_DefaultNewCameraMatrixTest() : CvArrTest("undistort-getDefaultNewCameraMatrix","getDefaultNewCameraMatrix")
|
||||
{
|
||||
test_array[INPUT].push(NULL);
|
||||
test_array[OUTPUT].push(NULL);
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
}
|
||||
|
||||
void CV_DefaultNewCameraMatrixTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
|
||||
{
|
||||
CvArrTest::get_test_array_types_and_sizes(test_case_idx,sizes,types);
|
||||
CvRNG* rng = ts->get_rng();
|
||||
matrix_type = types[INPUT][0] = types[OUTPUT][0]= types[REF_OUTPUT][0] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
sizes[INPUT][0] = sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(3,3);
|
||||
}
|
||||
|
||||
int CV_DefaultNewCameraMatrixTest::prepare_test_case(int test_case_idx)
|
||||
{
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
|
||||
if (code <= 0)
|
||||
return code;
|
||||
|
||||
CvRNG* rng = ts->get_rng();
|
||||
|
||||
img_size.width = cvTsRandInt(rng) % MAX_X + 1;
|
||||
img_size.height = cvTsRandInt(rng) % MAX_Y + 1;
|
||||
|
||||
center_principal_point = ((cvTsRandInt(rng) % 2)!=0);
|
||||
|
||||
// Generating camera_mat matrix
|
||||
double sz = MAX(img_size.width, img_size.height);
|
||||
double aspect_ratio = cvTsRandReal(rng)*0.6 + 0.7;
|
||||
double a[9] = {0,0,0,0,0,0,0,0,1};
|
||||
CvMat _a = cvMat(3,3,CV_64F,a);
|
||||
a[2] = (img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
a[5] = (img_size.height - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
a[0] = sz/(0.9 - cvTsRandReal(rng)*0.6);
|
||||
a[4] = aspect_ratio*a[0];
|
||||
|
||||
//Copying into input array
|
||||
CvMat* _a0 = &test_mat[INPUT][0];
|
||||
cvTsConvert( &_a, _a0 );
|
||||
camera_mat = _a0;
|
||||
//new_camera_mat = camera_mat;
|
||||
|
||||
return code;
|
||||
|
||||
}
|
||||
|
||||
void CV_DefaultNewCameraMatrixTest::run_func()
|
||||
{
|
||||
new_camera_mat = cv::getDefaultNewCameraMatrix(camera_mat,img_size,center_principal_point);
|
||||
}
|
||||
|
||||
void CV_DefaultNewCameraMatrixTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
const CvMat* src = &test_mat[INPUT][0];
|
||||
CvMat* dst = &test_mat[REF_OUTPUT][0];
|
||||
CvMat* test_output = &test_mat[OUTPUT][0];
|
||||
CvMat output = new_camera_mat;
|
||||
cvTsConvert( &output, test_output );
|
||||
if (!center_principal_point)
|
||||
{
|
||||
cvCopy(src,dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
double a[9] = {0,0,0,0,0,0,0,0,1};
|
||||
CvMat _a = cvMat(3,3,CV_64F,a);
|
||||
if (matrix_type == CV_64F)
|
||||
{
|
||||
a[0] = ((double*)(src->data.ptr + src->step*0))[0];
|
||||
a[4] = ((double*)(src->data.ptr + src->step*1))[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
a[0] = (double)((float*)(src->data.ptr + src->step*0))[0];
|
||||
a[4] = (double)((float*)(src->data.ptr + src->step*1))[1];
|
||||
}
|
||||
a[2] = (img_size.width - 1)*0.5;
|
||||
a[5] = (img_size.height - 1)*0.5;
|
||||
cvTsConvert( &_a, dst );
|
||||
}
|
||||
}
|
||||
|
||||
CV_DefaultNewCameraMatrixTest default_new_camera_matrix_test;
|
||||
|
||||
//---------
|
||||
|
||||
class CV_UndistortPointsTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_UndistortPointsTest();
|
||||
protected:
|
||||
int prepare_test_case (int test_case_idx);
|
||||
void prepare_to_validation( int test_case_idx );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void cvTsDistortPoints(const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatrix,
|
||||
const CvMat* _distCoeffs,
|
||||
const CvMat* matR, const CvMat* matP);
|
||||
|
||||
private:
|
||||
bool useCPlus;
|
||||
bool useDstMat;
|
||||
static const int N_POINTS = 10;
|
||||
static const int MAX_X = 2048;
|
||||
static const int MAX_Y = 2048;
|
||||
|
||||
bool zero_new_cam;
|
||||
bool zero_distortion;
|
||||
bool zero_R;
|
||||
|
||||
cv::Size img_size;
|
||||
cv::Mat dst_points_mat;
|
||||
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat R;
|
||||
cv::Mat P;
|
||||
cv::Mat distortion_coeffs;
|
||||
cv::Mat src_points;
|
||||
std::vector<cv::Point2f> dst_points;
|
||||
};
|
||||
|
||||
CV_UndistortPointsTest::CV_UndistortPointsTest() : CvArrTest("undistort-points","cvUndistortPoints")
|
||||
{
|
||||
test_array[INPUT].push(NULL); // points matrix
|
||||
test_array[INPUT].push(NULL); // camera matrix
|
||||
test_array[INPUT].push(NULL); // distortion coeffs
|
||||
test_array[INPUT].push(NULL); // R matrix
|
||||
test_array[INPUT].push(NULL); // P matrix
|
||||
test_array[OUTPUT].push(NULL); // distorted dst points
|
||||
test_array[TEMP].push(NULL); // dst points
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
}
|
||||
|
||||
void CV_UndistortPointsTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
|
||||
{
|
||||
CvArrTest::get_test_array_types_and_sizes(test_case_idx,sizes,types);
|
||||
CvRNG* rng = ts->get_rng();
|
||||
useCPlus = ((cvTsRandInt(rng) % 2)!=0);
|
||||
//useCPlus = 0;
|
||||
if (useCPlus)
|
||||
{
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = types[TEMP][0]= CV_32FC2;
|
||||
}
|
||||
else
|
||||
{
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = types[TEMP][0]= cvTsRandInt(rng)%2 ? CV_64FC2 : CV_32FC2;
|
||||
}
|
||||
types[INPUT][1] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][2] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][3] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][4] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
|
||||
sizes[INPUT][0] = sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = sizes[TEMP][0]= cvTsRandInt(rng)%2 ? cvSize(1,N_POINTS) : cvSize(N_POINTS,1);
|
||||
sizes[INPUT][1] = sizes[INPUT][3] = cvSize(3,3);
|
||||
sizes[INPUT][4] = cvTsRandInt(rng)%2 ? cvSize(3,3) : cvSize(4,3);
|
||||
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(1,4);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(1,5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(4,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(5,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CV_UndistortPointsTest::prepare_test_case(int test_case_idx)
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
|
||||
if (code <= 0)
|
||||
return code;
|
||||
|
||||
useDstMat = (cvTsRandInt(rng) % 2) == 0;
|
||||
|
||||
img_size.width = cvTsRandInt(rng) % MAX_X + 1;
|
||||
img_size.height = cvTsRandInt(rng) % MAX_Y + 1;
|
||||
int dist_size = test_mat[INPUT][2].cols > test_mat[INPUT][2].rows ? test_mat[INPUT][2].cols : test_mat[INPUT][2].rows;
|
||||
double cam[9] = {0,0,0,0,0,0,0,0,1};
|
||||
double* dist = new double[dist_size ];
|
||||
double* proj = new double[test_mat[INPUT][4].cols * test_mat[INPUT][4].rows];
|
||||
double* points = new double[N_POINTS*2];
|
||||
|
||||
CvMat _camera = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _distort = cvMat(test_mat[INPUT][2].rows,test_mat[INPUT][2].cols,CV_64F,dist);
|
||||
CvMat _proj = cvMat(test_mat[INPUT][4].rows,test_mat[INPUT][4].cols,CV_64F,proj);
|
||||
CvMat _points= cvMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_64FC2, points);
|
||||
|
||||
for (int i=0;i<test_mat[INPUT][4].cols * test_mat[INPUT][4].rows;i++)
|
||||
{
|
||||
proj[i] = 0;
|
||||
}
|
||||
|
||||
//Generating points
|
||||
for (int i=0;i<N_POINTS;i++)
|
||||
{
|
||||
points[2*i] = cvTsRandReal(rng)*img_size.width;
|
||||
points[2*i+1] = cvTsRandReal(rng)*img_size.height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Generating camera matrix
|
||||
double sz = MAX(img_size.width,img_size.height);
|
||||
double aspect_ratio = cvTsRandReal(rng)*0.6 + 0.7;
|
||||
cam[2] = (img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
cam[5] = (img_size.height - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
cam[0] = sz/(0.9 - cvTsRandReal(rng)*0.6);
|
||||
cam[4] = aspect_ratio*cam[0];
|
||||
|
||||
//Generating distortion coeffs
|
||||
dist[0] = cvTsRandReal(rng)*0.06 - 0.03;
|
||||
dist[1] = cvTsRandReal(rng)*0.06 - 0.03;
|
||||
if( dist[0]*dist[1] > 0 )
|
||||
dist[1] = -dist[1];
|
||||
if( cvTsRandInt(rng)%4 != 0 )
|
||||
{
|
||||
dist[2] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
dist[3] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
if (dist_size > 4)
|
||||
dist[4] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
}
|
||||
else
|
||||
{
|
||||
dist[2] = dist[3] = 0;
|
||||
if (dist_size > 4)
|
||||
dist[4] = 0;
|
||||
}
|
||||
|
||||
//Generating P matrix (projection)
|
||||
if ( test_mat[INPUT][4].cols != 4)
|
||||
{
|
||||
proj[8] = 1;
|
||||
if (cvTsRandInt(rng)%2 == 0) // use identity new camera matrix
|
||||
{
|
||||
proj[0] = 1;
|
||||
proj[4] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
proj[0] = cam[0] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[0]; //10%
|
||||
proj[4] = cam[4] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[4]; //10%
|
||||
proj[2] = cam[2] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.width; //15%
|
||||
proj[5] = cam[5] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.height; //15%
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
proj[10] = 1;
|
||||
proj[0] = cam[0] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[0]; //10%
|
||||
proj[5] = cam[4] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[4]; //10%
|
||||
proj[2] = cam[2] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.width; //15%
|
||||
proj[6] = cam[5] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.height; //15%
|
||||
|
||||
proj[3] = (img_size.height + img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
proj[7] = (img_size.height + img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
proj[11] = (img_size.height + img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
}
|
||||
|
||||
//Generating R matrix
|
||||
CvMat* _rot = cvCreateMat(3,3,CV_64F);
|
||||
CvMat* rotation = cvCreateMat(1,3,CV_64F);
|
||||
rotation->data.db[0] = CV_PI*(cvTsRandReal(rng) - (double)0.5); // phi
|
||||
rotation->data.db[1] = CV_PI*(cvTsRandReal(rng) - (double)0.5); // ksi
|
||||
rotation->data.db[2] = CV_PI*(cvTsRandReal(rng) - (double)0.5); //khi
|
||||
cvRodrigues2(rotation,_rot);
|
||||
cvReleaseMat(&rotation);
|
||||
|
||||
//copying data
|
||||
//src_points = &_points;
|
||||
CvMat* dst = &test_mat[INPUT][0];
|
||||
cvTsConvert( &_points, dst);
|
||||
dst = &test_mat[INPUT][1];
|
||||
cvTsConvert( &_camera, dst);
|
||||
dst = &test_mat[INPUT][2];
|
||||
cvTsConvert( &_distort, dst);
|
||||
dst = &test_mat[INPUT][3];
|
||||
cvTsConvert( _rot, dst);
|
||||
dst = &test_mat[INPUT][4];
|
||||
cvTsConvert( &_proj, dst);
|
||||
|
||||
zero_distortion = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
zero_new_cam = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
zero_R = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
|
||||
|
||||
cvReleaseMat(&_rot);
|
||||
|
||||
if (useCPlus)
|
||||
{
|
||||
CvMat* temp = cvCreateMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_32FC2);
|
||||
for (int i=0;i<test_mat[INPUT][0].rows*test_mat[INPUT][0].cols*2;i++)
|
||||
temp->data.fl[i] = (float)_points.data.db[i];
|
||||
|
||||
|
||||
src_points = cv::Mat(temp,true);
|
||||
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
camera_mat = &test_mat[INPUT][1];
|
||||
distortion_coeffs = &test_mat[INPUT][2];
|
||||
R = &test_mat[INPUT][3];
|
||||
P = &test_mat[INPUT][4];
|
||||
}
|
||||
delete[] dist;
|
||||
delete[] proj;
|
||||
delete[] points;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void CV_UndistortPointsTest::prepare_to_validation(int /*test_case_idx*/)
|
||||
{
|
||||
int dist_size = test_mat[INPUT][2].cols > test_mat[INPUT][2].rows ? test_mat[INPUT][2].cols : test_mat[INPUT][2].rows;
|
||||
double cam[9] = {0,0,0,0,0,0,0,0,1};
|
||||
double rot[9] = {1,0,0,0,1,0,0,0,1};
|
||||
double* dist = new double[dist_size ];
|
||||
double* proj = new double[test_mat[INPUT][4].cols * test_mat[INPUT][4].rows];
|
||||
double* points = new double[N_POINTS*2];
|
||||
double* r_points = new double[N_POINTS*2];
|
||||
//Run reference calculations
|
||||
CvMat ref_points= cvMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_64FC2,r_points);
|
||||
CvMat _camera = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _rot = cvMat(3,3,CV_64F,rot);
|
||||
CvMat _distort = cvMat(test_mat[INPUT][2].rows,test_mat[INPUT][2].cols,CV_64F,dist);
|
||||
CvMat _proj = cvMat(test_mat[INPUT][4].rows,test_mat[INPUT][4].cols,CV_64F,proj);
|
||||
CvMat _points= cvMat(test_mat[TEMP][0].rows,test_mat[TEMP][0].cols,CV_64FC2,points);
|
||||
|
||||
|
||||
cvTsConvert(&test_mat[INPUT][1],&_camera);
|
||||
cvTsConvert(&test_mat[INPUT][2],&_distort);
|
||||
cvTsConvert(&test_mat[INPUT][3],&_rot);
|
||||
cvTsConvert(&test_mat[INPUT][4],&_proj);
|
||||
|
||||
if (useCPlus)
|
||||
{
|
||||
if (useDstMat)
|
||||
{
|
||||
CvMat temp = dst_points_mat;
|
||||
for (int i=0;i<N_POINTS*2;i++)
|
||||
{
|
||||
points[i] = temp.data.fl[i];
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
for (int i=0;i<N_POINTS;i++)
|
||||
{
|
||||
points[2*i] = dst_points[i].x;
|
||||
points[2*i+1] = dst_points[i].y;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cvTsConvert(&test_mat[TEMP][0],&_points);
|
||||
}
|
||||
|
||||
CvMat* input2;
|
||||
CvMat* input3;
|
||||
CvMat* input4;
|
||||
input2 = zero_distortion ? 0 : &_distort;
|
||||
input3 = zero_R ? 0 : &_rot;
|
||||
input4 = zero_new_cam ? 0 : &_proj;
|
||||
cvTsDistortPoints(&_points,&ref_points,&_camera,input2,input3,input4);
|
||||
|
||||
CvMat* dst = &test_mat[REF_OUTPUT][0];
|
||||
cvTsConvert(&ref_points,dst);
|
||||
|
||||
cvCopy(&test_mat[INPUT][0],&test_mat[OUTPUT][0]);
|
||||
|
||||
delete[] dist;
|
||||
delete[] proj;
|
||||
delete[] points;
|
||||
delete[] r_points;
|
||||
}
|
||||
|
||||
void CV_UndistortPointsTest::run_func()
|
||||
{
|
||||
|
||||
if (useCPlus)
|
||||
{
|
||||
cv::Mat input2,input3,input4;
|
||||
input2 = zero_distortion ? cv::Mat() : cv::Mat(&test_mat[INPUT][2]);
|
||||
input3 = zero_R ? cv::Mat() : cv::Mat(&test_mat[INPUT][3]);
|
||||
input4 = zero_new_cam ? cv::Mat() : cv::Mat(&test_mat[INPUT][4]);
|
||||
|
||||
if (useDstMat)
|
||||
{
|
||||
//cv::undistortPoints(src_points,dst_points_mat,camera_mat,distortion_coeffs,R,P);
|
||||
cv::undistortPoints(src_points,dst_points_mat,camera_mat,input2,input3,input4);
|
||||
}
|
||||
else
|
||||
{
|
||||
//cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
|
||||
cv::undistortPoints(src_points,dst_points,camera_mat,input2,input3,input4);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CvMat* input2;
|
||||
CvMat* input3;
|
||||
CvMat* input4;
|
||||
input2 = zero_distortion ? 0 : &test_mat[INPUT][2];
|
||||
input3 = zero_R ? 0 : &test_mat[INPUT][3];
|
||||
input4 = zero_new_cam ? 0 : &test_mat[INPUT][4];
|
||||
cvUndistortPoints(&test_mat[INPUT][0],&test_mat[TEMP][0],&test_mat[INPUT][1],input2,input3,input4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CV_UndistortPointsTest::cvTsDistortPoints(const CvMat* _src, CvMat* _dst, const CvMat* _cameraMatrix,
|
||||
const CvMat* _distCoeffs,
|
||||
const CvMat* matR, const CvMat* matP)
|
||||
{
|
||||
double a[9];
|
||||
|
||||
CvMat* __P;
|
||||
if ((!matP)||(matP->cols == 3))
|
||||
__P = cvCreateMat(3,3,CV_64F);
|
||||
else
|
||||
__P = cvCreateMat(3,4,CV_64F);
|
||||
if (matP)
|
||||
{
|
||||
cvTsConvert(matP,__P);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvZero(__P);
|
||||
__P->data.db[0] = 1;
|
||||
__P->data.db[4] = 1;
|
||||
__P->data.db[8] = 1;
|
||||
}
|
||||
CvMat* __R = cvCreateMat(3,3,CV_64F);;
|
||||
if (matR)
|
||||
{
|
||||
cvCopy(matR,__R);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvZero(__R);
|
||||
__R->data.db[0] = 1;
|
||||
__R->data.db[4] = 1;
|
||||
__R->data.db[8] = 1;
|
||||
}
|
||||
for (int i=0;i<N_POINTS;i++)
|
||||
{
|
||||
int movement = __P->cols > 3 ? 1 : 0;
|
||||
double x = (_src->data.db[2*i]-__P->data.db[2])/__P->data.db[0];
|
||||
double y = (_src->data.db[2*i+1]-__P->data.db[5+movement])/__P->data.db[4+movement];
|
||||
CvMat inverse = cvMat(3,3,CV_64F,a);
|
||||
cvInvert(__R,&inverse);
|
||||
double w1 = x*inverse.data.db[6]+y*inverse.data.db[7]+inverse.data.db[8];
|
||||
double _x = (x*inverse.data.db[0]+y*inverse.data.db[1]+inverse.data.db[2])/w1;
|
||||
double _y = (x*inverse.data.db[3]+y*inverse.data.db[4]+inverse.data.db[5])/w1;
|
||||
|
||||
//Distortions
|
||||
|
||||
double __x = _x;
|
||||
double __y = _y;
|
||||
if (_distCoeffs)
|
||||
{
|
||||
double r2 = _x*_x+_y*_y;
|
||||
|
||||
__x = _x*(1+_distCoeffs->data.db[0]*r2+_distCoeffs->data.db[1]*r2*r2)+
|
||||
2*_distCoeffs->data.db[2]*_x*_y+_distCoeffs->data.db[3]*(r2+2*_x*_x);
|
||||
__y = _y*(1+_distCoeffs->data.db[0]*r2+_distCoeffs->data.db[1]*r2*r2)+
|
||||
2*_distCoeffs->data.db[3]*_x*_y+_distCoeffs->data.db[2]*(r2+2*_y*_y);
|
||||
if ((_distCoeffs->cols > 4) || (_distCoeffs->rows > 4))
|
||||
{
|
||||
__x+=_x*_distCoeffs->data.db[4]*r2*r2*r2;
|
||||
__y+=_y*_distCoeffs->data.db[4]*r2*r2*r2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_dst->data.db[2*i] = __x*_cameraMatrix->data.db[0]+_cameraMatrix->data.db[2];
|
||||
_dst->data.db[2*i+1] = __y*_cameraMatrix->data.db[4]+_cameraMatrix->data.db[5];
|
||||
|
||||
}
|
||||
|
||||
cvReleaseMat(&__R);
|
||||
cvReleaseMat(&__P);
|
||||
|
||||
}
|
||||
|
||||
double CV_UndistortPointsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 5e-2;
|
||||
}
|
||||
|
||||
CV_UndistortPointsTest undistort_points_test;
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class CV_InitUndistortRectifyMapTest : public CvArrTest
|
||||
{
|
||||
public:
|
||||
CV_InitUndistortRectifyMapTest();
|
||||
protected:
|
||||
int prepare_test_case (int test_case_idx);
|
||||
void prepare_to_validation( int test_case_idx );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
|
||||
private:
|
||||
bool useCPlus;
|
||||
static const int N_POINTS = 100;
|
||||
static const int MAX_X = 2048;
|
||||
static const int MAX_Y = 2048;
|
||||
bool zero_new_cam;
|
||||
bool zero_distortion;
|
||||
bool zero_R;
|
||||
|
||||
|
||||
cv::Size img_size;
|
||||
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat R;
|
||||
cv::Mat new_camera_mat;
|
||||
cv::Mat distortion_coeffs;
|
||||
cv::Mat mapx;
|
||||
cv::Mat mapy;
|
||||
CvMat* _mapx;
|
||||
CvMat* _mapy;
|
||||
int mat_type;
|
||||
};
|
||||
|
||||
CV_InitUndistortRectifyMapTest::CV_InitUndistortRectifyMapTest() : CvArrTest("undistort-undistort_rectify_map","cvInitUndistortRectifyMap")
|
||||
{
|
||||
test_array[INPUT].push(NULL); // test points matrix
|
||||
test_array[INPUT].push(NULL); // camera matrix
|
||||
test_array[INPUT].push(NULL); // distortion coeffs
|
||||
test_array[INPUT].push(NULL); // R matrix
|
||||
test_array[INPUT].push(NULL); // new camera matrix
|
||||
test_array[OUTPUT].push(NULL); // distorted dst points
|
||||
test_array[REF_OUTPUT].push(NULL);
|
||||
}
|
||||
|
||||
void CV_InitUndistortRectifyMapTest::get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types )
|
||||
{
|
||||
CvArrTest::get_test_array_types_and_sizes(test_case_idx,sizes,types);
|
||||
CvRNG* rng = ts->get_rng();
|
||||
useCPlus = ((cvTsRandInt(rng) % 2)!=0);
|
||||
//useCPlus = 0;
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC2;
|
||||
|
||||
types[INPUT][1] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][2] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][3] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
types[INPUT][4] = cvTsRandInt(rng)%2 ? CV_64F : CV_32F;
|
||||
|
||||
sizes[INPUT][0] = sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(N_POINTS,1);
|
||||
sizes[INPUT][1] = sizes[INPUT][3] = cvSize(3,3);
|
||||
sizes[INPUT][4] = cvSize(3,3);
|
||||
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(1,4);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(1,5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cvTsRandInt(rng)%2)
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(4,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes[INPUT][2] = cvSize(5,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CV_InitUndistortRectifyMapTest::prepare_test_case(int test_case_idx)
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
int code = CvArrTest::prepare_test_case( test_case_idx );
|
||||
|
||||
if (code <= 0)
|
||||
return code;
|
||||
|
||||
img_size.width = cvTsRandInt(rng) % MAX_X + 1;
|
||||
img_size.height = cvTsRandInt(rng) % MAX_Y + 1;
|
||||
|
||||
if (useCPlus)
|
||||
{
|
||||
mat_type = (cvTsRandInt(rng) % 2) == 0 ? CV_32FC1 : CV_16SC2;
|
||||
if ((cvTsRandInt(rng) % 4) == 0)
|
||||
mat_type = -1;
|
||||
if ((cvTsRandInt(rng) % 4) == 0)
|
||||
mat_type = CV_32FC2;
|
||||
_mapx = 0;
|
||||
_mapy = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int typex = (cvTsRandInt(rng) % 2) == 0 ? CV_32FC1 : CV_16SC2;
|
||||
//typex = CV_32FC1; ///!!!!!!!!!!!!!!!!
|
||||
int typey = (typex == CV_32FC1) ? CV_32FC1 : CV_16UC1;
|
||||
|
||||
_mapx = cvCreateMat(img_size.height,img_size.width,typex);
|
||||
_mapy = cvCreateMat(img_size.height,img_size.width,typey);
|
||||
|
||||
|
||||
}
|
||||
|
||||
int dist_size = test_mat[INPUT][2].cols > test_mat[INPUT][2].rows ? test_mat[INPUT][2].cols : test_mat[INPUT][2].rows;
|
||||
double cam[9] = {0,0,0,0,0,0,0,0,1};
|
||||
double* dist = new double[dist_size ];
|
||||
double* new_cam = new double[test_mat[INPUT][4].cols * test_mat[INPUT][4].rows];
|
||||
double* points = new double[N_POINTS*2];
|
||||
|
||||
CvMat _camera = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _distort = cvMat(test_mat[INPUT][2].rows,test_mat[INPUT][2].cols,CV_64F,dist);
|
||||
CvMat _new_cam = cvMat(test_mat[INPUT][4].rows,test_mat[INPUT][4].cols,CV_64F,new_cam);
|
||||
CvMat _points= cvMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_64FC2, points);
|
||||
|
||||
for (int i=0;i<test_mat[INPUT][4].cols * test_mat[INPUT][4].rows;i++)
|
||||
{
|
||||
new_cam[i] = 0;
|
||||
}
|
||||
|
||||
//Generating points
|
||||
for (int i=0;i<N_POINTS;i++)
|
||||
{
|
||||
points[2*i] = cvTsRandReal(rng)*img_size.width;
|
||||
points[2*i+1] = cvTsRandReal(rng)*img_size.height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Generating camera matrix
|
||||
double sz = MAX(img_size.width,img_size.height);
|
||||
double aspect_ratio = cvTsRandReal(rng)*0.6 + 0.7;
|
||||
cam[2] = (img_size.width - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
cam[5] = (img_size.height - 1)*0.5 + cvTsRandReal(rng)*10 - 5;
|
||||
cam[0] = sz/(0.9 - cvTsRandReal(rng)*0.6);
|
||||
cam[4] = aspect_ratio*cam[0];
|
||||
|
||||
//Generating distortion coeffs
|
||||
dist[0] = cvTsRandReal(rng)*0.06 - 0.03;
|
||||
dist[1] = cvTsRandReal(rng)*0.06 - 0.03;
|
||||
if( dist[0]*dist[1] > 0 )
|
||||
dist[1] = -dist[1];
|
||||
if( cvTsRandInt(rng)%4 != 0 )
|
||||
{
|
||||
dist[2] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
dist[3] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
if (dist_size > 4)
|
||||
dist[4] = cvTsRandReal(rng)*0.004 - 0.002;
|
||||
}
|
||||
else
|
||||
{
|
||||
dist[2] = dist[3] = 0;
|
||||
if (dist_size > 4)
|
||||
dist[4] = 0;
|
||||
}
|
||||
|
||||
//Generating new camera matrix
|
||||
|
||||
new_cam[8] = 1;
|
||||
|
||||
//new_cam[0] = cam[0];
|
||||
//new_cam[4] = cam[4];
|
||||
//new_cam[2] = cam[2];
|
||||
//new_cam[5] = cam[5];
|
||||
|
||||
new_cam[0] = cam[0] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[0]; //10%
|
||||
new_cam[4] = cam[4] + (cvTsRandReal(rng) - (double)0.5)*0.2*cam[4]; //10%
|
||||
new_cam[2] = cam[2] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.width; //15%
|
||||
new_cam[5] = cam[5] + (cvTsRandReal(rng) - (double)0.5)*0.3*img_size.height; //15%
|
||||
|
||||
|
||||
//Generating R matrix
|
||||
CvMat* _rot = cvCreateMat(3,3,CV_64F);
|
||||
CvMat* rotation = cvCreateMat(1,3,CV_64F);
|
||||
rotation->data.db[0] = CV_PI/8*(cvTsRandReal(rng) - (double)0.5); // phi
|
||||
rotation->data.db[1] = CV_PI/8*(cvTsRandReal(rng) - (double)0.5); // ksi
|
||||
rotation->data.db[2] = CV_PI/3*(cvTsRandReal(rng) - (double)0.5); //khi
|
||||
cvRodrigues2(rotation,_rot);
|
||||
cvReleaseMat(&rotation);
|
||||
|
||||
//cvSetIdentity(_rot);
|
||||
//copying data
|
||||
CvMat* dst = &test_mat[INPUT][0];
|
||||
cvTsConvert( &_points, dst);
|
||||
dst = &test_mat[INPUT][1];
|
||||
cvTsConvert( &_camera, dst);
|
||||
dst = &test_mat[INPUT][2];
|
||||
cvTsConvert( &_distort, dst);
|
||||
dst = &test_mat[INPUT][3];
|
||||
cvTsConvert( _rot, dst);
|
||||
dst = &test_mat[INPUT][4];
|
||||
cvTsConvert( &_new_cam, dst);
|
||||
|
||||
zero_distortion = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
zero_new_cam = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
zero_R = (cvRandInt(rng)%2) == 0 ? false : true;
|
||||
|
||||
cvReleaseMat(&_rot);
|
||||
|
||||
if (useCPlus)
|
||||
{
|
||||
camera_mat = &test_mat[INPUT][1];
|
||||
distortion_coeffs = &test_mat[INPUT][2];
|
||||
R = &test_mat[INPUT][3];
|
||||
new_camera_mat = &test_mat[INPUT][4];
|
||||
}
|
||||
delete[] dist;
|
||||
delete[] new_cam;
|
||||
delete[] points;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void CV_InitUndistortRectifyMapTest::prepare_to_validation(int/* test_case_idx*/)
|
||||
{
|
||||
int dist_size = test_mat[INPUT][2].cols > test_mat[INPUT][2].rows ? test_mat[INPUT][2].cols : test_mat[INPUT][2].rows;
|
||||
double cam[9] = {0,0,0,0,0,0,0,0,1};
|
||||
double rot[9] = {1,0,0,0,1,0,0,0,1};
|
||||
double* dist = new double[dist_size ];
|
||||
double* new_cam = new double[test_mat[INPUT][4].cols * test_mat[INPUT][4].rows];
|
||||
double* points = new double[N_POINTS*2];
|
||||
double* r_points = new double[N_POINTS*2];
|
||||
//Run reference calculations
|
||||
CvMat ref_points= cvMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_64FC2,r_points);
|
||||
CvMat _camera = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _rot = cvMat(3,3,CV_64F,rot);
|
||||
CvMat _distort = cvMat(test_mat[INPUT][2].rows,test_mat[INPUT][2].cols,CV_64F,dist);
|
||||
CvMat _new_cam = cvMat(test_mat[INPUT][4].rows,test_mat[INPUT][4].cols,CV_64F,new_cam);
|
||||
CvMat _points= cvMat(test_mat[INPUT][0].rows,test_mat[INPUT][0].cols,CV_64FC2,points);
|
||||
|
||||
cvTsConvert(&test_mat[INPUT][1],&_camera);
|
||||
cvTsConvert(&test_mat[INPUT][2],&_distort);
|
||||
cvTsConvert(&test_mat[INPUT][3],&_rot);
|
||||
cvTsConvert(&test_mat[INPUT][4],&_new_cam);
|
||||
|
||||
//Applying precalculated undistort rectify map
|
||||
if (!useCPlus)
|
||||
{
|
||||
mapx = cv::Mat(_mapx);
|
||||
mapy = cv::Mat(_mapy);
|
||||
}
|
||||
cv::Mat map1,map2;
|
||||
cv::convertMaps(mapx,mapy,map1,map2,CV_32FC1);
|
||||
CvMat _map1 = map1;
|
||||
CvMat _map2 = map2;
|
||||
for (int i=0;i<N_POINTS;i++)
|
||||
{
|
||||
double u = test_mat[INPUT][0].data.db[2*i];
|
||||
double v = test_mat[INPUT][0].data.db[2*i+1];
|
||||
_points.data.db[2*i] = (double)_map1.data.fl[(int)v*_map1.cols+(int)u];
|
||||
_points.data.db[2*i+1] = (double)_map2.data.fl[(int)v*_map2.cols+(int)u];
|
||||
}
|
||||
|
||||
//---
|
||||
|
||||
cvUndistortPoints(&_points,&ref_points,&_camera,
|
||||
zero_distortion ? 0 : &_distort, zero_R ? 0 : &_rot, zero_new_cam ? &_camera : &_new_cam);
|
||||
//cvTsDistortPoints(&_points,&ref_points,&_camera,&_distort,&_rot,&_new_cam);
|
||||
CvMat* dst = &test_mat[REF_OUTPUT][0];
|
||||
cvTsConvert(&ref_points,dst);
|
||||
|
||||
cvCopy(&test_mat[INPUT][0],&test_mat[OUTPUT][0]);
|
||||
|
||||
delete[] dist;
|
||||
delete[] new_cam;
|
||||
delete[] points;
|
||||
delete[] r_points;
|
||||
if (_mapx)
|
||||
{
|
||||
cvReleaseMat(&_mapx);
|
||||
_mapx = 0;
|
||||
}
|
||||
if (_mapy)
|
||||
{
|
||||
cvReleaseMat(&_mapy);
|
||||
_mapy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CV_InitUndistortRectifyMapTest::run_func()
|
||||
{
|
||||
if (useCPlus)
|
||||
{
|
||||
cv::Mat input2,input3,input4;
|
||||
input2 = zero_distortion ? cv::Mat() : cv::Mat(&test_mat[INPUT][2]);
|
||||
input3 = zero_R ? cv::Mat() : cv::Mat(&test_mat[INPUT][3]);
|
||||
input4 = zero_new_cam ? cv::Mat() : cv::Mat(&test_mat[INPUT][4]);
|
||||
cv::initUndistortRectifyMap(camera_mat,input2,input3,input4,img_size,mat_type,mapx,mapy);
|
||||
}
|
||||
else
|
||||
{
|
||||
CvMat* input2;
|
||||
CvMat* input3;
|
||||
CvMat* input4;
|
||||
input2 = zero_distortion ? 0 : &test_mat[INPUT][2];
|
||||
input3 = zero_R ? 0 : &test_mat[INPUT][3];
|
||||
input4 = zero_new_cam ? 0 : &test_mat[INPUT][4];
|
||||
cvInitUndistortRectifyMap(&test_mat[INPUT][1],input2,input3,input4,_mapx,_mapy);
|
||||
}
|
||||
}
|
||||
|
||||
double CV_InitUndistortRectifyMapTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
CV_InitUndistortRectifyMapTest init_undistort_rectify_map_test;
|
||||
@@ -1,745 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_CameraCalibrationBadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_CameraCalibrationBadArgTest() : CvBadArgTest("calibrate-camera-c-badarg", "cvCalibrateCamera2"),
|
||||
imgSize(800, 600)
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
};
|
||||
~CV_CameraCalibrationBadArgTest() {} ;
|
||||
protected:
|
||||
void run(int);
|
||||
void run_func(void) {};
|
||||
|
||||
const static int M = 1;
|
||||
|
||||
Size imgSize;
|
||||
Size corSize;
|
||||
Mat chessBoard;
|
||||
Mat corners;
|
||||
|
||||
struct C_Caller
|
||||
{
|
||||
CvMat* objPts;
|
||||
CvMat* imgPts;
|
||||
CvMat* npoints;
|
||||
Size imageSize;
|
||||
CvMat *cameraMatrix;
|
||||
CvMat *distCoeffs;
|
||||
CvMat *rvecs;
|
||||
CvMat *tvecs;
|
||||
int flags;
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
cvCalibrateCamera2(objPts, imgPts, npoints, imageSize,
|
||||
cameraMatrix, distCoeffs, rvecs, tvecs, flags );
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void CV_CameraCalibrationBadArgTest::run( int /* start_from */ )
|
||||
{
|
||||
Mat_<float> camMat(3, 3);
|
||||
Mat_<float> distCoeffs0(1, 5);
|
||||
|
||||
camMat << 300.f, 0.f, imgSize.width/2.f, 0, 300.f, imgSize.height/2.f, 0.f, 0.f, 1.f;
|
||||
distCoeffs0 << 1.2f, 0.2f, 0.f, 0.f, 0.f;
|
||||
|
||||
ChessBoardGenerator cbg(Size(8,6));
|
||||
corSize = cbg.cornersSize();
|
||||
vector<Point2f> exp_corn;
|
||||
chessBoard = cbg(Mat(imgSize, CV_8U, Scalar(0)), camMat, distCoeffs0, exp_corn);
|
||||
Mat_<Point2f>(corSize.height, corSize.width, (Point2f*)&exp_corn[0]).copyTo(corners);
|
||||
|
||||
CvMat objPts, imgPts, npoints, cameraMatrix, distCoeffs, rvecs, tvecs;
|
||||
Mat zeros(1, sizeof(CvMat), CV_8U, Scalar(0));
|
||||
|
||||
C_Caller caller, bad_caller;
|
||||
caller.imageSize = imgSize;
|
||||
caller.objPts = &objPts;
|
||||
caller.imgPts = &imgPts;
|
||||
caller.npoints = &npoints;
|
||||
caller.cameraMatrix = &cameraMatrix;
|
||||
caller.distCoeffs = &distCoeffs;
|
||||
caller.rvecs = &rvecs;
|
||||
caller.tvecs = &tvecs;
|
||||
|
||||
/////////////////////////////
|
||||
Mat objPts_cpp;
|
||||
Mat imgPts_cpp;
|
||||
Mat npoints_cpp;
|
||||
Mat cameraMatrix_cpp;
|
||||
Mat distCoeffs_cpp;
|
||||
Mat rvecs_cpp;
|
||||
Mat tvecs_cpp;
|
||||
|
||||
objPts_cpp.create(corSize, CV_32FC3);
|
||||
for(int j = 0; j < corSize.height; ++j)
|
||||
for(int i = 0; i < corSize.width; ++i)
|
||||
objPts_cpp.at<Point3f>(j, i) = Point3i(i, j, 0);
|
||||
objPts_cpp = objPts_cpp.reshape(3, 1);
|
||||
|
||||
imgPts_cpp = corners.clone().reshape(2, 1);
|
||||
npoints_cpp = Mat_<int>(M, 1, corSize.width * corSize.height);
|
||||
cameraMatrix_cpp.create(3, 3, CV_32F);
|
||||
distCoeffs_cpp.create(5, 1, CV_32F);
|
||||
rvecs_cpp.create(M, 1, CV_32FC3);
|
||||
tvecs_cpp.create(M, 1, CV_32FC3);
|
||||
|
||||
caller.flags = 0;
|
||||
//CV_CALIB_USE_INTRINSIC_GUESS; //CV_CALIB_FIX_ASPECT_RATIO
|
||||
//CV_CALIB_USE_INTRINSIC_GUESS //CV_CALIB_FIX_ASPECT_RATIO
|
||||
//CV_CALIB_FIX_PRINCIPAL_POINT //CV_CALIB_ZERO_TANGENT_DIST
|
||||
//CV_CALIB_FIX_FOCAL_LENGTH //CV_CALIB_FIX_K1 //CV_CALIB_FIX_K2 //CV_CALIB_FIX_K3
|
||||
|
||||
objPts = objPts_cpp;
|
||||
imgPts = imgPts_cpp;
|
||||
npoints = npoints_cpp;
|
||||
cameraMatrix = cameraMatrix_cpp;
|
||||
distCoeffs = distCoeffs_cpp;
|
||||
rvecs = rvecs_cpp;
|
||||
tvecs = tvecs_cpp;
|
||||
|
||||
/* /*//*/ */
|
||||
int errors = 0;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.objPts = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero passed in objPts", bad_caller);
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.imgPts = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero passed in imgPts", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.npoints = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero passed in npoints", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.cameraMatrix = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero passed in cameraMatrix", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero passed in distCoeffs", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.imageSize.width = -1;
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad image width", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.imageSize.height = -1;
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad image height", bad_caller );
|
||||
|
||||
Mat bad_nts_cpp1 = Mat_<float>(M, 1, 1.f);
|
||||
Mat bad_nts_cpp2 = Mat_<int>(3, 3, corSize.width * corSize.height);
|
||||
CvMat bad_npts_c1 = bad_nts_cpp1;
|
||||
CvMat bad_npts_c2 = bad_nts_cpp2;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.npoints = &bad_npts_c1;
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "Bad npoints format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.npoints = &bad_npts_c2;
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "Bad npoints size", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.rvecs = (CvMat*)zeros.ptr();
|
||||
errors += run_test_case( CV_StsBadArg, "Bad rvecs header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.tvecs = (CvMat*)zeros.ptr();
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvecs header", bad_caller );
|
||||
|
||||
Mat bad_rvecs_cpp1(M+1, 1, CV_32FC3); CvMat bad_rvecs_c1 = bad_rvecs_cpp1;
|
||||
Mat bad_tvecs_cpp1(M+1, 1, CV_32FC3); CvMat bad_tvecs_c1 = bad_tvecs_cpp1;
|
||||
|
||||
|
||||
|
||||
Mat bad_rvecs_cpp2(M, 2, CV_32FC3); CvMat bad_rvecs_c2 = bad_rvecs_cpp2;
|
||||
Mat bad_tvecs_cpp2(M, 2, CV_32FC3); CvMat bad_tvecs_c2 = bad_tvecs_cpp2;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.rvecs = &bad_rvecs_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvecs header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.rvecs = &bad_rvecs_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvecs header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.tvecs = &bad_tvecs_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvecs header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.tvecs = &bad_tvecs_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvecs header", bad_caller );
|
||||
|
||||
Mat bad_cameraMatrix_cpp1(3, 3, CV_32S); CvMat bad_cameraMatrix_c1 = bad_cameraMatrix_cpp1;
|
||||
Mat bad_cameraMatrix_cpp2(2, 3, CV_32F); CvMat bad_cameraMatrix_c2 = bad_cameraMatrix_cpp2;
|
||||
Mat bad_cameraMatrix_cpp3(3, 2, CV_64F); CvMat bad_cameraMatrix_c3 = bad_cameraMatrix_cpp3;
|
||||
|
||||
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.cameraMatrix = &bad_cameraMatrix_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad camearaMatrix header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.cameraMatrix = &bad_cameraMatrix_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad camearaMatrix header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.cameraMatrix = &bad_cameraMatrix_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad camearaMatrix header", bad_caller );
|
||||
|
||||
Mat bad_distCoeffs_cpp1(1, 5, CV_32S); CvMat bad_distCoeffs_c1 = bad_distCoeffs_cpp1;
|
||||
Mat bad_distCoeffs_cpp2(2, 2, CV_64F); CvMat bad_distCoeffs_c2 = bad_distCoeffs_cpp2;
|
||||
Mat bad_distCoeffs_cpp3(1, 6, CV_64F); CvMat bad_distCoeffs_c3 = bad_distCoeffs_cpp3;
|
||||
|
||||
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs header", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs header", bad_caller );
|
||||
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs header", bad_caller );
|
||||
|
||||
double CM[] = {0, 0, 0, /**/0, 0, 0, /**/0, 0, 0};
|
||||
Mat bad_cameraMatrix_cpp4(3, 3, CV_64F, CM); CvMat bad_cameraMatrix_c4 = bad_cameraMatrix_cpp4;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.flags |= CV_CALIB_USE_INTRINSIC_GUESS;
|
||||
bad_caller.cameraMatrix = &bad_cameraMatrix_c4;
|
||||
CM[0] = 0; //bad fx
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 0; //bad fy
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 500; CM[2] = -1; //bad cx
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 500; CM[2] = imgSize.width*2; //bad cx
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 500; CM[2] = imgSize.width/2; CM[5] = -1; //bad cy
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 500; CM[2] = imgSize.width/2; CM[5] = imgSize.height*2; //bad cy
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[0] = 500; CM[4] = 500; CM[2] = imgSize.width/2; CM[5] = imgSize.height/2;
|
||||
CM[1] = 0.1; //Non-zero skew
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[1] = 0;
|
||||
CM[3] = 0.1; /* mad matrix shape */
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[3] = 0; CM[6] = 0.1; /* mad matrix shape */
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[3] = 0; CM[6] = 0; CM[7] = 0.1; /* mad matrix shape */
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
|
||||
CM[3] = 0; CM[6] = 0; CM[7] = 0; CM[8] = 1.1; /* mad matrix shape */
|
||||
errors += run_test_case( CV_StsOutOfRange, "Bad camearaMatrix data", bad_caller );
|
||||
CM[8] = 1.0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
bad_caller = caller;
|
||||
Mat bad_objPts_cpp5 = objPts_cpp.clone(); CvMat bad_objPts_c5 = bad_objPts_cpp5;
|
||||
bad_caller.objPts = &bad_objPts_c5;
|
||||
|
||||
cv::RNG& rng = theRNG();
|
||||
for(int i = 0; i < bad_objPts_cpp5.rows; ++i)
|
||||
bad_objPts_cpp5.at<Point3f>(0, i).z += ((float)rng - 0.5f);
|
||||
|
||||
errors += run_test_case( CV_StsBadArg, "Bad objPts data", bad_caller );
|
||||
|
||||
if (errors)
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
|
||||
//try { caller(); }
|
||||
//catch (...)
|
||||
//{
|
||||
// ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
// printf("+!");
|
||||
//}
|
||||
}
|
||||
|
||||
CV_CameraCalibrationBadArgTest camera_calibration_bad_arg_test;
|
||||
|
||||
|
||||
class CV_Rodrigues2BadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_Rodrigues2BadArgTest() : CvBadArgTest("_3d-rodrigues-badarg", "cvRodrigues2") { };
|
||||
~CV_Rodrigues2BadArgTest() {} ;
|
||||
protected:
|
||||
void run_func(void) {};
|
||||
|
||||
struct C_Caller
|
||||
{
|
||||
CvMat* src;
|
||||
CvMat* dst;
|
||||
CvMat* jacobian;
|
||||
|
||||
void operator()() { cvRodrigues2(src, dst, jacobian); }
|
||||
};
|
||||
|
||||
void run(int /* start_from */ )
|
||||
{
|
||||
Mat zeros(1, sizeof(CvMat), CV_8U, Scalar(0));
|
||||
CvMat src_c, dst_c, jacobian_c;
|
||||
|
||||
Mat src_cpp(3, 1, CV_32F); src_c = src_cpp;
|
||||
Mat dst_cpp(3, 3, CV_32F); dst_c = dst_cpp;
|
||||
Mat jacobian_cpp(3, 9, CV_32F); jacobian_c = jacobian_cpp;
|
||||
|
||||
C_Caller caller, bad_caller;
|
||||
caller.src = &src_c;
|
||||
caller.dst = &dst_c;
|
||||
caller.jacobian = &jacobian_c;
|
||||
|
||||
/* try { caller(); }
|
||||
catch (...)
|
||||
{
|
||||
printf("badasfas");
|
||||
}*/
|
||||
|
||||
/*/*//*/*/
|
||||
int errors = 0;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.src = 0;
|
||||
errors += run_test_case( CV_StsNullPtr, "Src is zero pointer", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = 0;
|
||||
errors += run_test_case( CV_StsNullPtr, "Dst is zero pointer", bad_caller );
|
||||
|
||||
Mat bad_src_cpp1(3, 1, CV_8U); CvMat bad_src_c1 = bad_src_cpp1;
|
||||
Mat bad_dst_cpp1(3, 1, CV_8U); CvMat bad_dst_c1 = bad_dst_cpp1;
|
||||
Mat bad_jac_cpp1(3, 1, CV_8U); CvMat bad_jac_c1 = bad_jac_cpp1;
|
||||
Mat bad_jac_cpp2(3, 1, CV_32FC2); CvMat bad_jac_c2 = bad_jac_cpp2;
|
||||
Mat bad_jac_cpp3(3, 1, CV_32F); CvMat bad_jac_c3 = bad_jac_cpp3;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.src = &bad_src_c1;
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "Bad src formart", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = &bad_dst_c1;
|
||||
errors += run_test_case( CV_StsUnmatchedFormats, "Bad dst formart", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.jacobian = (CvMat*)zeros.ptr();
|
||||
errors += run_test_case( CV_StsBadArg, "Bad jacobian ", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.jacobian = &bad_jac_c1;
|
||||
errors += run_test_case( CV_StsUnmatchedFormats, "Bad jacobian format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.jacobian = &bad_jac_c2;
|
||||
errors += run_test_case( CV_StsUnmatchedFormats, "Bad jacobian format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.jacobian = &bad_jac_c3;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad jacobian format", bad_caller );
|
||||
|
||||
Mat bad_src_cpp2(1, 1, CV_32F); CvMat bad_src_c2 = bad_src_cpp2;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.src = &bad_src_c2;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad src format", bad_caller );
|
||||
|
||||
Mat bad_dst_cpp2(2, 1, CV_32F); CvMat bad_dst_c2 = bad_dst_cpp2;
|
||||
Mat bad_dst_cpp3(3, 2, CV_32F); CvMat bad_dst_c3 = bad_dst_cpp3;
|
||||
Mat bad_dst_cpp4(3, 3, CV_32FC2); CvMat bad_dst_c4 = bad_dst_cpp4;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = &bad_dst_c2;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad dst format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = &bad_dst_c3;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad dst format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = &bad_dst_c4;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad dst format", bad_caller );
|
||||
|
||||
|
||||
/********/
|
||||
src_cpp.create(3, 3, CV_32F); src_c = src_cpp;
|
||||
dst_cpp.create(3, 1, CV_32F); dst_c = dst_cpp;
|
||||
|
||||
|
||||
Mat bad_dst_cpp5(5, 5, CV_32F); CvMat bad_dst_c5 = bad_dst_cpp5;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dst = &bad_dst_c5;
|
||||
errors += run_test_case( CV_StsBadSize, "Bad dst format", bad_caller );
|
||||
|
||||
|
||||
if (errors)
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
CV_Rodrigues2BadArgTest cv_rodrigues2_badarg_test;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
class CV_ProjectPoints2BadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_ProjectPoints2BadArgTest() : CvBadArgTest("projectPoints-badarg", "cvProjectPoints2"),
|
||||
camMat(3, 3), distCoeffs(1, 5)
|
||||
{
|
||||
Size imsSize(800, 600);
|
||||
camMat << 300.f, 0.f, imsSize.width/2.f, 0, 300.f, imsSize.height/2.f, 0.f, 0.f, 1.f;
|
||||
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
|
||||
};
|
||||
~CV_ProjectPoints2BadArgTest() {} ;
|
||||
protected:
|
||||
void run_func(void) {};
|
||||
|
||||
Mat_<float> camMat;
|
||||
Mat_<float> distCoeffs;
|
||||
|
||||
struct C_Caller
|
||||
{
|
||||
CvMat* objectPoints;
|
||||
CvMat* r_vec;
|
||||
CvMat* t_vec;
|
||||
CvMat* A;
|
||||
CvMat* distCoeffs;
|
||||
CvMat* imagePoints;
|
||||
CvMat* dpdr;
|
||||
CvMat* dpdt;
|
||||
CvMat* dpdf;
|
||||
CvMat* dpdc;
|
||||
CvMat* dpdk;
|
||||
double aspectRatio;
|
||||
|
||||
void operator()()
|
||||
{
|
||||
cvProjectPoints2( objectPoints, r_vec, t_vec, A, distCoeffs, imagePoints,
|
||||
dpdr, dpdt, dpdf, dpdc, dpdk, aspectRatio );
|
||||
}
|
||||
};
|
||||
|
||||
void run(int /* start_from */ )
|
||||
{
|
||||
CvMat zeros;
|
||||
memset(&zeros, 0, sizeof(zeros));
|
||||
|
||||
C_Caller caller, bad_caller;
|
||||
CvMat objectPoints_c, r_vec_c, t_vec_c, A_c, distCoeffs_c, imagePoints_c,
|
||||
dpdr_c, dpdt_c, dpdf_c, dpdc_c, dpdk_c;
|
||||
|
||||
const int n = 10;
|
||||
|
||||
Mat imagePoints_cpp(1, n, CV_32FC2); imagePoints_c = imagePoints_cpp;
|
||||
|
||||
Mat objectPoints_cpp(1, n, CV_32FC3);
|
||||
randu(objectPoints_cpp, Scalar::all(1), Scalar::all(10));
|
||||
objectPoints_c = objectPoints_cpp;
|
||||
|
||||
Mat t_vec_cpp(Mat::zeros(1, 3, CV_32F)); t_vec_c = t_vec_cpp;
|
||||
Mat r_vec_cpp;
|
||||
Rodrigues(Mat::eye(3, 3, CV_32F), r_vec_cpp); r_vec_c = r_vec_cpp;
|
||||
|
||||
Mat A_cpp = camMat.clone(); A_c = A_cpp;
|
||||
Mat distCoeffs_cpp = distCoeffs.clone(); distCoeffs_c = distCoeffs_cpp;
|
||||
|
||||
Mat dpdr_cpp(2*n, 3, CV_32F); dpdr_c = dpdr_cpp;
|
||||
Mat dpdt_cpp(2*n, 3, CV_32F); dpdt_c = dpdt_cpp;
|
||||
Mat dpdf_cpp(2*n, 2, CV_32F); dpdf_c = dpdf_cpp;
|
||||
Mat dpdc_cpp(2*n, 2, CV_32F); dpdc_c = dpdc_cpp;
|
||||
Mat dpdk_cpp(2*n, 4, CV_32F); dpdk_c = dpdk_cpp;
|
||||
|
||||
caller.aspectRatio = 1.0;
|
||||
caller.objectPoints = &objectPoints_c;
|
||||
caller.r_vec = &r_vec_c;
|
||||
caller.t_vec = &t_vec_c;
|
||||
caller.A = &A_c;
|
||||
caller.distCoeffs = &distCoeffs_c;
|
||||
caller.imagePoints = &imagePoints_c;
|
||||
caller.dpdr = &dpdr_c;
|
||||
caller.dpdt = &dpdt_c;
|
||||
caller.dpdf = &dpdf_c;
|
||||
caller.dpdc = &dpdc_c;
|
||||
caller.dpdk = &dpdk_c;
|
||||
|
||||
/********************/
|
||||
int errors = 0;
|
||||
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.objectPoints = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero objectPoints", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.r_vec = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero r_vec", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.t_vec = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero t_vec", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.A = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero camMat", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.imagePoints = 0;
|
||||
errors += run_test_case( CV_StsBadArg, "Zero imagePoints", bad_caller );
|
||||
|
||||
/****************************/
|
||||
Mat bad_r_vec_cpp1(r_vec_cpp.size(), CV_32S); CvMat bad_r_vec_c1 = bad_r_vec_cpp1;
|
||||
Mat bad_r_vec_cpp2(2, 2, CV_32F); CvMat bad_r_vec_c2 = bad_r_vec_cpp2;
|
||||
Mat bad_r_vec_cpp3(r_vec_cpp.size(), CV_32FC2); CvMat bad_r_vec_c3 = bad_r_vec_cpp3;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.r_vec = &bad_r_vec_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad rvec format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.r_vec = &bad_r_vec_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad rvec format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.r_vec = &bad_r_vec_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad rvec format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
Mat bad_t_vec_cpp1(t_vec_cpp.size(), CV_32S); CvMat bad_t_vec_c1 = bad_t_vec_cpp1;
|
||||
Mat bad_t_vec_cpp2(2, 2, CV_32F); CvMat bad_t_vec_c2 = bad_t_vec_cpp2;
|
||||
Mat bad_t_vec_cpp3(1, 1, CV_32FC2); CvMat bad_t_vec_c3 = bad_t_vec_cpp3;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.t_vec = &bad_t_vec_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvec format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.t_vec = &bad_t_vec_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvec format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.t_vec = &bad_t_vec_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad tvec format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
Mat bad_A_cpp1(A_cpp.size(), CV_32S); CvMat bad_A_c1 = bad_A_cpp1;
|
||||
Mat bad_A_cpp2(2, 2, CV_32F); CvMat bad_A_c2 = bad_A_cpp2;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.A = &bad_A_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad A format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.A = &bad_A_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad A format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
Mat bad_distCoeffs_cpp1(distCoeffs_cpp.size(), CV_32S); CvMat bad_distCoeffs_c1 = bad_distCoeffs_cpp1;
|
||||
Mat bad_distCoeffs_cpp2(2, 2, CV_32F); CvMat bad_distCoeffs_c2 = bad_distCoeffs_cpp2;
|
||||
Mat bad_distCoeffs_cpp3(1, 7, CV_32F); CvMat bad_distCoeffs_c3 = bad_distCoeffs_cpp3;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = &bad_distCoeffs_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad distCoeffs format", bad_caller );
|
||||
|
||||
|
||||
/****************************/
|
||||
Mat bad_dpdr_cpp1(dpdr_cpp.size(), CV_32S); CvMat bad_dpdr_c1 = bad_dpdr_cpp1;
|
||||
Mat bad_dpdr_cpp2(dpdr_cpp.cols+1, 3, CV_32F); CvMat bad_dpdr_c2 = bad_dpdr_cpp2;
|
||||
Mat bad_dpdr_cpp3(dpdr_cpp.cols, 7, CV_32F); CvMat bad_dpdr_c3 = bad_dpdr_cpp3;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdr = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdr format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdr = &bad_dpdr_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdr format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdr = &bad_dpdr_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdr format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdr = &bad_dpdr_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdr format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdt = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdt format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdt = &bad_dpdr_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdt format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdt = &bad_dpdr_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdt format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdt = &bad_dpdr_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdt format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
|
||||
Mat bad_dpdf_cpp2(dpdr_cpp.cols+1, 2, CV_32F); CvMat bad_dpdf_c2 = bad_dpdf_cpp2;
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdf = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdf format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdf = &bad_dpdr_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdf format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdf = &bad_dpdf_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdf format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdf = &bad_dpdr_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdf format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdc = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdc format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdc = &bad_dpdr_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdc format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdc = &bad_dpdf_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdc format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdc = &bad_dpdr_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdc format", bad_caller );
|
||||
|
||||
/****************************/
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdk = &zeros;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdk format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdk = &bad_dpdr_c1;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdk format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdk = &bad_dpdf_c2;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdk format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.dpdk = &bad_dpdr_c3;
|
||||
errors += run_test_case( CV_StsBadArg, "Bad dpdk format", bad_caller );
|
||||
|
||||
bad_caller = caller;
|
||||
bad_caller.distCoeffs = 0;
|
||||
errors += run_test_case( CV_StsNullPtr, "distCoeffs is NULL while dpdk is not", bad_caller );
|
||||
|
||||
|
||||
if (errors)
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
CV_ProjectPoints2BadArgTest projectPoints2_badarg_test;
|
||||
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class CV_ChessboardDetectorBadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_ChessboardDetectorBadArgTest();
|
||||
protected:
|
||||
void run(int);
|
||||
bool checkByGenerator();
|
||||
|
||||
bool cpp;
|
||||
|
||||
/* cpp interface */
|
||||
Mat img;
|
||||
Size pattern_size;
|
||||
int flags;
|
||||
vector<Point2f> corners;
|
||||
|
||||
/* c interface */
|
||||
CvMat arr;
|
||||
CvPoint2D32f* out_corners;
|
||||
int* out_corner_count;
|
||||
|
||||
|
||||
/* c interface draw corners */
|
||||
bool drawCorners;
|
||||
CvMat drawCorImg;
|
||||
bool was_found;
|
||||
|
||||
void run_func()
|
||||
{
|
||||
if (cpp)
|
||||
findChessboardCorners(img, pattern_size, corners, flags);
|
||||
else
|
||||
if (!drawCorners)
|
||||
cvFindChessboardCorners( &arr, pattern_size, out_corners, out_corner_count, flags );
|
||||
else
|
||||
cvDrawChessboardCorners( &drawCorImg, pattern_size,
|
||||
(CvPoint2D32f*)&corners[0], (int)corners.size(), was_found);
|
||||
}
|
||||
};
|
||||
|
||||
CV_ChessboardDetectorBadArgTest::CV_ChessboardDetectorBadArgTest():
|
||||
CvBadArgTest( "chessboard-detector-badarg", "cvFindChessboardCorners" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
/* ///////////////////// chess_corner_test ///////////////////////// */
|
||||
void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)
|
||||
{
|
||||
Mat bg(800, 600, CV_8U, Scalar(0));
|
||||
Mat_<float> camMat(3, 3);
|
||||
camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
|
||||
Mat_<float> distCoeffs(1, 5);
|
||||
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
|
||||
|
||||
ChessBoardGenerator cbg(Size(8,6));
|
||||
vector<Point2f> exp_corn;
|
||||
Mat cb = cbg(bg, camMat, distCoeffs, exp_corn);
|
||||
|
||||
/* /*//*/ */
|
||||
int errors = 0;
|
||||
flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE;
|
||||
cpp = true;
|
||||
|
||||
img = cb.clone();
|
||||
pattern_size = Size(2,2);
|
||||
errors += run_test_case( CV_StsOutOfRange, "Invlid pattern size" );
|
||||
|
||||
pattern_size = cbg.cornersSize();
|
||||
cb.convertTo(img, CV_32F);
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "Not 8-bit image" );
|
||||
|
||||
cv::merge(vector<Mat>(2, cb), img);
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );
|
||||
|
||||
cpp = false;
|
||||
drawCorners = false;
|
||||
|
||||
img = cb.clone();
|
||||
arr = img;
|
||||
out_corner_count = 0;
|
||||
out_corners = 0;
|
||||
errors += run_test_case( CV_StsNullPtr, "Null pointer to corners" );
|
||||
|
||||
drawCorners = true;
|
||||
Mat cvdrawCornImg(img.size(), CV_8UC2);
|
||||
drawCorImg = cvdrawCornImg;
|
||||
was_found = true;
|
||||
errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );
|
||||
|
||||
|
||||
if (errors)
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_ChessboardDetectorBadArgTest chessboard_detector_arg_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,522 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_UndistortPointsBadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_UndistortPointsBadArgTest();
|
||||
protected:
|
||||
void run(int);
|
||||
void run_func();
|
||||
|
||||
private:
|
||||
//common
|
||||
cv::Size img_size;
|
||||
bool useCPlus;
|
||||
//static const int N_POINTS = 1;
|
||||
static const int N_POINTS2 = 2;
|
||||
|
||||
//C
|
||||
CvMat* _camera_mat;
|
||||
CvMat* matR;
|
||||
CvMat* matP;
|
||||
CvMat* _distortion_coeffs;
|
||||
CvMat* _src_points;
|
||||
CvMat* _dst_points;
|
||||
|
||||
|
||||
//C++
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat R;
|
||||
cv::Mat P;
|
||||
cv::Mat distortion_coeffs;
|
||||
cv::Mat src_points;
|
||||
std::vector<cv::Point2f> dst_points;
|
||||
|
||||
};
|
||||
|
||||
CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ():
|
||||
CvBadArgTest( "undistort-points-badarg", "cvUndistortPoints" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_UndistortPointsBadArgTest::run_func()
|
||||
{
|
||||
if (useCPlus)
|
||||
{
|
||||
cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvUndistortPoints(_src_points,_dst_points,_camera_mat,_distortion_coeffs,matR,matP);
|
||||
}
|
||||
}
|
||||
|
||||
void CV_UndistortPointsBadArgTest::run(int)
|
||||
{
|
||||
//CvRNG* rng = ts->get_rng();
|
||||
int errcount = 0;
|
||||
useCPlus = false;
|
||||
//initializing
|
||||
img_size.width = 800;
|
||||
img_size.height = 600;
|
||||
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
|
||||
double dist[4] = {0.01,0.02,0.001,0.0005};
|
||||
double s_points[N_POINTS2] = {img_size.width/4,img_size.height/4};
|
||||
double d_points[N_POINTS2];
|
||||
double p[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
|
||||
double r[9] = {1,0,0,0,1,0,0,0,1};
|
||||
|
||||
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
|
||||
CvMat _P_orig = cvMat(3,3,CV_64F,p);
|
||||
CvMat _R_orig = cvMat(3,3,CV_64F,r);
|
||||
CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
|
||||
CvMat _dst_points_orig = cvMat(1,4,CV_64FC2,d_points);
|
||||
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
matP = &_P_orig;
|
||||
matR = &_R_orig;
|
||||
_src_points = &_src_points_orig;
|
||||
_dst_points = &_dst_points_orig;
|
||||
|
||||
//tests
|
||||
CvMat* temp1;
|
||||
CvMat* temp;
|
||||
IplImage* temp_img = cvCreateImage(cvSize(img_size.width,img_size.height),8,3);
|
||||
|
||||
//-----------
|
||||
temp = (CvMat*)temp_img;
|
||||
_src_points = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Input data is not CvMat*" );
|
||||
_src_points = &_src_points_orig;
|
||||
|
||||
temp = (CvMat*)temp_img;
|
||||
_dst_points = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Output data is not CvMat*" );
|
||||
_dst_points = &_dst_points_orig;
|
||||
|
||||
temp = cvCreateMat(2,3,CV_64F);
|
||||
_src_points = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
|
||||
_src_points = &_src_points_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(2,3,CV_64F);
|
||||
_dst_points = temp;
|
||||
errcount += run_test_case(CV_StsAssert, "Invalid output data matrix size" );
|
||||
_dst_points = &_dst_points_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(1,3,CV_64F);
|
||||
temp1 = cvCreateMat(4,1,CV_64F);
|
||||
_dst_points = temp;
|
||||
_src_points = temp1;
|
||||
errcount += run_test_case(CV_StsAssert, "Output and input data sizes mismatch" );
|
||||
_dst_points = &_dst_points_orig;
|
||||
_src_points = &_src_points_orig;
|
||||
cvReleaseMat(&temp);
|
||||
cvReleaseMat(&temp1);
|
||||
|
||||
temp = cvCreateMat(1,3,CV_32S);
|
||||
_dst_points = temp;
|
||||
errcount += run_test_case(CV_StsAssert, "Invalid output data matrix type" );
|
||||
_dst_points = &_dst_points_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(1,3,CV_32S);
|
||||
_src_points = temp;
|
||||
errcount += run_test_case(CV_StsAssert, "Invalid input data matrix type" );
|
||||
_src_points = &_src_points_orig;
|
||||
cvReleaseMat(&temp);
|
||||
//------------
|
||||
temp = cvCreateMat(2,3,CV_64F);
|
||||
_camera_mat = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(3,4,CV_64F);
|
||||
_camera_mat = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = (CvMat*)temp_img;
|
||||
_camera_mat = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Camera data is not CvMat*" );
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
//----------
|
||||
|
||||
temp = (CvMat*)temp_img;
|
||||
_distortion_coeffs = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Distortion coefficients data is not CvMat*" );
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
|
||||
temp = cvCreateMat(1,6,CV_64F);
|
||||
_distortion_coeffs = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(3,3,CV_64F);
|
||||
_distortion_coeffs = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
cvReleaseMat(&temp);
|
||||
//----------
|
||||
temp = (CvMat*)temp_img;
|
||||
matR = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "R data is not CvMat*" );
|
||||
matR = &_R_orig;
|
||||
|
||||
temp = cvCreateMat(4,3,CV_64F);
|
||||
matR = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
|
||||
matR = &_R_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(3,2,CV_64F);
|
||||
matR = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
|
||||
matR = &_R_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
//-----------
|
||||
temp = (CvMat*)temp_img;
|
||||
matP = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "P data is not CvMat*" );
|
||||
matP = &_P_orig;
|
||||
|
||||
temp = cvCreateMat(4,3,CV_64F);
|
||||
matP = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
|
||||
matP = &_P_orig;
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(3,2,CV_64F);
|
||||
matP = temp;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
|
||||
matP = &_P_orig;
|
||||
cvReleaseMat(&temp);
|
||||
//------------
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
P = cv::Mat(&_P_orig);
|
||||
R = cv::Mat(&_R_orig);
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
|
||||
temp = cvCreateMat(2,2,CV_32FC2);
|
||||
src_points = cv::Mat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(1,4,CV_64FC2);
|
||||
src_points = cv::Mat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
src_points = cv::Mat();
|
||||
errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );
|
||||
src_points = cv::Mat(&_src_points_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
|
||||
|
||||
//------------
|
||||
cvReleaseImage(&temp_img);
|
||||
ts->set_failed_test_info(errcount > 0 ? CvTS::FAIL_BAD_ARG_CHECK : CvTS::OK);
|
||||
}
|
||||
|
||||
CV_UndistortPointsBadArgTest default_new_camera_matrix_badarg_test;
|
||||
//=========
|
||||
class CV_InitUndistortRectifyMapBadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_InitUndistortRectifyMapBadArgTest();
|
||||
protected:
|
||||
void run(int);
|
||||
void run_func();
|
||||
|
||||
private:
|
||||
//common
|
||||
cv::Size img_size;
|
||||
bool useCPlus;
|
||||
|
||||
//C
|
||||
CvMat* _camera_mat;
|
||||
CvMat* matR;
|
||||
CvMat* _new_camera_mat;
|
||||
CvMat* _distortion_coeffs;
|
||||
CvMat* _mapx;
|
||||
CvMat* _mapy;
|
||||
|
||||
|
||||
//C++
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat R;
|
||||
cv::Mat new_camera_mat;
|
||||
cv::Mat distortion_coeffs;
|
||||
cv::Mat mapx;
|
||||
cv::Mat mapy;
|
||||
int mat_type;
|
||||
|
||||
};
|
||||
|
||||
CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ():
|
||||
CvBadArgTest( "undistort-undistort_rectify_map-badarg","cvInitUndistortRectifyMap" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_InitUndistortRectifyMapBadArgTest::run_func()
|
||||
{
|
||||
if (useCPlus)
|
||||
{
|
||||
cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvInitUndistortRectifyMap(_camera_mat,_distortion_coeffs,matR,_new_camera_mat,_mapx,_mapy);
|
||||
}
|
||||
}
|
||||
|
||||
void CV_InitUndistortRectifyMapBadArgTest::run(int)
|
||||
{
|
||||
int errcount = 0;
|
||||
//initializing
|
||||
img_size.width = 800;
|
||||
img_size.height = 600;
|
||||
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
|
||||
double dist[4] = {0.01,0.02,0.001,0.0005};
|
||||
float* arr_mapx = new float[img_size.width*img_size.height];
|
||||
float* arr_mapy = new float[img_size.width*img_size.height];
|
||||
double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
|
||||
double r[9] = {1,0,0,0,1,0,0,0,1};
|
||||
|
||||
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
|
||||
CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
|
||||
CvMat _R_orig = cvMat(3,3,CV_64F,r);
|
||||
CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapx);
|
||||
CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapy);
|
||||
int mat_type_orig = CV_32FC1;
|
||||
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
_new_camera_mat = &_new_camera_mat_orig;
|
||||
matR = &_R_orig;
|
||||
_mapx = &_mapx_orig;
|
||||
_mapy = &_mapy_orig;
|
||||
mat_type = mat_type_orig;
|
||||
|
||||
//tests
|
||||
useCPlus = true;
|
||||
CvMat* temp;
|
||||
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::Mat(&_new_camera_mat_orig);
|
||||
R = cv::Mat(&_R_orig);
|
||||
mapx = cv::Mat(&_mapx_orig);
|
||||
mapy = cv::Mat(&_mapy_orig);
|
||||
|
||||
|
||||
mat_type = CV_64F;
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
|
||||
mat_type = mat_type_orig;
|
||||
|
||||
temp = cvCreateMat(3,2,CV_32FC1);
|
||||
camera_mat = cv::Mat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(4,3,CV_32FC1);
|
||||
R = cv::Mat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
|
||||
R = cv::Mat(&_R_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
temp = cvCreateMat(6,1,CV_32FC1);
|
||||
distortion_coeffs = cv::Mat(temp);
|
||||
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
cvReleaseMat(&temp);
|
||||
|
||||
//------------
|
||||
delete[] arr_mapx;
|
||||
delete[] arr_mapy;
|
||||
ts->set_failed_test_info(errcount > 0 ? CvTS::FAIL_BAD_ARG_CHECK : CvTS::OK);
|
||||
}
|
||||
|
||||
CV_InitUndistortRectifyMapBadArgTest init_undistort_rectify_map_badarg_test;
|
||||
|
||||
//=========
|
||||
class CV_UndistortBadArgTest : public CvBadArgTest
|
||||
{
|
||||
public:
|
||||
CV_UndistortBadArgTest();
|
||||
protected:
|
||||
void run(int);
|
||||
void run_func();
|
||||
|
||||
private:
|
||||
//common
|
||||
cv::Size img_size;
|
||||
bool useCPlus;
|
||||
|
||||
//C
|
||||
CvMat* _camera_mat;
|
||||
CvMat* _new_camera_mat;
|
||||
CvMat* _distortion_coeffs;
|
||||
CvMat* _src;
|
||||
CvMat* _dst;
|
||||
|
||||
|
||||
//C++
|
||||
cv::Mat camera_mat;
|
||||
cv::Mat new_camera_mat;
|
||||
cv::Mat distortion_coeffs;
|
||||
cv::Mat src;
|
||||
cv::Mat dst;
|
||||
|
||||
};
|
||||
|
||||
CV_UndistortBadArgTest::CV_UndistortBadArgTest ():
|
||||
CvBadArgTest( "undistort-badarg","cvUndistort2" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
void CV_UndistortBadArgTest::run_func()
|
||||
{
|
||||
if (useCPlus)
|
||||
{
|
||||
cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvUndistort2(_src,_dst,_camera_mat,_distortion_coeffs,_new_camera_mat);
|
||||
}
|
||||
}
|
||||
|
||||
void CV_UndistortBadArgTest::run(int)
|
||||
{
|
||||
int errcount = 0;
|
||||
//initializing
|
||||
img_size.width = 800;
|
||||
img_size.height = 600;
|
||||
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
|
||||
double dist[4] = {0.01,0.02,0.001,0.0005};
|
||||
float* arr_src = new float[img_size.width*img_size.height];
|
||||
float* arr_dst = new float[img_size.width*img_size.height];
|
||||
double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
|
||||
|
||||
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
|
||||
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
|
||||
CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
|
||||
CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_src);
|
||||
CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_dst);
|
||||
|
||||
_camera_mat = &_camera_mat_orig;
|
||||
_distortion_coeffs = &_distortion_coeffs_orig;
|
||||
_new_camera_mat = &_new_camera_mat_orig;
|
||||
_src = &_src_orig;
|
||||
_dst = &_dst_orig;
|
||||
|
||||
//tests
|
||||
useCPlus = true;
|
||||
CvMat* temp;
|
||||
CvMat* temp1;
|
||||
|
||||
//C tests
|
||||
useCPlus = false;
|
||||
|
||||
temp = cvCreateMat(800,600,CV_32F);
|
||||
temp1 = cvCreateMat(800,601,CV_32F);
|
||||
_src = temp;
|
||||
_dst = temp1;
|
||||
errcount += run_test_case( CV_StsAssert, "Input and output data matrix sizes mismatch" );
|
||||
_src = &_src_orig;
|
||||
_dst = &_dst_orig;
|
||||
cvReleaseMat(&temp);
|
||||
cvReleaseMat(&temp1);
|
||||
|
||||
temp = cvCreateMat(800,600,CV_32F);
|
||||
temp1 = cvCreateMat(800,600,CV_64F);
|
||||
_src = temp;
|
||||
_dst = temp1;
|
||||
errcount += run_test_case( CV_StsAssert, "Input and output data matrix types mismatch" );
|
||||
_src = &_src_orig;
|
||||
_dst = &_dst_orig;
|
||||
cvReleaseMat(&temp);
|
||||
cvReleaseMat(&temp1);
|
||||
|
||||
//C++ tests
|
||||
useCPlus = true;
|
||||
|
||||
camera_mat = cv::Mat(&_camera_mat_orig);
|
||||
distortion_coeffs = cv::Mat(&_distortion_coeffs_orig);
|
||||
new_camera_mat = cv::Mat(&_new_camera_mat_orig);
|
||||
src = cv::Mat(&_src_orig);
|
||||
dst = cv::Mat(&_dst_orig);
|
||||
|
||||
//------------
|
||||
delete[] arr_src;
|
||||
delete[] arr_dst;
|
||||
ts->set_failed_test_info(errcount > 0 ? CvTS::FAIL_BAD_ARG_CHECK : CvTS::OK);
|
||||
}
|
||||
|
||||
CV_UndistortBadArgTest undistort_badarg_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,332 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include "cvchessboardgenerator.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
ChessBoardGenerator::ChessBoardGenerator(const Size& _patternSize) : sensorWidth(32), sensorHeight(24),
|
||||
squareEdgePointsNum(200), min_cos(sqrt(2.f)*0.5f), cov(0.5),
|
||||
patternSize(_patternSize), rendererResolutionMultiplier(4), tvec(Mat::zeros(1, 3, CV_32F))
|
||||
{
|
||||
Rodrigues(Mat::eye(3, 3, CV_32F), rvec);
|
||||
}
|
||||
|
||||
void cv::ChessBoardGenerator::generateEdge(const Point3f& p1, const Point3f& p2, vector<Point3f>& out) const
|
||||
{
|
||||
Point3f step = (p2 - p1) * (1.f/squareEdgePointsNum);
|
||||
for(size_t n = 0; n < squareEdgePointsNum; ++n)
|
||||
out.push_back( p1 + step * (float)n);
|
||||
}
|
||||
|
||||
Size cv::ChessBoardGenerator::cornersSize() const
|
||||
{
|
||||
return Size(patternSize.width-1, patternSize.height-1);
|
||||
}
|
||||
|
||||
struct Mult
|
||||
{
|
||||
float m;
|
||||
Mult(int mult) : m((float)mult) {}
|
||||
Point2f operator()(const Point2f& p)const { return p * m; }
|
||||
};
|
||||
|
||||
void cv::ChessBoardGenerator::generateBasis(Point3f& pb1, Point3f& pb2) const
|
||||
{
|
||||
RNG& rng = theRNG();
|
||||
|
||||
Vec3f n;
|
||||
for(;;)
|
||||
{
|
||||
n[0] = rng.uniform(-1.f, 1.f);
|
||||
n[1] = rng.uniform(-1.f, 1.f);
|
||||
n[2] = rng.uniform(-1.f, 1.f);
|
||||
float len = (float)norm(n);
|
||||
n[0]/=len;
|
||||
n[1]/=len;
|
||||
n[2]/=len;
|
||||
|
||||
if (n[2] > min_cos)
|
||||
break;
|
||||
}
|
||||
|
||||
Vec3f n_temp = n; n_temp[0] += 100;
|
||||
Vec3f b1 = n.cross(n_temp);
|
||||
Vec3f b2 = n.cross(b1);
|
||||
float len_b1 = (float)norm(b1);
|
||||
float len_b2 = (float)norm(b2);
|
||||
|
||||
pb1 = Point3f(b1[0]/len_b1, b1[1]/len_b1, b1[2]/len_b1);
|
||||
pb2 = Point3f(b2[0]/len_b1, b2[1]/len_b2, b2[2]/len_b2);
|
||||
}
|
||||
|
||||
|
||||
Mat cv::ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat, const Mat& distCoeffs,
|
||||
const Point3f& zero, const Point3f& pb1, const Point3f& pb2,
|
||||
float sqWidth, float sqHeight, const vector<Point3f>& whole,
|
||||
vector<Point2f>& corners) const
|
||||
{
|
||||
vector< vector<Point> > squares_black;
|
||||
for(int i = 0; i < patternSize.width; ++i)
|
||||
for(int j = 0; j < patternSize.height; ++j)
|
||||
if ( (i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0) )
|
||||
{
|
||||
vector<Point3f> pts_square3d;
|
||||
vector<Point2f> pts_square2d;
|
||||
|
||||
Point3f p1 = zero + (i + 0) * sqWidth * pb1 + (j + 0) * sqHeight * pb2;
|
||||
Point3f p2 = zero + (i + 1) * sqWidth * pb1 + (j + 0) * sqHeight * pb2;
|
||||
Point3f p3 = zero + (i + 1) * sqWidth * pb1 + (j + 1) * sqHeight * pb2;
|
||||
Point3f p4 = zero + (i + 0) * sqWidth * pb1 + (j + 1) * sqHeight * pb2;
|
||||
generateEdge(p1, p2, pts_square3d);
|
||||
generateEdge(p2, p3, pts_square3d);
|
||||
generateEdge(p3, p4, pts_square3d);
|
||||
generateEdge(p4, p1, pts_square3d);
|
||||
|
||||
projectPoints(Mat(pts_square3d), rvec, tvec, camMat, distCoeffs, pts_square2d);
|
||||
squares_black.resize(squares_black.size() + 1);
|
||||
vector<Point2f> temp;
|
||||
approxPolyDP(Mat(pts_square2d), temp, 1.0, true);
|
||||
transform(temp.begin(), temp.end(), back_inserter(squares_black.back()), Mult(rendererResolutionMultiplier));
|
||||
}
|
||||
|
||||
/* calculate corners */
|
||||
corners3d.clear();
|
||||
for(int j = 0; j < patternSize.height - 1; ++j)
|
||||
for(int i = 0; i < patternSize.width - 1; ++i)
|
||||
corners3d.push_back(zero + (i + 1) * sqWidth * pb1 + (j + 1) * sqHeight * pb2);
|
||||
corners.clear();
|
||||
projectPoints(Mat(corners3d), rvec, tvec, camMat, distCoeffs, corners);
|
||||
|
||||
vector<Point3f> whole3d;
|
||||
vector<Point2f> whole2d;
|
||||
generateEdge(whole[0], whole[1], whole3d);
|
||||
generateEdge(whole[1], whole[2], whole3d);
|
||||
generateEdge(whole[2], whole[3], whole3d);
|
||||
generateEdge(whole[3], whole[0], whole3d);
|
||||
projectPoints(Mat(whole3d), rvec, tvec, camMat, distCoeffs, whole2d);
|
||||
vector<Point2f> temp_whole2d;
|
||||
approxPolyDP(Mat(whole2d), temp_whole2d, 1.0, true);
|
||||
|
||||
vector< vector<Point > > whole_contour(1);
|
||||
transform(temp_whole2d.begin(), temp_whole2d.end(),
|
||||
back_inserter(whole_contour.front()), Mult(rendererResolutionMultiplier));
|
||||
|
||||
Mat result;
|
||||
if (rendererResolutionMultiplier == 1)
|
||||
{
|
||||
result = bg.clone();
|
||||
drawContours(result, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA);
|
||||
drawContours(result, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat tmp;
|
||||
resize(bg, tmp, bg.size() * rendererResolutionMultiplier);
|
||||
drawContours(tmp, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA);
|
||||
drawContours(tmp, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA);
|
||||
resize(tmp, result, bg.size(), 0, 0, INTER_AREA);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs, vector<Point2f>& corners) const
|
||||
{
|
||||
cov = min(cov, 0.8);
|
||||
double fovx, fovy, focalLen;
|
||||
Point2d principalPoint;
|
||||
double aspect;
|
||||
calibrationMatrixValues( camMat, bg.size(), sensorWidth, sensorHeight,
|
||||
fovx, fovy, focalLen, principalPoint, aspect);
|
||||
|
||||
RNG& rng = theRNG();
|
||||
|
||||
float d1 = static_cast<float>(rng.uniform(0.1, 10.0));
|
||||
float ah = static_cast<float>(rng.uniform(-fovx/2 * cov, fovx/2 * cov) * CV_PI / 180);
|
||||
float av = static_cast<float>(rng.uniform(-fovy/2 * cov, fovy/2 * cov) * CV_PI / 180);
|
||||
|
||||
Point3f p;
|
||||
p.z = cos(ah) * d1;
|
||||
p.x = sin(ah) * d1;
|
||||
p.y = p.z * tan(av);
|
||||
|
||||
Point3f pb1, pb2;
|
||||
generateBasis(pb1, pb2);
|
||||
|
||||
float cbHalfWidth = static_cast<float>(norm(p) * sin( min(fovx, fovy) * 0.5 * CV_PI / 180));
|
||||
float cbHalfHeight = cbHalfWidth * patternSize.height / patternSize.width;
|
||||
|
||||
float cbHalfWidthEx = cbHalfWidth * ( patternSize.width + 1) / patternSize.width;
|
||||
float cbHalfHeightEx = cbHalfHeight * (patternSize.height + 1) / patternSize.height;
|
||||
|
||||
vector<Point3f> pts3d(4);
|
||||
vector<Point2f> pts2d(4);
|
||||
for(;;)
|
||||
{
|
||||
pts3d[0] = p + pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
pts3d[1] = p + pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[2] = p - pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
bool inrect1 = pts2d[0].x < bg.cols && pts2d[0].y < bg.rows && pts2d[0].x > 0 && pts2d[0].y > 0;
|
||||
bool inrect2 = pts2d[1].x < bg.cols && pts2d[1].y < bg.rows && pts2d[1].x > 0 && pts2d[1].y > 0;
|
||||
bool inrect3 = pts2d[2].x < bg.cols && pts2d[2].y < bg.rows && pts2d[2].x > 0 && pts2d[2].y > 0;
|
||||
bool inrect4 = pts2d[3].x < bg.cols && pts2d[3].y < bg.rows && pts2d[3].x > 0 && pts2d[3].y > 0;
|
||||
|
||||
if (inrect1 && inrect2 && inrect3 && inrect4)
|
||||
break;
|
||||
|
||||
cbHalfWidth*=0.8f;
|
||||
cbHalfHeight = cbHalfWidth * patternSize.height / patternSize.width;
|
||||
|
||||
cbHalfWidthEx = cbHalfWidth * ( patternSize.width + 1) / patternSize.width;
|
||||
cbHalfHeightEx = cbHalfHeight * (patternSize.height + 1) / patternSize.height;
|
||||
}
|
||||
|
||||
Point3f zero = p - pb1 * cbHalfWidth - cbHalfHeight * pb2;
|
||||
float sqWidth = 2 * cbHalfWidth/patternSize.width;
|
||||
float sqHeight = 2 * cbHalfHeight/patternSize.height;
|
||||
|
||||
return generateChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2, sqWidth, sqHeight, pts3d, corners);
|
||||
}
|
||||
|
||||
|
||||
Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs,
|
||||
const Size2f& squareSize, vector<Point2f>& corners) const
|
||||
{
|
||||
cov = min(cov, 0.8);
|
||||
double fovx, fovy, focalLen;
|
||||
Point2d principalPoint;
|
||||
double aspect;
|
||||
calibrationMatrixValues( camMat, bg.size(), sensorWidth, sensorHeight,
|
||||
fovx, fovy, focalLen, principalPoint, aspect);
|
||||
|
||||
RNG& rng = theRNG();
|
||||
|
||||
float d1 = static_cast<float>(rng.uniform(0.1, 10.0));
|
||||
float ah = static_cast<float>(rng.uniform(-fovx/2 * cov, fovx/2 * cov) * CV_PI / 180);
|
||||
float av = static_cast<float>(rng.uniform(-fovy/2 * cov, fovy/2 * cov) * CV_PI / 180);
|
||||
|
||||
Point3f p;
|
||||
p.z = cos(ah) * d1;
|
||||
p.x = sin(ah) * d1;
|
||||
p.y = p.z * tan(av);
|
||||
|
||||
Point3f pb1, pb2;
|
||||
generateBasis(pb1, pb2);
|
||||
|
||||
float cbHalfWidth = squareSize.width * patternSize.width * 0.5f;
|
||||
float cbHalfHeight = squareSize.height * patternSize.height * 0.5f;
|
||||
|
||||
float cbHalfWidthEx = cbHalfWidth * ( patternSize.width + 1) / patternSize.width;
|
||||
float cbHalfHeightEx = cbHalfHeight * (patternSize.height + 1) / patternSize.height;
|
||||
|
||||
vector<Point3f> pts3d(4);
|
||||
vector<Point2f> pts2d(4);
|
||||
for(;;)
|
||||
{
|
||||
pts3d[0] = p + pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
pts3d[1] = p + pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[2] = p - pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
bool inrect1 = pts2d[0].x < bg.cols && pts2d[0].y < bg.rows && pts2d[0].x > 0 && pts2d[0].y > 0;
|
||||
bool inrect2 = pts2d[1].x < bg.cols && pts2d[1].y < bg.rows && pts2d[1].x > 0 && pts2d[1].y > 0;
|
||||
bool inrect3 = pts2d[2].x < bg.cols && pts2d[2].y < bg.rows && pts2d[2].x > 0 && pts2d[2].y > 0;
|
||||
bool inrect4 = pts2d[3].x < bg.cols && pts2d[3].y < bg.rows && pts2d[3].x > 0 && pts2d[3].y > 0;
|
||||
|
||||
if ( inrect1 && inrect2 && inrect3 && inrect4)
|
||||
break;
|
||||
|
||||
p.z *= 1.1f;
|
||||
}
|
||||
|
||||
Point3f zero = p - pb1 * cbHalfWidth - cbHalfHeight * pb2;
|
||||
|
||||
return generateChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2,
|
||||
squareSize.width, squareSize.height, pts3d, corners);
|
||||
}
|
||||
|
||||
Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs,
|
||||
const Size2f& squareSize, const Point3f& pos, vector<Point2f>& corners) const
|
||||
{
|
||||
cov = min(cov, 0.8);
|
||||
Point3f p = pos;
|
||||
Point3f pb1, pb2;
|
||||
generateBasis(pb1, pb2);
|
||||
|
||||
float cbHalfWidth = squareSize.width * patternSize.width * 0.5f;
|
||||
float cbHalfHeight = squareSize.height * patternSize.height * 0.5f;
|
||||
|
||||
float cbHalfWidthEx = cbHalfWidth * ( patternSize.width + 1) / patternSize.width;
|
||||
float cbHalfHeightEx = cbHalfHeight * (patternSize.height + 1) / patternSize.height;
|
||||
|
||||
vector<Point3f> pts3d(4);
|
||||
vector<Point2f> pts2d(4);
|
||||
|
||||
pts3d[0] = p + pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
pts3d[1] = p + pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[2] = p - pb1 * cbHalfWidthEx - cbHalfHeightEx * pb2;
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
Point3f zero = p - pb1 * cbHalfWidth - cbHalfHeight * pb2;
|
||||
|
||||
return generateChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2,
|
||||
squareSize.width, squareSize.height, pts3d, corners);
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef CV_CHESSBOARDGENERATOR_H143KJTVYM389YTNHKFDHJ89NYVMO3VLMEJNTBGUEIYVCM203P
|
||||
#define CV_CHESSBOARDGENERATOR_H143KJTVYM389YTNHKFDHJ89NYVMO3VLMEJNTBGUEIYVCM203P
|
||||
|
||||
#include "cv.h"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class ChessBoardGenerator
|
||||
{
|
||||
public:
|
||||
double sensorWidth;
|
||||
double sensorHeight;
|
||||
size_t squareEdgePointsNum;
|
||||
double min_cos;
|
||||
mutable double cov;
|
||||
Size patternSize;
|
||||
int rendererResolutionMultiplier;
|
||||
|
||||
ChessBoardGenerator(const Size& patternSize = Size(8, 6));
|
||||
Mat operator()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs, vector<Point2f>& corners) const;
|
||||
Mat operator()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs, const Size2f& squareSize, vector<Point2f>& corners) const;
|
||||
Mat operator()(const Mat& bg, const Mat& camMat, const Mat& distCoeffs, const Size2f& squareSize, const Point3f& pos, vector<Point2f>& corners) const;
|
||||
Size cornersSize() const;
|
||||
|
||||
mutable vector<Point3f> corners3d;
|
||||
private:
|
||||
void generateEdge(const Point3f& p1, const Point3f& p2, vector<Point3f>& out) const;
|
||||
Mat generateChessBoard(const Mat& bg, const Mat& camMat, const Mat& distCoeffs,
|
||||
const Point3f& zero, const Point3f& pb1, const Point3f& pb2,
|
||||
float sqWidth, float sqHeight, const vector<Point3f>& whole, vector<Point2f>& corners) const;
|
||||
void generateBasis(Point3f& pb1, Point3f& pb2) const;
|
||||
|
||||
Mat rvec, tvec;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,44 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,72 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
#ifndef _CVTEST_H_
|
||||
#define _CVTEST_H_
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#include "cxts.h"
|
||||
#include "opencv2/legacy/legacy.hpp"
|
||||
#include "opencv2/legacy/compat.hpp"
|
||||
#include "opencv2/contrib/contrib.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/video/tracking.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
void cvTsCalcSobelKernel2D( int dx, int dy, int _aperture_size, int origin, CvMat* kernel );
|
||||
int cvTsRodrigues( const CvMat* src, CvMat* dst, CvMat* jacobian=0 );
|
||||
void cvTsConvertHomogeneous( const CvMat* src, CvMat* dst );
|
||||
|
||||
#endif /* _CVTEST_H_ */
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,318 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_DetectorsTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_DetectorsTest();
|
||||
~CV_DetectorsTest();
|
||||
protected:
|
||||
void run(int);
|
||||
template <class T> bool testDetector(const Mat& img, const T& detector, vector<KeyPoint>& expected);
|
||||
|
||||
void LoadExpected(const string& file, vector<KeyPoint>& out);
|
||||
};
|
||||
|
||||
CV_DetectorsTest::CV_DetectorsTest(): CvTest( "feature-detectors", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_DetectorsTest::~CV_DetectorsTest() {}
|
||||
|
||||
void getRotation(const Mat& img, Mat& aff, Mat& out)
|
||||
{
|
||||
Point center(img.cols/2, img.rows/2);
|
||||
aff = getRotationMatrix2D(center, 30, 1);
|
||||
warpAffine( img, out, aff, img.size());
|
||||
}
|
||||
|
||||
void getZoom(const Mat& img, Mat& aff, Mat& out)
|
||||
{
|
||||
const double mult = 1.2;
|
||||
|
||||
aff.create(2, 3, CV_64F);
|
||||
double *data = aff.ptr<double>();
|
||||
data[0] = mult; data[1] = 0; data[2] = 0;
|
||||
data[3] = 0; data[4] = mult; data[5] = 0;
|
||||
|
||||
warpAffine( img, out, aff, img.size());
|
||||
}
|
||||
|
||||
void getBlur(const Mat& img, Mat& aff, Mat& out)
|
||||
{
|
||||
aff.create(2, 3, CV_64F);
|
||||
double *data = aff.ptr<double>();
|
||||
data[0] = 1; data[1] = 0; data[2] = 0;
|
||||
data[3] = 0; data[4] = 1; data[5] = 0;
|
||||
|
||||
GaussianBlur(img, out, Size(5, 5), 2);
|
||||
}
|
||||
|
||||
void getBrightness(const Mat& img, Mat& aff, Mat& out)
|
||||
{
|
||||
aff.create(2, 3, CV_64F);
|
||||
double *data = aff.ptr<double>();
|
||||
data[0] = 1; data[1] = 0; data[2] = 0;
|
||||
data[3] = 0; data[4] = 1; data[5] = 0;
|
||||
|
||||
add(img, Mat(img.size(), img.type(), Scalar(15)), out);
|
||||
}
|
||||
|
||||
void showOrig(const Mat& img, const vector<KeyPoint>& orig_pts)
|
||||
{
|
||||
|
||||
Mat img_color;
|
||||
cvtColor(img, img_color, CV_GRAY2BGR);
|
||||
|
||||
for(size_t i = 0; i < orig_pts.size(); ++i)
|
||||
circle(img_color, orig_pts[i].pt, (int)orig_pts[i].size/2, CV_RGB(0, 255, 0));
|
||||
|
||||
namedWindow("O"); imshow("O", img_color);
|
||||
}
|
||||
|
||||
void show(const string& name, const Mat& new_img, const vector<KeyPoint>& new_pts, const vector<KeyPoint>& transf_pts)
|
||||
{
|
||||
|
||||
Mat new_img_color;
|
||||
cvtColor(new_img, new_img_color, CV_GRAY2BGR);
|
||||
|
||||
for(size_t i = 0; i < transf_pts.size(); ++i)
|
||||
circle(new_img_color, transf_pts[i].pt, (int)transf_pts[i].size/2, CV_RGB(255, 0, 0));
|
||||
|
||||
for(size_t i = 0; i < new_pts.size(); ++i)
|
||||
circle(new_img_color, new_pts[i].pt, (int)new_pts[i].size/2, CV_RGB(0, 0, 255));
|
||||
|
||||
namedWindow(name + "_T"); imshow(name + "_T", new_img_color);
|
||||
}
|
||||
|
||||
struct WrapPoint
|
||||
{
|
||||
const double* R;
|
||||
WrapPoint(const Mat& rmat) : R(rmat.ptr<double>()) { };
|
||||
|
||||
KeyPoint operator()(const KeyPoint& kp) const
|
||||
{
|
||||
KeyPoint res = kp;
|
||||
res.pt.x = static_cast<float>(kp.pt.x * R[0] + kp.pt.y * R[1] + R[2]);
|
||||
res.pt.y = static_cast<float>(kp.pt.x * R[3] + kp.pt.y * R[4] + R[5]);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
struct sortByR { bool operator()(const KeyPoint& kp1, const KeyPoint& kp2) { return norm(kp1.pt) < norm(kp2.pt); } };
|
||||
|
||||
template <class T> bool CV_DetectorsTest::testDetector(const Mat& img, const T& detector, vector<KeyPoint>& exp)
|
||||
{
|
||||
vector<KeyPoint> orig_kpts;
|
||||
detector(img, orig_kpts);
|
||||
|
||||
typedef void (*TransfFunc )(const Mat&, Mat&, Mat& FransfFunc);
|
||||
const TransfFunc transfFunc[] = { getRotation, getZoom, getBlur, getBrightness };
|
||||
//const string names[] = { "Rotation", "Zoom", "Blur", "Brightness" };
|
||||
const size_t case_num = sizeof(transfFunc)/sizeof(transfFunc[0]);
|
||||
|
||||
vector<Mat> affs(case_num);
|
||||
vector<Mat> new_imgs(case_num);
|
||||
|
||||
vector< vector<KeyPoint> > new_kpts(case_num);
|
||||
vector< vector<KeyPoint> > transf_kpts(case_num);
|
||||
|
||||
//showOrig(img, orig_kpts);
|
||||
for(size_t i = 0; i < case_num; ++i)
|
||||
{
|
||||
transfFunc[i](img, affs[i], new_imgs[i]);
|
||||
detector(new_imgs[i], new_kpts[i]);
|
||||
transform(orig_kpts.begin(), orig_kpts.end(), back_inserter(transf_kpts[i]), WrapPoint(affs[i]));
|
||||
//show(names[i], new_imgs[i], new_kpts[i], transf_kpts[i]);
|
||||
}
|
||||
|
||||
const float thres = 3;
|
||||
const float nthres = 3;
|
||||
|
||||
vector<KeyPoint> result;
|
||||
for(size_t i = 0; i < orig_kpts.size(); ++i)
|
||||
{
|
||||
const KeyPoint& okp = orig_kpts[i];
|
||||
int foundCounter = 0;
|
||||
for(size_t j = 0; j < case_num; ++j)
|
||||
{
|
||||
const KeyPoint& tkp = transf_kpts[j][i];
|
||||
|
||||
size_t k = 0;
|
||||
|
||||
for(; k < new_kpts[j].size(); ++k)
|
||||
if (norm(new_kpts[j][k].pt - tkp.pt) < nthres && fabs(new_kpts[j][k].size - tkp.size) < thres)
|
||||
break;
|
||||
|
||||
if (k != new_kpts[j].size())
|
||||
++foundCounter;
|
||||
|
||||
}
|
||||
if (foundCounter == (int)case_num)
|
||||
result.push_back(okp);
|
||||
}
|
||||
|
||||
sort(result.begin(), result.end(), sortByR());
|
||||
sort(exp.begin(), exp.end(), sortByR());
|
||||
|
||||
if (result.size() != exp.size())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_TEST_DATA);
|
||||
return false;
|
||||
}
|
||||
|
||||
int foundCounter1 = 0;
|
||||
for(size_t i = 0; i < exp.size(); ++i)
|
||||
{
|
||||
const KeyPoint& e = exp[i];
|
||||
size_t j = 0;
|
||||
for(; j < result.size(); ++j)
|
||||
{
|
||||
const KeyPoint& r = result[i];
|
||||
if (norm(r.pt-e.pt) < nthres && fabs(r.size - e.size) < thres)
|
||||
break;
|
||||
}
|
||||
if (j != result.size())
|
||||
++foundCounter1;
|
||||
}
|
||||
|
||||
int foundCounter2 = 0;
|
||||
for(size_t i = 0; i < result.size(); ++i)
|
||||
{
|
||||
const KeyPoint& r = result[i];
|
||||
size_t j = 0;
|
||||
for(; j < exp.size(); ++j)
|
||||
{
|
||||
const KeyPoint& e = exp[i];
|
||||
if (norm(r.pt-e.pt) < nthres && fabs(r.size - e.size) < thres)
|
||||
break;
|
||||
}
|
||||
if (j != exp.size())
|
||||
++foundCounter2;
|
||||
}
|
||||
//showOrig(img, result); waitKey();
|
||||
|
||||
const float errorRate = 0.9f;
|
||||
if (float(foundCounter1)/exp.size() < errorRate || float(foundCounter2)/result.size() < errorRate)
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct SurfNoMaskWrap
|
||||
{
|
||||
const SURF& detector;
|
||||
SurfNoMaskWrap(const SURF& surf) : detector(surf) {}
|
||||
SurfNoMaskWrap& operator=(const SurfNoMaskWrap&);
|
||||
void operator()(const Mat& img, vector<KeyPoint>& kpts) const { detector(img, Mat(), kpts); }
|
||||
};
|
||||
|
||||
void CV_DetectorsTest::LoadExpected(const string& file, vector<KeyPoint>& out)
|
||||
{
|
||||
Mat mat_exp;
|
||||
FileStorage fs(file, FileStorage::READ);
|
||||
if (fs.isOpened())
|
||||
{
|
||||
read( fs["ResultVectorData"], mat_exp, Mat() );
|
||||
out.resize(mat_exp.cols / sizeof(KeyPoint));
|
||||
copy(mat_exp.ptr<KeyPoint>(), mat_exp.ptr<KeyPoint>() + out.size(), out.begin());
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA);
|
||||
out.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void CV_DetectorsTest::run( int /*start_from*/ )
|
||||
{
|
||||
Mat img = imread(string(ts->get_data_path()) + "shared/graffiti.png", 0);
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
Mat to_test(img.size() * 2, img.type(), Scalar(0));
|
||||
Mat roi = to_test(Rect(img.rows/2, img.cols/2, img.cols, img.rows));
|
||||
img.copyTo(roi);
|
||||
GaussianBlur(to_test, to_test, Size(3, 3), 1.5);
|
||||
|
||||
vector<KeyPoint> exp;
|
||||
LoadExpected(string(ts->get_data_path()) + "detectors/surf.xml", exp);
|
||||
if (exp.empty())
|
||||
return;
|
||||
|
||||
if (!testDetector(to_test, SurfNoMaskWrap(SURF(1536+512+512, 2)), exp))
|
||||
return;
|
||||
|
||||
LoadExpected(string(ts->get_data_path()) + "detectors/star.xml", exp);
|
||||
if (exp.empty())
|
||||
return;
|
||||
|
||||
if (!testDetector(to_test, StarDetector(45, 30, 10, 8, 5), exp))
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info( CvTS::OK);
|
||||
}
|
||||
|
||||
|
||||
CV_DetectorsTest Detectors_test;
|
||||
|
||||
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class CV_FastTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_FastTest();
|
||||
~CV_FastTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_FastTest::CV_FastTest(): CvTest( "features-fast", "cv::FAST" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_FastTest::~CV_FastTest() {}
|
||||
|
||||
void CV_FastTest::run( int )
|
||||
{
|
||||
Mat image1 = imread(string(ts->get_data_path()) + "inpaint/orig.jpg");
|
||||
Mat image2 = imread(string(ts->get_data_path()) + "cameracalibration/chess9.jpg");
|
||||
string xml = string(ts->get_data_path()) + "fast/result.xml";
|
||||
|
||||
if (image1.empty() || image2.empty())
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
Mat gray1, gray2;
|
||||
cvtColor(image1, gray1, CV_BGR2GRAY);
|
||||
cvtColor(image2, gray2, CV_BGR2GRAY);
|
||||
|
||||
vector<KeyPoint> keypoints1;
|
||||
vector<KeyPoint> keypoints2;
|
||||
FAST(gray1, keypoints1, 30);
|
||||
FAST(gray2, keypoints2, 30);
|
||||
|
||||
for(size_t i = 0; i < keypoints1.size(); ++i)
|
||||
{
|
||||
const KeyPoint& kp = keypoints1[i];
|
||||
cv::circle(image1, kp.pt, cvRound(kp.size/2), CV_RGB(255, 0, 0));
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < keypoints2.size(); ++i)
|
||||
{
|
||||
const KeyPoint& kp = keypoints2[i];
|
||||
cv::circle(image2, kp.pt, cvRound(kp.size/2), CV_RGB(255, 0, 0));
|
||||
}
|
||||
|
||||
Mat kps1(1, (int)(keypoints1.size() * sizeof(KeyPoint)), CV_8U, &keypoints1[0]);
|
||||
Mat kps2(1, (int)(keypoints2.size() * sizeof(KeyPoint)), CV_8U, &keypoints2[0]);
|
||||
|
||||
FileStorage fs(xml, FileStorage::READ);
|
||||
if (!fs.isOpened())
|
||||
{
|
||||
fs.open(xml, FileStorage::WRITE);
|
||||
fs << "exp_kps1" << kps1;
|
||||
fs << "exp_kps2" << kps2;
|
||||
fs.release();
|
||||
}
|
||||
|
||||
if (!fs.isOpened())
|
||||
fs.open(xml, FileStorage::READ);
|
||||
|
||||
Mat exp_kps1, exp_kps2;
|
||||
read( fs["exp_kps1"], exp_kps1, Mat() );
|
||||
read( fs["exp_kps2"], exp_kps2, Mat() );
|
||||
fs.release();
|
||||
|
||||
if ( 0 != norm(exp_kps1, kps1, NORM_L2) || 0 != norm(exp_kps2, kps2, NORM_L2))
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
/* cv::namedWindow("Img1"); cv::imshow("Img1", image1);
|
||||
cv::namedWindow("Img2"); cv::imshow("Img2", image2);
|
||||
cv::waitKey(0);*/
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_FastTest fast_test;
|
||||
@@ -1,142 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class CV_GrabcutTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GrabcutTest();
|
||||
~CV_GrabcutTest();
|
||||
protected:
|
||||
bool verify(const Mat& mask, const Mat& exp);
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_GrabcutTest::CV_GrabcutTest(): CvTest( "segmentation-grabcut", "cv::grabCut" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_GrabcutTest::~CV_GrabcutTest() {}
|
||||
|
||||
bool CV_GrabcutTest::verify(const Mat& mask, const Mat& exp)
|
||||
{
|
||||
const float maxDiffRatio = 0.005f;
|
||||
int expArea = countNonZero( exp );
|
||||
int nonIntersectArea = countNonZero( mask != exp );
|
||||
|
||||
float curRatio = (float)nonIntersectArea / (float)expArea;
|
||||
ts->printf( CvTS::LOG, "nonIntersectArea/expArea = %f\n", curRatio );
|
||||
return curRatio < maxDiffRatio;
|
||||
}
|
||||
|
||||
void CV_GrabcutTest::run( int /* start_from */)
|
||||
{
|
||||
DefaultRngAuto defRng;
|
||||
|
||||
Mat img = imread(string(ts->get_data_path()) + "shared/airplane.jpg");
|
||||
Mat mask_prob = imread(string(ts->get_data_path()) + "grabcut/mask_prob.png", 0);
|
||||
Mat exp_mask1 = imread(string(ts->get_data_path()) + "grabcut/exp_mask1.png", 0);
|
||||
Mat exp_mask2 = imread(string(ts->get_data_path()) + "grabcut/exp_mask2.png", 0);
|
||||
|
||||
if (img.empty() || (!mask_prob.empty() && img.size() != mask_prob.size()) ||
|
||||
(!exp_mask1.empty() && img.size() != exp_mask1.size()) ||
|
||||
(!exp_mask2.empty() && img.size() != exp_mask2.size()) )
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
Rect rect(Point(24, 126), Point(483, 294));
|
||||
Mat exp_bgdModel, exp_fgdModel;
|
||||
|
||||
Mat mask;
|
||||
mask = Scalar(0);
|
||||
Mat bgdModel, fgdModel;
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_RECT );
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 2, GC_EVAL );
|
||||
|
||||
// Multiply images by 255 for more visuality of test data.
|
||||
if( mask_prob.empty() )
|
||||
{
|
||||
mask.copyTo( mask_prob );
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/mask_prob.png", mask_prob);
|
||||
}
|
||||
if( exp_mask1.empty() )
|
||||
{
|
||||
exp_mask1 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask1.png", exp_mask1);
|
||||
}
|
||||
|
||||
if (!verify((mask & 1) * 255, exp_mask1))
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
mask = mask_prob;
|
||||
bgdModel.release();
|
||||
fgdModel.release();
|
||||
rect = Rect();
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_MASK );
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 1, GC_EVAL );
|
||||
|
||||
if( exp_mask2.empty() )
|
||||
{
|
||||
exp_mask2 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask2.png", exp_mask2);
|
||||
}
|
||||
|
||||
if (!verify((mask & 1) * 255, exp_mask2))
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_GrabcutTest grabcut_test;
|
||||
@@ -1,315 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
//#include <iostream>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
//#if 0
|
||||
|
||||
#else
|
||||
|
||||
#define MARKERS1
|
||||
|
||||
#ifdef MARKERS
|
||||
#define marker(x) cout << (x) << endl
|
||||
#else
|
||||
#define marker(x)
|
||||
#endif
|
||||
|
||||
struct TempDirHolder
|
||||
{
|
||||
string temp_folder;
|
||||
TempDirHolder()
|
||||
{
|
||||
char* p = tmpnam(0);
|
||||
if(p[0] == '\\') p++;
|
||||
temp_folder = string(p);
|
||||
exec_cmd("mkdir " + temp_folder);
|
||||
}
|
||||
~TempDirHolder() { exec_cmd("rm -rf " + temp_folder); }
|
||||
static void exec_cmd(const string& cmd) { marker(cmd); int res = system( cmd.c_str() ); (void)res; }
|
||||
|
||||
TempDirHolder& operator=(const TempDirHolder&);
|
||||
};
|
||||
|
||||
|
||||
class CV_HighGuiTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_HighGuiTest();
|
||||
~CV_HighGuiTest();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool ImagesTest(const string& dir, const string& tmp);
|
||||
bool VideoTest(const string& dir, const string& tmp, int fourcc);
|
||||
|
||||
bool GuiTest(const string& dir, const string& tmp);
|
||||
};
|
||||
|
||||
CV_HighGuiTest::CV_HighGuiTest(): CvTest( "z-highgui", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_HighGuiTest::~CV_HighGuiTest() {}
|
||||
|
||||
double PSNR(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
Mat tmp;
|
||||
absdiff( m1.reshape(1), m2.reshape(1), tmp);
|
||||
multiply(tmp, tmp, tmp);
|
||||
|
||||
double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0];
|
||||
|
||||
return 20 * log10(255.0 / sqrt(MSE));
|
||||
}
|
||||
|
||||
bool CV_HighGuiTest::ImagesTest(const string& dir, const string& tmp)
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
Mat image = imread(dir + "shared/baboon.jpg");
|
||||
|
||||
if (image.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return false;
|
||||
}
|
||||
|
||||
const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras"};
|
||||
const size_t ext_num = sizeof(exts)/sizeof(exts[0]);
|
||||
|
||||
for(size_t i = 0; i < ext_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "ext=%s\n", exts[i].c_str());
|
||||
string ext = exts[i];
|
||||
string full_name = tmp + "/img." + ext;
|
||||
marker(exts[i]);
|
||||
|
||||
imwrite(full_name, image);
|
||||
Mat loaded = imread(full_name);
|
||||
if (loaded.empty())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Reading failed at fmt=%s\n", ext.c_str());
|
||||
code = CvTS::FAIL_MISMATCH;
|
||||
continue;
|
||||
}
|
||||
|
||||
const double thresDbell = 20;
|
||||
double psnr = PSNR(loaded, image);
|
||||
if (psnr < thresDbell)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
continue;
|
||||
}
|
||||
|
||||
FILE *f = fopen(full_name.c_str(), "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
vector<uchar> from_file(len);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
size_t read = fread(&from_file[0], len, sizeof(vector<uchar>::value_type), f); (void)read;
|
||||
fclose(f);
|
||||
|
||||
|
||||
vector<uchar> buf;
|
||||
imencode("." + exts[i], image, buf);
|
||||
|
||||
if (buf != from_file)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Encoding failed with fmt=%s\n", ext.c_str());
|
||||
code = CvTS::FAIL_MISMATCH;
|
||||
continue;
|
||||
}
|
||||
|
||||
Mat buf_loaded = imdecode(Mat(buf), 1);
|
||||
if (buf_loaded.empty())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Decoding failed with fmt=%s\n", ext.c_str());
|
||||
code = CvTS::FAIL_MISMATCH;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
psnr = PSNR(buf_loaded, image);
|
||||
if (psnr < thresDbell)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str());
|
||||
code = CvTS::FAIL_MISMATCH;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(code);
|
||||
return code == CvTS::OK;
|
||||
}
|
||||
|
||||
bool CV_HighGuiTest::VideoTest(const string& dir, const string& tmp, int fourcc)
|
||||
{
|
||||
string src_file = dir + "shared/video_for_test.avi";
|
||||
string tmp_name = tmp + "/video.avi";
|
||||
|
||||
CvCapture* cap = cvCaptureFromFile(src_file.c_str());
|
||||
|
||||
if (!cap)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
CvVideoWriter* writer = 0;
|
||||
|
||||
int counter = 0;
|
||||
for(;;)
|
||||
{
|
||||
IplImage* img = cvQueryFrame( cap );
|
||||
|
||||
if (!img)
|
||||
break;
|
||||
|
||||
if (writer == 0)
|
||||
{
|
||||
writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
|
||||
if (writer == 0)
|
||||
{
|
||||
marker("can't craete writer");
|
||||
cvReleaseCapture( &cap );
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cvWriteFrame(writer, img);
|
||||
}
|
||||
|
||||
|
||||
cvReleaseVideoWriter( &writer );
|
||||
cvReleaseCapture( &cap );
|
||||
|
||||
marker("mid++");
|
||||
|
||||
cap = cvCaptureFromFile(src_file.c_str());
|
||||
marker("mid1");
|
||||
CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
|
||||
if (!saved)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const double thresDbell = 20;
|
||||
|
||||
bool error = false;
|
||||
counter = 0;
|
||||
for(;;)
|
||||
{
|
||||
|
||||
IplImage* ipl = cvQueryFrame( cap );
|
||||
IplImage* ipl1 = cvQueryFrame( saved );
|
||||
|
||||
|
||||
if (!ipl || !ipl1)
|
||||
break;
|
||||
|
||||
Mat img(ipl);
|
||||
Mat img1(ipl1);
|
||||
|
||||
if (PSNR(img1, img) < thresDbell)
|
||||
{
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseCapture( &cap );
|
||||
cvReleaseCapture( &saved );
|
||||
|
||||
if (error)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CV_HighGuiTest::run( int /*start_from */)
|
||||
{
|
||||
TempDirHolder th;
|
||||
|
||||
if (!ImagesTest(ts->get_data_path(), th.temp_folder))
|
||||
return;
|
||||
|
||||
#if defined WIN32 || defined __linux__
|
||||
|
||||
#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
|
||||
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC_DEFAULT))
|
||||
return;
|
||||
|
||||
|
||||
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('M', 'J', 'P', 'G')))
|
||||
return;
|
||||
|
||||
|
||||
if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('M', 'P', 'G', '2')))
|
||||
return;
|
||||
|
||||
#endif
|
||||
//if (!VideoTest(ts->get_data_path(), th.temp_folder, CV_FOURCC('D', 'X', '5', '0'))) return;
|
||||
#endif
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
CV_HighGuiTest HighGui_test;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
//#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
|
||||
#define MARKERS
|
||||
|
||||
#ifdef MARKERS
|
||||
#define marker(x) cout << (x) << endl
|
||||
#else
|
||||
#define marker(x)
|
||||
#endif
|
||||
|
||||
|
||||
class CV_HighGuiOnlyGuiTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_HighGuiOnlyGuiTest();
|
||||
~CV_HighGuiOnlyGuiTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_HighGuiOnlyGuiTest::CV_HighGuiOnlyGuiTest(): CvTest( "z-highgui-gui-only", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_HighGuiOnlyGuiTest::~CV_HighGuiOnlyGuiTest() {}
|
||||
|
||||
void Foo(int /*k*/, void* /*z*/) {}
|
||||
|
||||
void CV_HighGuiOnlyGuiTest::run( int /*start_from */)
|
||||
{
|
||||
cout << "GUI 1" << endl;
|
||||
namedWindow("Win");
|
||||
cout << "GUI 2" << endl;
|
||||
Mat m(30, 30, CV_8U);
|
||||
m = Scalar(128);
|
||||
cout << "GUI 3" << endl;
|
||||
imshow("Win", m);
|
||||
cout << "GUI 4" << endl;
|
||||
int value = 50;
|
||||
cout << "GUI 5" << endl;
|
||||
createTrackbar( "trackbar", "Win", &value, 100, Foo, &value);
|
||||
cout << "GUI 6" << endl;
|
||||
getTrackbarPos( "trackbar", "Win" );
|
||||
cout << "GUI 7" << endl;
|
||||
waitKey(500);
|
||||
cout << "GUI 8" << endl;
|
||||
cvDestroyAllWindows();
|
||||
cout << "GUI 9" << endl;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_HighGuiOnlyGuiTest highGuiOnlyGui_test;
|
||||
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class CV_InpaintTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_InpaintTest();
|
||||
~CV_InpaintTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_InpaintTest::CV_InpaintTest(): CvTest( "inpaint", "cvInpaint" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_InpaintTest::~CV_InpaintTest() {}
|
||||
|
||||
void CV_InpaintTest::run( int )
|
||||
{
|
||||
string folder = string(ts->get_data_path()) + "inpaint/";
|
||||
Mat orig = imread(folder + "orig.jpg");
|
||||
Mat exp1 = imread(folder + "exp1.png");
|
||||
Mat exp2 = imread(folder + "exp2.png");
|
||||
Mat mask = imread(folder + "mask.png");
|
||||
|
||||
if (orig.empty() || exp1.empty() || exp2.empty() || mask.empty())
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
Mat inv_mask;
|
||||
mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0);
|
||||
|
||||
Mat mask1ch;
|
||||
cv::cvtColor(mask, mask1ch, CV_BGR2GRAY);
|
||||
|
||||
Mat test = orig.clone();
|
||||
test.setTo(Scalar::all(255), mask1ch);
|
||||
|
||||
Mat res1, res2;
|
||||
inpaint( test, mask1ch, res1, 5, CV_INPAINT_NS );
|
||||
inpaint( test, mask1ch, res2, 5, CV_INPAINT_TELEA );
|
||||
|
||||
imwrite("d:/exp1.png", res1);
|
||||
imwrite("d:/exp2.png", res2);
|
||||
|
||||
Mat diff1, diff2;
|
||||
absdiff( orig, res1, diff1 );
|
||||
absdiff( orig, res2, diff2 );
|
||||
|
||||
double n1 = norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));
|
||||
double n2 = norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));
|
||||
|
||||
if (n1 != 0 || n2 != 0)
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
return;
|
||||
}
|
||||
|
||||
absdiff( exp1, res1, diff1 );
|
||||
absdiff( exp2, res2, diff2 );
|
||||
|
||||
n1 = norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
|
||||
n2 = norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
|
||||
|
||||
const int jpeg_thres = 3;
|
||||
if (n1 > jpeg_thres || n2 > jpeg_thres)
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_InpaintTest inpaint_test;
|
||||
@@ -1,136 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/task_scheduler_init.h"
|
||||
#endif
|
||||
|
||||
using namespace cv;
|
||||
|
||||
const int num_detections = 3;
|
||||
const float true_scores[3] = {-0.383931f, -0.825876f, -0.959934f};
|
||||
const float score_thr = 0.05f;
|
||||
const CvRect true_bounding_boxes[3] = {cvRect(0, 45, 362, 452), cvRect(304, 0, 64, 80), cvRect(236, 0, 108, 59)};
|
||||
|
||||
class CV_LatentSVMDetectorTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_LatentSVMDetectorTest();
|
||||
~CV_LatentSVMDetectorTest();
|
||||
protected:
|
||||
void run(int);
|
||||
private:
|
||||
bool isEqual(CvRect r1, CvRect r2);
|
||||
};
|
||||
|
||||
CV_LatentSVMDetectorTest::CV_LatentSVMDetectorTest(): CvTest( "latentsvmdetector", "cvLatentSvmDetectObjects" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
CV_LatentSVMDetectorTest::~CV_LatentSVMDetectorTest() {}
|
||||
|
||||
bool CV_LatentSVMDetectorTest::isEqual(CvRect r1, CvRect r2)
|
||||
{
|
||||
return ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width == r2.width) && (r1.height == r2.height));
|
||||
}
|
||||
|
||||
void CV_LatentSVMDetectorTest::run( int /* start_from */)
|
||||
{
|
||||
int numThreads = -1;
|
||||
#ifdef HAVE_TBB
|
||||
numThreads = 2;
|
||||
tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
|
||||
init.initialize(numThreads);
|
||||
#endif
|
||||
|
||||
IplImage* image = cvLoadImage(img_path.c_str());
|
||||
if (!image)
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_path.c_str());
|
||||
if (!detector)
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
cvReleaseImage(&image);
|
||||
return;
|
||||
}
|
||||
|
||||
CvMemStorage* storage = cvCreateMemStorage(0);
|
||||
CvSeq* detections = 0;
|
||||
detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads);
|
||||
|
||||
if (detections->total != num_detections)
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
for (int i = 0; i < detections->total; i++)
|
||||
{
|
||||
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
|
||||
CvRect bounding_box = detection.rect;
|
||||
float score = detection.score;
|
||||
if ((!isEqual(bounding_box, true_bounding_boxes[i])) || (fabs(score - true_scores[i]) > score_thr))
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
init.terminate();
|
||||
#endif
|
||||
cvReleaseMemStorage( &storage );
|
||||
cvReleaseLatentSvmDetector( &detector );
|
||||
cvReleaseImage( &image );
|
||||
}
|
||||
|
||||
CV_LatentSVMDetectorTest latentsvmdetector_test;
|
||||
@@ -1,829 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
|
||||
class CV_OperationsTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_OperationsTest();
|
||||
~CV_OperationsTest();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
struct test_excep
|
||||
{
|
||||
test_excep(const string& _s=string("")) : s(_s) {};
|
||||
string s;
|
||||
};
|
||||
|
||||
bool SomeMatFunctions();
|
||||
bool TestMat();
|
||||
bool TestTemplateMat();
|
||||
bool TestMatND();
|
||||
bool TestSparseMat();
|
||||
bool operations1();
|
||||
|
||||
void checkDiff(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) != 0) throw test_excep(s); }
|
||||
void checkDiffF(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); }
|
||||
|
||||
};
|
||||
|
||||
CV_OperationsTest::CV_OperationsTest(): CvTest( "operations", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_OperationsTest::~CV_OperationsTest() {}
|
||||
|
||||
#define STR(a) STR2(a)
|
||||
#define STR2(a) #a
|
||||
|
||||
#define CHECK_DIFF(a, b) checkDiff(a, b, "(" #a ") != (" #b ") at l." STR(__LINE__))
|
||||
#define CHECK_DIFF_FLT(a, b) checkDiffF(a, b, "(" #a ") !=(eps) (" #b ") at l." STR(__LINE__))
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER < 1400
|
||||
#define MSVC_OLD 1
|
||||
#else
|
||||
#define MSVC_OLD 0
|
||||
#endif
|
||||
|
||||
bool CV_OperationsTest::TestMat()
|
||||
{
|
||||
try
|
||||
{
|
||||
Mat one_3x1(3, 1, CV_32F, Scalar(1.0));
|
||||
Mat shi_3x1(3, 1, CV_32F, Scalar(1.2));
|
||||
Mat shi_2x1(2, 1, CV_32F, Scalar(-1));
|
||||
Scalar shift = Scalar::all(15);
|
||||
|
||||
float data[] = { sqrt(2.f)/2, -sqrt(2.f)/2, 1.f, sqrt(2.f)/2, sqrt(2.f)/2, 10.f };
|
||||
Mat rot_2x3(2, 3, CV_32F, data);
|
||||
|
||||
Mat res = one_3x1 + shi_3x1 + shi_3x1 + shi_3x1;
|
||||
res = Mat(Mat(2 * rot_2x3) * res - shi_2x1) + shift;
|
||||
|
||||
Mat tmp, res2;
|
||||
add(one_3x1, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
gemm(rot_2x3, tmp, 2, shi_2x1, -1, res2, 0);
|
||||
add(res2, Mat(2, 1, CV_32F, shift), res2);
|
||||
|
||||
CHECK_DIFF(res, res2);
|
||||
|
||||
Mat mat4x4(4, 4, CV_32F);
|
||||
randu(mat4x4, Scalar(0), Scalar(10));
|
||||
|
||||
Mat roi1 = mat4x4(Rect(Point(1, 1), Size(2, 2)));
|
||||
Mat roi2 = mat4x4(Range(1, 3), Range(1, 3));
|
||||
|
||||
CHECK_DIFF(roi1, roi2);
|
||||
CHECK_DIFF(mat4x4, mat4x4(Rect(Point(0,0), mat4x4.size())));
|
||||
|
||||
Mat intMat10(3, 3, CV_32S, Scalar(10));
|
||||
Mat intMat11(3, 3, CV_32S, Scalar(11));
|
||||
Mat resMat(3, 3, CV_8U, Scalar(255));
|
||||
|
||||
CHECK_DIFF(resMat, intMat10 == intMat10);
|
||||
CHECK_DIFF(resMat, intMat10 < intMat11);
|
||||
CHECK_DIFF(resMat, intMat11 > intMat10);
|
||||
CHECK_DIFF(resMat, intMat10 <= intMat11);
|
||||
CHECK_DIFF(resMat, intMat11 >= intMat10);
|
||||
CHECK_DIFF(resMat, intMat11 != intMat10);
|
||||
|
||||
CHECK_DIFF(resMat, intMat10 == 10.0);
|
||||
CHECK_DIFF(resMat, 10.0 == intMat10);
|
||||
CHECK_DIFF(resMat, intMat10 < 11.0);
|
||||
CHECK_DIFF(resMat, 11.0 > intMat10);
|
||||
CHECK_DIFF(resMat, 10.0 < intMat11);
|
||||
CHECK_DIFF(resMat, 11.0 >= intMat10);
|
||||
CHECK_DIFF(resMat, 10.0 <= intMat11);
|
||||
CHECK_DIFF(resMat, 10.0 != intMat11);
|
||||
CHECK_DIFF(resMat, intMat11 != 10.0);
|
||||
|
||||
Mat eye = Mat::eye(3, 3, CV_16S);
|
||||
Mat maskMat4(3, 3, CV_16S, Scalar(4));
|
||||
Mat maskMat1(3, 3, CV_16S, Scalar(1));
|
||||
Mat maskMat5(3, 3, CV_16S, Scalar(5));
|
||||
Mat maskMat0(3, 3, CV_16S, Scalar(0));
|
||||
|
||||
CHECK_DIFF(maskMat0, maskMat4 & maskMat1);
|
||||
CHECK_DIFF(maskMat0, Scalar(1) & maskMat4);
|
||||
CHECK_DIFF(maskMat0, maskMat4 & Scalar(1));
|
||||
|
||||
Mat m;
|
||||
m = maskMat4.clone(); m &= maskMat1; CHECK_DIFF(maskMat0, m);
|
||||
m = maskMat4.clone(); m &= maskMat1 | maskMat1; CHECK_DIFF(maskMat0, m);
|
||||
m = maskMat4.clone(); m &= (2* maskMat1 - maskMat1); CHECK_DIFF(maskMat0, m);
|
||||
|
||||
m = maskMat4.clone(); m &= Scalar(1); CHECK_DIFF(maskMat0, m);
|
||||
m = maskMat4.clone(); m |= maskMat1; CHECK_DIFF(maskMat5, m);
|
||||
m = maskMat5.clone(); m ^= maskMat1; CHECK_DIFF(maskMat4, m);
|
||||
m = maskMat4.clone(); m |= (2* maskMat1 - maskMat1); CHECK_DIFF(maskMat5, m);
|
||||
m = maskMat5.clone(); m ^= (2* maskMat1 - maskMat1); CHECK_DIFF(maskMat4, m);
|
||||
|
||||
m = maskMat4.clone(); m |= Scalar(1); CHECK_DIFF(maskMat5, m);
|
||||
m = maskMat5.clone(); m ^= Scalar(1); CHECK_DIFF(maskMat4, m);
|
||||
|
||||
|
||||
|
||||
CHECK_DIFF(maskMat0, (maskMat4 | maskMat4) & (maskMat1 | maskMat1));
|
||||
CHECK_DIFF(maskMat0, (maskMat4 | maskMat4) & maskMat1);
|
||||
CHECK_DIFF(maskMat0, maskMat4 & (maskMat1 | maskMat1));
|
||||
CHECK_DIFF(maskMat0, (maskMat1 | maskMat1) & Scalar(4));
|
||||
CHECK_DIFF(maskMat0, Scalar(4) & (maskMat1 | maskMat1));
|
||||
|
||||
CHECK_DIFF(maskMat0, maskMat5 ^ (maskMat4 | maskMat1));
|
||||
CHECK_DIFF(maskMat0, (maskMat4 | maskMat1) ^ maskMat5);
|
||||
CHECK_DIFF(maskMat0, (maskMat4 + maskMat1) ^ (maskMat4 + maskMat1));
|
||||
CHECK_DIFF(maskMat0, Scalar(5) ^ (maskMat4 | Scalar(1)));
|
||||
CHECK_DIFF(maskMat1, Scalar(5) ^ maskMat4);
|
||||
CHECK_DIFF(maskMat0, Scalar(5) ^ (maskMat4 + maskMat1));
|
||||
CHECK_DIFF(maskMat5, Scalar(5) | (maskMat4 + maskMat1));
|
||||
CHECK_DIFF(maskMat0, (maskMat4 + maskMat1) ^ Scalar(5));
|
||||
|
||||
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ maskMat1));
|
||||
CHECK_DIFF(maskMat5, (maskMat4 ^ maskMat1) | maskMat5);
|
||||
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ Scalar(1)));
|
||||
CHECK_DIFF(maskMat5, (maskMat4 | maskMat4) | Scalar(1));
|
||||
CHECK_DIFF(maskMat5, Scalar(1) | (maskMat4 | maskMat4));
|
||||
CHECK_DIFF(maskMat5, Scalar(1) | maskMat4);
|
||||
CHECK_DIFF(maskMat5, (maskMat5 | maskMat5) | (maskMat4 ^ maskMat1));
|
||||
|
||||
CHECK_DIFF(maskMat1, min(maskMat1, maskMat5));
|
||||
CHECK_DIFF(maskMat1, min(Mat(maskMat1 | maskMat1), maskMat5 | maskMat5));
|
||||
CHECK_DIFF(maskMat5, max(maskMat1, maskMat5));
|
||||
CHECK_DIFF(maskMat5, max(Mat(maskMat1 | maskMat1), maskMat5 | maskMat5));
|
||||
|
||||
CHECK_DIFF(maskMat1, min(maskMat1, maskMat5 | maskMat5));
|
||||
CHECK_DIFF(maskMat1, min(maskMat1 | maskMat1, maskMat5));
|
||||
CHECK_DIFF(maskMat5, max(maskMat1 | maskMat1, maskMat5));
|
||||
CHECK_DIFF(maskMat5, max(maskMat1, maskMat5 | maskMat5));
|
||||
|
||||
CHECK_DIFF(~maskMat1, maskMat1 ^ -1);
|
||||
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ -1);
|
||||
|
||||
CHECK_DIFF(maskMat1, maskMat4/4.0);
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
CHECK_DIFF(1.0 - (maskMat5 | maskMat5), -maskMat4);
|
||||
CHECK_DIFF((maskMat4 | maskMat4) * 1.0 + 1.0, maskMat5);
|
||||
CHECK_DIFF(1.0 + (maskMat4 | maskMat4) * 1.0, maskMat5);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) * 1.0 - 1.0, maskMat4);
|
||||
CHECK_DIFF(5.0 - (maskMat4 | maskMat4) * 1.0, maskMat1);
|
||||
CHECK_DIFF((maskMat4 | maskMat4) * 1.0 + 0.5 + 0.5, maskMat5);
|
||||
CHECK_DIFF(0.5 + ((maskMat4 | maskMat4) * 1.0 + 0.5), maskMat5);
|
||||
CHECK_DIFF(((maskMat4 | maskMat4) * 1.0 + 2.0) - 1.0, maskMat5);
|
||||
CHECK_DIFF(5.0 - ((maskMat1 | maskMat1) * 1.0 + 3.0), maskMat1);
|
||||
CHECK_DIFF( ( (maskMat1 | maskMat1) * 2.0 + 2.0) * 1.25, maskMat5);
|
||||
CHECK_DIFF( 1.25 * ( (maskMat1 | maskMat1) * 2.0 + 2.0), maskMat5);
|
||||
CHECK_DIFF( -( (maskMat1 | maskMat1) * (-2.0) + 1.0), maskMat1);
|
||||
CHECK_DIFF( maskMat1 * 1.0 + maskMat4 * 0.5 + 2.0, maskMat5);
|
||||
CHECK_DIFF( 1.0 + (maskMat1 * 1.0 + maskMat4 * 0.5 + 1.0), maskMat5);
|
||||
CHECK_DIFF( (maskMat1 * 1.0 + maskMat4 * 0.5 + 2.0) - 1.0, maskMat4);
|
||||
CHECK_DIFF(5.0 - (maskMat1 * 1.0 + maskMat4 * 0.5 + 1.0), maskMat1);
|
||||
CHECK_DIFF((maskMat1 * 1.0 + maskMat4 * 0.5 + 1.0)*1.25, maskMat5);
|
||||
CHECK_DIFF(1.25 * (maskMat1 * 1.0 + maskMat4 * 0.5 + 1.0), maskMat5);
|
||||
CHECK_DIFF(-(maskMat1 * 2.0 + maskMat4 * (-1) + 1.0), maskMat1);
|
||||
CHECK_DIFF((maskMat1 * 1.0 + maskMat4), maskMat5);
|
||||
CHECK_DIFF((maskMat4 + maskMat1 * 1.0), maskMat5);
|
||||
CHECK_DIFF((maskMat1 * 3.0 + 1.0) + maskMat1, maskMat5);
|
||||
CHECK_DIFF(maskMat1 + (maskMat1 * 3.0 + 1.0), maskMat5);
|
||||
CHECK_DIFF(maskMat1*4.0 + (maskMat1 | maskMat1), maskMat5);
|
||||
CHECK_DIFF((maskMat1 | maskMat1) + maskMat1*4.0, maskMat5);
|
||||
CHECK_DIFF((maskMat1*3.0 + 1.0) + (maskMat1 | maskMat1), maskMat5);
|
||||
CHECK_DIFF((maskMat1 | maskMat1) + (maskMat1*3.0 + 1.0), maskMat5);
|
||||
CHECK_DIFF(maskMat1*4.0 + maskMat4*2.0, maskMat1 * 12);
|
||||
CHECK_DIFF((maskMat1*3.0 + 1.0) + maskMat4*2.0, maskMat1 * 12);
|
||||
CHECK_DIFF(maskMat4*2.0 + (maskMat1*3.0 + 1.0), maskMat1 * 12);
|
||||
CHECK_DIFF((maskMat1*3.0 + 1.0) + (maskMat1*2.0 + 2.0), maskMat1 * 8);
|
||||
|
||||
CHECK_DIFF(maskMat5*1.0 - maskMat4, maskMat1);
|
||||
CHECK_DIFF(maskMat5 - maskMat1 * 4.0, maskMat1);
|
||||
CHECK_DIFF((maskMat4 * 1.0 + 4.0)- maskMat4, maskMat4);
|
||||
CHECK_DIFF(maskMat5 - (maskMat1 * 2.0 + 2.0), maskMat1);
|
||||
CHECK_DIFF(maskMat5*1.0 - (maskMat4 | maskMat4), maskMat1);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) - maskMat1 * 4.0, maskMat1);
|
||||
CHECK_DIFF((maskMat4 * 1.0 + 4.0)- (maskMat4 | maskMat4), maskMat4);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) - (maskMat1 * 2.0 + 2.0), maskMat1);
|
||||
CHECK_DIFF(maskMat1*5.0 - maskMat4 * 1.0, maskMat1);
|
||||
CHECK_DIFF((maskMat1*5.0 + 3.0)- maskMat4 * 1.0, maskMat4);
|
||||
CHECK_DIFF(maskMat4 * 2.0 - (maskMat1*4.0 + 3.0), maskMat1);
|
||||
CHECK_DIFF((maskMat1 * 2.0 + 3.0) - (maskMat1*3.0 + 1.0), maskMat1);
|
||||
|
||||
CHECK_DIFF((maskMat5 - maskMat4)* 4.0, maskMat4);
|
||||
CHECK_DIFF(4.0 * (maskMat5 - maskMat4), maskMat4);
|
||||
|
||||
CHECK_DIFF(-((maskMat4 | maskMat4) - (maskMat5 | maskMat5)), maskMat1);
|
||||
|
||||
CHECK_DIFF(4.0 * (maskMat1 | maskMat1), maskMat4);
|
||||
CHECK_DIFF((maskMat4 | maskMat4)/4.0, maskMat1);
|
||||
|
||||
#if !MSVC_OLD
|
||||
CHECK_DIFF(2.0 * (maskMat1 * 2.0) , maskMat4);
|
||||
#endif
|
||||
CHECK_DIFF((maskMat4 / 2.0) / 2.0 , maskMat1);
|
||||
CHECK_DIFF(-(maskMat4 - maskMat5) , maskMat1);
|
||||
CHECK_DIFF(-((maskMat4 - maskMat5) * 1.0), maskMat1);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
CHECK_DIFF(maskMat4 / maskMat4, maskMat1);
|
||||
|
||||
///// Element-wise multiplication
|
||||
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4, 0.25), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat1 * 4, 0.25), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4 / 4), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4 / 4), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4) * 0.25, maskMat4);
|
||||
CHECK_DIFF(0.25 * maskMat4.mul(maskMat4), maskMat4);
|
||||
|
||||
////// Element-wise division
|
||||
|
||||
CHECK_DIFF(maskMat4 / maskMat4, maskMat1);
|
||||
CHECK_DIFF((maskMat4 & maskMat4) / (maskMat1 * 4), maskMat1);
|
||||
|
||||
CHECK_DIFF((maskMat4 & maskMat4) / maskMat4, maskMat1);
|
||||
CHECK_DIFF(maskMat4 / (maskMat4 & maskMat4), maskMat1);
|
||||
CHECK_DIFF((maskMat1 * 4) / maskMat4, maskMat1);
|
||||
|
||||
CHECK_DIFF(maskMat4 / (maskMat1 * 4), maskMat1);
|
||||
CHECK_DIFF((maskMat4 * 0.5 )/ (maskMat1 * 2), maskMat1);
|
||||
|
||||
CHECK_DIFF(maskMat4 / maskMat4.mul(maskMat1), maskMat1);
|
||||
CHECK_DIFF((maskMat4 & maskMat4) / maskMat4.mul(maskMat1), maskMat1);
|
||||
|
||||
CHECK_DIFF(4.0 / maskMat4, maskMat1);
|
||||
CHECK_DIFF(4.0 / (maskMat4 | maskMat4), maskMat1);
|
||||
CHECK_DIFF(4.0 / (maskMat1 * 4.0), maskMat1);
|
||||
CHECK_DIFF(4.0 / (maskMat4 / maskMat1), maskMat1);
|
||||
|
||||
m = maskMat4.clone(); m/=4.0; CHECK_DIFF(m, maskMat1);
|
||||
m = maskMat4.clone(); m/=maskMat4; CHECK_DIFF(m, maskMat1);
|
||||
m = maskMat4.clone(); m/=(maskMat1 * 4.0); CHECK_DIFF(m, maskMat1);
|
||||
m = maskMat4.clone(); m/=(maskMat4 / maskMat1); CHECK_DIFF(m, maskMat1);
|
||||
|
||||
/////////////////////////////
|
||||
float matrix_data[] = { 3, 1, -4, -5, 1, 0, 0, 1.1f, 1.5f};
|
||||
Mat mt(3, 3, CV_32F, matrix_data);
|
||||
Mat mi = mt.inv();
|
||||
Mat d1 = Mat::eye(3, 3, CV_32F);
|
||||
Mat d2 = d1 * 2;
|
||||
MatExpr mt_tr = mt.t();
|
||||
MatExpr mi_tr = mi.t();
|
||||
Mat mi2 = mi * 2;
|
||||
|
||||
|
||||
CHECK_DIFF_FLT( mi2 * mt, d2 );
|
||||
CHECK_DIFF_FLT( mi * mt, d1 );
|
||||
CHECK_DIFF_FLT( mt_tr * mi_tr, d1 );
|
||||
|
||||
m = mi.clone(); m*=mt; CHECK_DIFF_FLT(m, d1);
|
||||
m = mi.clone(); m*= (2 * mt - mt) ; CHECK_DIFF_FLT(m, d1);
|
||||
|
||||
m = maskMat4.clone(); m+=(maskMat1 * 1.0); CHECK_DIFF(m, maskMat5);
|
||||
m = maskMat5.clone(); m-=(maskMat1 * 4.0); CHECK_DIFF(m, maskMat1);
|
||||
|
||||
m = maskMat1.clone(); m+=(maskMat1 * 3.0 + 1.0); CHECK_DIFF(m, maskMat5);
|
||||
m = maskMat5.clone(); m-=(maskMat1 * 3.0 + 1.0); CHECK_DIFF(m, maskMat1);
|
||||
#if !MSVC_OLD
|
||||
m = mi.clone(); m+=(3.0 * mi * mt + d1); CHECK_DIFF_FLT(m, mi + d1 * 4);
|
||||
m = mi.clone(); m-=(3.0 * mi * mt + d1); CHECK_DIFF_FLT(m, mi - d1 * 4);
|
||||
m = mi.clone(); m*=(mt * 1.0); CHECK_DIFF_FLT(m, d1);
|
||||
m = mi.clone(); m*=(mt * 1.0 + Mat::eye(m.size(), m.type())); CHECK_DIFF_FLT(m, d1 + mi);
|
||||
m = mi.clone(); m*=mt_tr.t(); CHECK_DIFF_FLT(m, d1);
|
||||
|
||||
CHECK_DIFF_FLT( (mi * 2) * mt, d2);
|
||||
CHECK_DIFF_FLT( mi * (2 * mt), d2);
|
||||
CHECK_DIFF_FLT( mt.t() * mi_tr, d1 );
|
||||
CHECK_DIFF_FLT( mt_tr * mi.t(), d1 );
|
||||
CHECK_DIFF_FLT( (mi * 0.4) * (mt * 5), d2);
|
||||
|
||||
CHECK_DIFF_FLT( mt.t() * (mi_tr * 2), d2 );
|
||||
CHECK_DIFF_FLT( (mt_tr * 2) * mi.t(), d2 );
|
||||
|
||||
CHECK_DIFF_FLT(mt.t() * mi.t(), d1);
|
||||
CHECK_DIFF_FLT( (mi * mt) * 2.0, d2);
|
||||
CHECK_DIFF_FLT( 2.0 * (mi * mt), d2);
|
||||
CHECK_DIFF_FLT( -(mi * mt), -d1);
|
||||
|
||||
CHECK_DIFF_FLT( (mi * mt) / 2.0, d1 / 2);
|
||||
|
||||
Mat mt_mul_2_plus_1;
|
||||
gemm(mt, d1, 2, Mat::ones(3, 3, CV_32F), 1, mt_mul_2_plus_1);
|
||||
|
||||
CHECK_DIFF( (mt * 2.0 + 1.0) * mi, mt_mul_2_plus_1 * mi); // (A*alpha + beta)*B
|
||||
CHECK_DIFF( mi * (mt * 2.0 + 1.0), mi * mt_mul_2_plus_1); // A*(B*alpha + beta)
|
||||
CHECK_DIFF( (mt * 2.0 + 1.0) * (mi * 2), mt_mul_2_plus_1 * mi2); // (A*alpha + beta)*(B*gamma)
|
||||
CHECK_DIFF( (mi *2)* (mt * 2.0 + 1.0), mi2 * mt_mul_2_plus_1); // (A*gamma)*(B*alpha + beta)
|
||||
CHECK_DIFF_FLT( (mt * 2.0 + 1.0) * mi.t(), mt_mul_2_plus_1 * mi_tr); // (A*alpha + beta)*B^t
|
||||
CHECK_DIFF_FLT( mi.t() * (mt * 2.0 + 1.0), mi_tr * mt_mul_2_plus_1); // A^t*(B*alpha + beta)
|
||||
|
||||
CHECK_DIFF_FLT( (mi * mt + d2)*5, d1 * 3 * 5);
|
||||
CHECK_DIFF_FLT( mi * mt + d2, d1 * 3);
|
||||
CHECK_DIFF_FLT( -(mi * mt) + d2, d1);
|
||||
CHECK_DIFF_FLT( (mi * mt) + d1, d2);
|
||||
CHECK_DIFF_FLT( d1 + (mi * mt), d2);
|
||||
CHECK_DIFF_FLT( (mi * mt) - d2, -d1);
|
||||
CHECK_DIFF_FLT( d2 - (mi * mt), d1);
|
||||
|
||||
CHECK_DIFF_FLT( (mi * mt) + d2 * 0.5, d2);
|
||||
CHECK_DIFF_FLT( d2 * 0.5 + (mi * mt), d2);
|
||||
CHECK_DIFF_FLT( (mi * mt) - d1 * 2, -d1);
|
||||
CHECK_DIFF_FLT( d1 * 2 - (mi * mt), d1);
|
||||
|
||||
CHECK_DIFF_FLT( (mi * mt) + mi.t(), mi_tr + d1);
|
||||
CHECK_DIFF_FLT( mi.t() + (mi * mt), mi_tr + d1);
|
||||
CHECK_DIFF_FLT( (mi * mt) - mi.t(), d1 - mi_tr);
|
||||
CHECK_DIFF_FLT( mi.t() - (mi * mt), mi_tr - d1);
|
||||
|
||||
CHECK_DIFF_FLT( 2.0 *(mi * mt + d2), d1 * 6);
|
||||
CHECK_DIFF_FLT( -(mi * mt + d2), d1 * -3);
|
||||
|
||||
CHECK_DIFF_FLT(mt.inv() * mt, d1);
|
||||
|
||||
CHECK_DIFF_FLT(mt.inv() * (2*mt - mt), d1);
|
||||
#endif
|
||||
}
|
||||
catch (const test_excep& e)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%s\n", e.s.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_OperationsTest::SomeMatFunctions()
|
||||
{
|
||||
try
|
||||
{
|
||||
Mat rgba( 10, 10, CV_8UC4, Scalar(1,2,3,4) );
|
||||
Mat bgr( rgba.rows, rgba.cols, CV_8UC3 );
|
||||
Mat alpha( rgba.rows, rgba.cols, CV_8UC1 );
|
||||
Mat out[] = { bgr, alpha };
|
||||
// rgba[0] -> bgr[2], rgba[1] -> bgr[1],
|
||||
// rgba[2] -> bgr[0], rgba[3] -> alpha[0]
|
||||
int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
|
||||
mixChannels( &rgba, 1, out, 2, from_to, 4 );
|
||||
|
||||
Mat bgr_exp( rgba.size(), CV_8UC3, Scalar(3,2,1));
|
||||
Mat alpha_exp( rgba.size(), CV_8UC1, Scalar(4));
|
||||
|
||||
CHECK_DIFF(bgr_exp, bgr);
|
||||
CHECK_DIFF(alpha_exp, alpha);
|
||||
}
|
||||
catch (const test_excep& e)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%s\n", e.s.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool CV_OperationsTest::TestTemplateMat()
|
||||
{
|
||||
try
|
||||
{
|
||||
Mat_<float> one_3x1(3, 1, 1.0f);
|
||||
Mat_<float> shi_3x1(3, 1, 1.2f);
|
||||
Mat_<float> shi_2x1(2, 1, -2);
|
||||
Scalar shift = Scalar::all(15);
|
||||
|
||||
float data[] = { sqrt(2.f)/2, -sqrt(2.f)/2, 1.f, sqrt(2.f)/2, sqrt(2.f)/2, 10.f };
|
||||
Mat_<float> rot_2x3(2, 3, data);
|
||||
|
||||
Mat_<float> res = Mat(Mat(2 * rot_2x3) * Mat(one_3x1 + shi_3x1 + shi_3x1 + shi_3x1) - shi_2x1) + shift;
|
||||
Mat_<float> resS = rot_2x3 * one_3x1;
|
||||
|
||||
Mat_<float> tmp, res2, resS2;
|
||||
add(one_3x1, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
gemm(rot_2x3, tmp, 2, shi_2x1, -1, res2, 0);
|
||||
add(res2, Mat(2, 1, CV_32F, shift), res2);
|
||||
|
||||
gemm(rot_2x3, one_3x1, 1, shi_2x1, 0, resS2, 0);
|
||||
CHECK_DIFF(res, res2);
|
||||
CHECK_DIFF(resS, resS2);
|
||||
|
||||
|
||||
Mat_<float> mat4x4(4, 4);
|
||||
randu(mat4x4, Scalar(0), Scalar(10));
|
||||
|
||||
Mat_<float> roi1 = mat4x4(Rect(Point(1, 1), Size(2, 2)));
|
||||
Mat_<float> roi2 = mat4x4(Range(1, 3), Range(1, 3));
|
||||
|
||||
CHECK_DIFF(roi1, roi2);
|
||||
CHECK_DIFF(mat4x4, mat4x4(Rect(Point(0,0), mat4x4.size())));
|
||||
|
||||
Mat_<int> intMat10(3, 3, 10);
|
||||
Mat_<int> intMat11(3, 3, 11);
|
||||
Mat_<uchar> resMat(3, 3, 255);
|
||||
|
||||
CHECK_DIFF(resMat, intMat10 == intMat10);
|
||||
CHECK_DIFF(resMat, intMat10 < intMat11);
|
||||
CHECK_DIFF(resMat, intMat11 > intMat10);
|
||||
CHECK_DIFF(resMat, intMat10 <= intMat11);
|
||||
CHECK_DIFF(resMat, intMat11 >= intMat10);
|
||||
|
||||
CHECK_DIFF(resMat, intMat10 == 10.0);
|
||||
CHECK_DIFF(resMat, intMat10 < 11.0);
|
||||
CHECK_DIFF(resMat, intMat11 > 10.0);
|
||||
CHECK_DIFF(resMat, intMat10 <= 11.0);
|
||||
CHECK_DIFF(resMat, intMat11 >= 10.0);
|
||||
|
||||
Mat_<uchar> maskMat4(3, 3, 4);
|
||||
Mat_<uchar> maskMat1(3, 3, 1);
|
||||
Mat_<uchar> maskMat5(3, 3, 5);
|
||||
Mat_<uchar> maskMat0(3, 3, (uchar)0);
|
||||
|
||||
CHECK_DIFF(maskMat0, maskMat4 & maskMat1);
|
||||
CHECK_DIFF(maskMat0, Scalar(1) & maskMat4);
|
||||
CHECK_DIFF(maskMat0, maskMat4 & Scalar(1));
|
||||
|
||||
Mat_<uchar> m;
|
||||
m = maskMat4.clone(); m&=maskMat1; CHECK_DIFF(maskMat0, m);
|
||||
m = maskMat4.clone(); m&=Scalar(1); CHECK_DIFF(maskMat0, m);
|
||||
|
||||
m = maskMat4.clone(); m|=maskMat1; CHECK_DIFF(maskMat5, m);
|
||||
m = maskMat4.clone(); m^=maskMat1; CHECK_DIFF(maskMat5, m);
|
||||
|
||||
CHECK_DIFF(maskMat0, (maskMat4 | maskMat4) & (maskMat1 | maskMat1));
|
||||
CHECK_DIFF(maskMat0, (maskMat4 | maskMat4) & maskMat1);
|
||||
CHECK_DIFF(maskMat0, maskMat4 & (maskMat1 | maskMat1));
|
||||
|
||||
CHECK_DIFF(maskMat0, maskMat5 ^ (maskMat4 | maskMat1));
|
||||
CHECK_DIFF(maskMat0, Scalar(5) ^ (maskMat4 | Scalar(1)));
|
||||
|
||||
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ maskMat1));
|
||||
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ Scalar(1)));
|
||||
|
||||
CHECK_DIFF(~maskMat1, maskMat1 ^ 0xFF);
|
||||
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ 0xFF);
|
||||
|
||||
CHECK_DIFF(maskMat1 + maskMat4, maskMat5);
|
||||
CHECK_DIFF(maskMat1 + Scalar(4), maskMat5);
|
||||
CHECK_DIFF(Scalar(4) + maskMat1, maskMat5);
|
||||
CHECK_DIFF(Scalar(4) + (maskMat1 & maskMat1), maskMat5);
|
||||
|
||||
CHECK_DIFF(maskMat1 + 4.0, maskMat5);
|
||||
CHECK_DIFF((maskMat1 & 0xFF) + 4.0, maskMat5);
|
||||
CHECK_DIFF(4.0 + maskMat1, maskMat5);
|
||||
|
||||
m = maskMat4.clone(); m+=Scalar(1); CHECK_DIFF(m, maskMat5);
|
||||
m = maskMat4.clone(); m+=maskMat1; CHECK_DIFF(m, maskMat5);
|
||||
m = maskMat4.clone(); m+=(maskMat1 | maskMat1); CHECK_DIFF(m, maskMat5);
|
||||
|
||||
CHECK_DIFF(maskMat5 - maskMat1, maskMat4);
|
||||
CHECK_DIFF(maskMat5 - Scalar(1), maskMat4);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) - Scalar(1), maskMat4);
|
||||
CHECK_DIFF(maskMat5 - 1, maskMat4);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) - 1, maskMat4);
|
||||
CHECK_DIFF((maskMat5 | maskMat5) - (maskMat1 | maskMat1), maskMat4);
|
||||
|
||||
CHECK_DIFF(maskMat1, min(maskMat1, maskMat5));
|
||||
CHECK_DIFF(maskMat5, max(maskMat1, maskMat5));
|
||||
|
||||
m = maskMat5.clone(); m-=Scalar(1); CHECK_DIFF(m, maskMat4);
|
||||
m = maskMat5.clone(); m-=maskMat1; CHECK_DIFF(m, maskMat4);
|
||||
m = maskMat5.clone(); m-=(maskMat1 | maskMat1); CHECK_DIFF(m, maskMat4);
|
||||
|
||||
m = maskMat4.clone(); m |= Scalar(1); CHECK_DIFF(maskMat5, m);
|
||||
m = maskMat5.clone(); m ^= Scalar(1); CHECK_DIFF(maskMat4, m);
|
||||
|
||||
CHECK_DIFF(maskMat1, maskMat4/4.0);
|
||||
|
||||
Mat_<float> negf(3, 3, -3.0);
|
||||
Mat_<float> posf = -negf;
|
||||
Mat_<float> posf2 = posf * 2;
|
||||
Mat_<int> negi(3, 3, -3);
|
||||
|
||||
CHECK_DIFF(abs(negf), -negf);
|
||||
CHECK_DIFF(abs(posf - posf2), -negf);
|
||||
CHECK_DIFF(abs(negi), -(negi & negi));
|
||||
|
||||
CHECK_DIFF(5.0 - maskMat4, maskMat1);
|
||||
|
||||
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4, 0.25), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat1 * 4, 0.25), maskMat4);
|
||||
CHECK_DIFF(maskMat4.mul(maskMat4 / 4), maskMat4);
|
||||
|
||||
|
||||
////// Element-wise division
|
||||
|
||||
CHECK_DIFF(maskMat4 / maskMat4, maskMat1);
|
||||
CHECK_DIFF(4.0 / maskMat4, maskMat1);
|
||||
m = maskMat4.clone(); m/=4.0; CHECK_DIFF(m, maskMat1);
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
typedef Mat_<int> TestMat_t;
|
||||
|
||||
const TestMat_t cnegi = negi.clone();
|
||||
|
||||
TestMat_t::iterator beg = negi.begin();
|
||||
TestMat_t::iterator end = negi.end();
|
||||
|
||||
TestMat_t::const_iterator cbeg = cnegi.begin();
|
||||
TestMat_t::const_iterator cend = cnegi.end();
|
||||
|
||||
int sum = 0;
|
||||
for(; beg!=end; ++beg)
|
||||
sum+=*beg;
|
||||
|
||||
for(; cbeg!=cend; ++cbeg)
|
||||
sum-=*cbeg;
|
||||
|
||||
if (sum != 0) throw test_excep();
|
||||
|
||||
CHECK_DIFF(negi.col(1), negi.col(2));
|
||||
CHECK_DIFF(negi.row(1), negi.row(2));
|
||||
CHECK_DIFF(negi.col(1), negi.diag());
|
||||
|
||||
if (Mat_<Point2f>(1, 1).elemSize1() != sizeof(float)) throw test_excep();
|
||||
if (Mat_<Point2f>(1, 1).elemSize() != 2 * sizeof(float)) throw test_excep();
|
||||
if (Mat_<Point2f>(1, 1).depth() != CV_32F) throw test_excep();
|
||||
if (Mat_<float>(1, 1).depth() != CV_32F) throw test_excep();
|
||||
if (Mat_<int>(1, 1).depth() != CV_32S) throw test_excep();
|
||||
if (Mat_<double>(1, 1).depth() != CV_64F) throw test_excep();
|
||||
if (Mat_<Point3d>(1, 1).depth() != CV_64F) throw test_excep();
|
||||
if (Mat_<signed char>(1, 1).depth() != CV_8S) throw test_excep();
|
||||
if (Mat_<unsigned short>(1, 1).depth() != CV_16U) throw test_excep();
|
||||
if (Mat_<unsigned short>(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat_<Point2f>(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat_<Point3f>(1, 1).channels() != 3) throw test_excep();
|
||||
if (Mat_<Point3d>(1, 1).channels() != 3) throw test_excep();
|
||||
|
||||
Mat_<uchar> eye = Mat_<uchar>::zeros(2, 2); CHECK_DIFF(Mat_<uchar>::zeros(Size(2, 2)), eye);
|
||||
eye.at<uchar>(Point(0,0)) = 1; eye.at<uchar>(1, 1) = 1;
|
||||
|
||||
CHECK_DIFF(Mat_<uchar>::eye(2, 2), eye);
|
||||
CHECK_DIFF(eye, Mat_<uchar>::eye(Size(2,2)));
|
||||
|
||||
Mat_<uchar> ones(2, 2, (uchar)1);
|
||||
CHECK_DIFF(ones, Mat_<uchar>::ones(Size(2,2)));
|
||||
CHECK_DIFF(Mat_<uchar>::ones(2, 2), ones);
|
||||
|
||||
Mat_<Point2f> pntMat(2, 2, Point2f(1, 0));
|
||||
if(pntMat.stepT() != 2) throw test_excep();
|
||||
|
||||
uchar uchar_data[] = {1, 0, 0, 1};
|
||||
|
||||
Mat_<uchar> matFromData(1, 4, uchar_data);
|
||||
const Mat_<uchar> mat2 = matFromData.clone();
|
||||
CHECK_DIFF(matFromData, eye.reshape(1));
|
||||
if (matFromData(Point(0,0)) != uchar_data[0])throw test_excep();
|
||||
if (mat2(Point(0,0)) != uchar_data[0]) throw test_excep();
|
||||
|
||||
if (matFromData(0,0) != uchar_data[0])throw test_excep();
|
||||
if (mat2(0,0) != uchar_data[0]) throw test_excep();
|
||||
|
||||
Mat_<uchar> rect(eye, Rect(0, 0, 1, 1));
|
||||
if (rect.cols != 1 || rect.rows != 1 || rect(0,0) != uchar_data[0]) throw test_excep();
|
||||
|
||||
//cv::Mat_<_Tp>::adjustROI(int,int,int,int)
|
||||
//cv::Mat_<_Tp>::cross(const Mat_&) const
|
||||
//cv::Mat_<_Tp>::Mat_(const vector<_Tp>&,bool)
|
||||
//cv::Mat_<_Tp>::Mat_(int,int,_Tp*,size_t)
|
||||
//cv::Mat_<_Tp>::Mat_(int,int,const _Tp&)
|
||||
//cv::Mat_<_Tp>::Mat_(Size,const _Tp&)
|
||||
//cv::Mat_<_Tp>::mul(const Mat_<_Tp>&,double) const
|
||||
//cv::Mat_<_Tp>::mul(const MatExpr_<MatExpr_Op2_<Mat_<_Tp>,double,Mat_<_Tp>,MatOp_DivRS_<Mat> >,Mat_<_Tp> >&,double) const
|
||||
//cv::Mat_<_Tp>::mul(const MatExpr_<MatExpr_Op2_<Mat_<_Tp>,double,Mat_<_Tp>,MatOp_Scale_<Mat> >,Mat_<_Tp> >&,double) const
|
||||
//cv::Mat_<_Tp>::operator Mat_<T2>() const
|
||||
//cv::Mat_<_Tp>::operator MatExpr_<Mat_<_Tp>,Mat_<_Tp> >() const
|
||||
//cv::Mat_<_Tp>::operator()(const Range&,const Range&) const
|
||||
//cv::Mat_<_Tp>::operator()(const Rect&) const
|
||||
|
||||
//cv::Mat_<_Tp>::operator=(const MatExpr_Base&)
|
||||
//cv::Mat_<_Tp>::operator[](int) const
|
||||
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
float matrix_data[] = { 3, 1, -4, -5, 1, 0, 0, 1.1f, 1.5f};
|
||||
Mat_<float> mt(3, 3, matrix_data);
|
||||
Mat_<float> mi = mt.inv();
|
||||
Mat_<float> d1 = Mat_<float>::eye(3, 3);
|
||||
Mat_<float> d2 = d1 * 2;
|
||||
Mat_<float> mt_tr = mt.t();
|
||||
Mat_<float> mi_tr = mi.t();
|
||||
Mat_<float> mi2 = mi * 2;
|
||||
|
||||
CHECK_DIFF_FLT( mi2 * mt, d2 );
|
||||
CHECK_DIFF_FLT( mi * mt, d1 );
|
||||
CHECK_DIFF_FLT( mt_tr * mi_tr, d1 );
|
||||
|
||||
Mat_<float> mf;
|
||||
mf = mi.clone(); mf*=mt; CHECK_DIFF_FLT(mf, d1);
|
||||
|
||||
////// typedefs //////
|
||||
|
||||
if (Mat1b(1, 1).elemSize() != sizeof(uchar)) throw test_excep();
|
||||
if (Mat2b(1, 1).elemSize() != 2 * sizeof(uchar)) throw test_excep();
|
||||
if (Mat3b(1, 1).elemSize() != 3 * sizeof(uchar)) throw test_excep();
|
||||
if (Mat1f(1, 1).elemSize() != sizeof(float)) throw test_excep();
|
||||
if (Mat2f(1, 1).elemSize() != 2 * sizeof(float)) throw test_excep();
|
||||
if (Mat3f(1, 1).elemSize() != 3 * sizeof(float)) throw test_excep();
|
||||
if (Mat1f(1, 1).depth() != CV_32F) throw test_excep();
|
||||
if (Mat3f(1, 1).depth() != CV_32F) throw test_excep();
|
||||
if (Mat3f(1, 1).type() != CV_32FC3) throw test_excep();
|
||||
if (Mat1i(1, 1).depth() != CV_32S) throw test_excep();
|
||||
if (Mat1d(1, 1).depth() != CV_64F) throw test_excep();
|
||||
if (Mat1b(1, 1).depth() != CV_8U) throw test_excep();
|
||||
if (Mat3b(1, 1).type() != CV_8UC3) throw test_excep();
|
||||
if (Mat1w(1, 1).depth() != CV_16U) throw test_excep();
|
||||
if (Mat1s(1, 1).depth() != CV_16S) throw test_excep();
|
||||
if (Mat1f(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat1b(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat1i(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat1w(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat1s(1, 1).channels() != 1) throw test_excep();
|
||||
if (Mat2f(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat2b(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat2i(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat2w(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat2s(1, 1).channels() != 2) throw test_excep();
|
||||
if (Mat3f(1, 1).channels() != 3) throw test_excep();
|
||||
if (Mat3b(1, 1).channels() != 3) throw test_excep();
|
||||
if (Mat3i(1, 1).channels() != 3) throw test_excep();
|
||||
if (Mat3w(1, 1).channels() != 3) throw test_excep();
|
||||
if (Mat3s(1, 1).channels() != 3) throw test_excep();
|
||||
|
||||
}
|
||||
catch (const test_excep& e)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%s\n", e.s.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_OperationsTest::TestMatND()
|
||||
{
|
||||
int sizes[] = { 3, 3, 3};
|
||||
cv::MatND nd(3, sizes, CV_32F);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_OperationsTest::TestSparseMat()
|
||||
{
|
||||
try
|
||||
{
|
||||
int sizes[] = { 10, 10, 10};
|
||||
int dims = sizeof(sizes)/sizeof(sizes[0]);
|
||||
SparseMat mat(dims, sizes, CV_32FC2);
|
||||
|
||||
if (mat.dims() != dims) throw test_excep();
|
||||
if (mat.channels() != 2) throw test_excep();
|
||||
if (mat.depth() != CV_32F) throw test_excep();
|
||||
|
||||
SparseMat mat2 = mat.clone();
|
||||
}
|
||||
catch (const test_excep&)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_OperationsTest::operations1()
|
||||
{
|
||||
try
|
||||
{
|
||||
Point3d p1(1, 1, 1), p2(2, 2, 2), p4(4, 4, 4);
|
||||
p1*=2;
|
||||
if (!(p1 == p2)) throw test_excep();
|
||||
if (!(p2 * 2 == p4)) throw test_excep();
|
||||
if (!(p2 * 2.f == p4)) throw test_excep();
|
||||
if (!(p2 * 2.f == p4)) throw test_excep();
|
||||
|
||||
Point2d pi1(1, 1), pi2(2, 2), pi4(4, 4);
|
||||
pi1*=2;
|
||||
if (!(pi1 == pi2)) throw test_excep();
|
||||
if (!(pi2 * 2 == pi4)) throw test_excep();
|
||||
if (!(pi2 * 2.f == pi4)) throw test_excep();
|
||||
if (!(pi2 * 2.f == pi4)) throw test_excep();
|
||||
|
||||
Vec2d v12(1, 1), v22(2, 2);
|
||||
v12*=2.0;
|
||||
if (!(v12 == v22)) throw test_excep();
|
||||
|
||||
Vec3d v13(1, 1, 1), v23(2, 2, 2);
|
||||
v13*=2.0;
|
||||
if (!(v13 == v23)) throw test_excep();
|
||||
|
||||
Vec4d v14(1, 1, 1, 1), v24(2, 2, 2, 2);
|
||||
v14*=2.0;
|
||||
if (!(v14 == v24)) throw test_excep();
|
||||
|
||||
Size sz(10, 20);
|
||||
if (sz.area() != 200) throw test_excep();
|
||||
if (sz.width != 10 || sz.height != 20) throw test_excep();
|
||||
if (((CvSize)sz).width != 10 || ((CvSize)sz).height != 20) throw test_excep();
|
||||
|
||||
Vec<double, 5> v5d(1, 1, 1, 1, 1);
|
||||
Vec<double, 6> v6d(1, 1, 1, 1, 1, 1);
|
||||
Vec<double, 7> v7d(1, 1, 1, 1, 1, 1, 1);
|
||||
Vec<double, 8> v8d(1, 1, 1, 1, 1, 1, 1, 1);
|
||||
Vec<double, 9> v9d(1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
Vec<double,10> v10d(1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
|
||||
Vec<double,10> v10dzero;
|
||||
for (int ii = 0; ii < 10; ++ii) {
|
||||
if (!v10dzero[ii] == 0.0)
|
||||
throw test_excep();
|
||||
}
|
||||
}
|
||||
catch(const test_excep&)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_OperationsTest::run( int /* start_from */)
|
||||
{
|
||||
if (!TestMat())
|
||||
return;
|
||||
|
||||
if (!SomeMatFunctions())
|
||||
return;
|
||||
|
||||
if (!TestTemplateMat())
|
||||
return;
|
||||
|
||||
/* if (!TestMatND())
|
||||
return;*/
|
||||
|
||||
if (!TestSparseMat())
|
||||
return;
|
||||
|
||||
if (!operations1())
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_OperationsTest cv_Operations_test;
|
||||
@@ -1,356 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include "cvaux.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_OptFlowTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_OptFlowTest();
|
||||
~CV_OptFlowTest();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool runDense(const Point& shift = Point(3, 0));
|
||||
bool runSparse();
|
||||
};
|
||||
|
||||
CV_OptFlowTest::CV_OptFlowTest(): CvTest( "optflow-all", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_OptFlowTest::~CV_OptFlowTest() {}
|
||||
|
||||
|
||||
Mat copnvert2flow(const Mat& velx, const Mat& vely)
|
||||
{
|
||||
Mat flow(velx.size(), CV_32FC2);
|
||||
for(int y = 0 ; y < flow.rows; ++y)
|
||||
for(int x = 0 ; x < flow.cols; ++x)
|
||||
flow.at<Point2f>(y, x) = Point2f(velx.at<float>(y, x), vely.at<float>(y, x));
|
||||
return flow;
|
||||
}
|
||||
|
||||
void calcOpticalFlowLK( const Mat& prev, const Mat& curr, Size winSize, Mat& flow )
|
||||
{
|
||||
Mat velx(prev.size(), CV_32F), vely(prev.size(), CV_32F);
|
||||
CvMat cvvelx = velx; CvMat cvvely = vely;
|
||||
CvMat cvprev = prev; CvMat cvcurr = curr;
|
||||
cvCalcOpticalFlowLK( &cvprev, &cvcurr, winSize, &cvvelx, &cvvely );
|
||||
flow = copnvert2flow(velx, vely);
|
||||
}
|
||||
|
||||
void calcOpticalFlowBM( const Mat& prev, const Mat& curr, Size bSize, Size shiftSize, Size maxRange, int usePrevious, Mat& flow )
|
||||
{
|
||||
Size sz((curr.cols - bSize.width)/shiftSize.width, (curr.rows - bSize.height)/shiftSize.height);
|
||||
Mat velx(sz, CV_32F), vely(sz, CV_32F);
|
||||
|
||||
CvMat cvvelx = velx; CvMat cvvely = vely;
|
||||
CvMat cvprev = prev; CvMat cvcurr = curr;
|
||||
cvCalcOpticalFlowBM( &cvprev, &cvcurr, bSize, shiftSize, maxRange, usePrevious, &cvvelx, &cvvely);
|
||||
flow = copnvert2flow(velx, vely);
|
||||
}
|
||||
|
||||
void calcOpticalFlowHS( const Mat& prev, const Mat& curr, int usePrevious, double lambda, TermCriteria criteria, Mat& flow)
|
||||
{
|
||||
Mat velx(prev.size(), CV_32F), vely(prev.size(), CV_32F);
|
||||
CvMat cvvelx = velx; CvMat cvvely = vely;
|
||||
CvMat cvprev = prev; CvMat cvcurr = curr;
|
||||
cvCalcOpticalFlowHS( &cvprev, &cvcurr, usePrevious, &cvvelx, &cvvely, lambda, criteria );
|
||||
flow = copnvert2flow(velx, vely);
|
||||
}
|
||||
|
||||
void calcAffineFlowPyrLK( const Mat& prev, const Mat& curr,
|
||||
const vector<Point2f>& prev_features, vector<Point2f>& curr_features,
|
||||
vector<uchar>& status, vector<float>& track_error, vector<float>& matrices,
|
||||
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS,30, 0.01),
|
||||
Size win_size = Size(15, 15), int level = 3, int flags = 0)
|
||||
{
|
||||
CvMat cvprev = prev;
|
||||
CvMat cvcurr = curr;
|
||||
|
||||
size_t count = prev_features.size();
|
||||
curr_features.resize(count);
|
||||
status.resize(count);
|
||||
track_error.resize(count);
|
||||
matrices.resize(count * 6);
|
||||
|
||||
cvCalcAffineFlowPyrLK( &cvprev, &cvcurr, 0, 0,
|
||||
(const CvPoint2D32f*)&prev_features[0], (CvPoint2D32f*)&curr_features[0], &matrices[0],
|
||||
(int)count, win_size, level, (char*)&status[0], &track_error[0], criteria, flags );
|
||||
}
|
||||
|
||||
double showFlowAndCalcError(const string& name, const Mat& gray, const Mat& flow,
|
||||
const Rect& where, const Point& d,
|
||||
bool showImages = false, bool writeError = false)
|
||||
{
|
||||
const int mult = 16;
|
||||
|
||||
if (showImages)
|
||||
{
|
||||
Mat tmp, cflow;
|
||||
resize(gray, tmp, gray.size() * mult, 0, 0, INTER_NEAREST);
|
||||
cvtColor(tmp, cflow, CV_GRAY2BGR);
|
||||
|
||||
const float m2 = 0.3f;
|
||||
const float minVel = 0.1f;
|
||||
|
||||
for(int y = 0; y < flow.rows; ++y)
|
||||
for(int x = 0; x < flow.cols; ++x)
|
||||
{
|
||||
Point2f f = flow.at<Point2f>(y, x);
|
||||
|
||||
if (f.x * f.x + f.y * f.y > minVel * minVel)
|
||||
{
|
||||
Point p1 = Point(x, y) * mult;
|
||||
Point p2 = Point(cvRound((x + f.x*m2) * mult), cvRound((y + f.y*m2) * mult));
|
||||
|
||||
line(cflow, p1, p2, CV_RGB(0, 255, 0));
|
||||
circle(cflow, Point(x, y) * mult, 2, CV_RGB(255, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
rectangle(cflow, (where.tl() + d) * mult, (where.br() + d - Point(1,1)) * mult, CV_RGB(0, 0, 255));
|
||||
namedWindow(name, 1); imshow(name, cflow);
|
||||
}
|
||||
|
||||
double angle = atan2((float)d.y, (float)d.x);
|
||||
double error = 0;
|
||||
|
||||
bool all = true;
|
||||
Mat inner = flow(where);
|
||||
for(int y = 0; y < inner.rows; ++y)
|
||||
for(int x = 0; x < inner.cols; ++x)
|
||||
{
|
||||
const Point2f f = inner.at<Point2f>(y, x);
|
||||
|
||||
if (f.x == 0 && f.y == 0)
|
||||
continue;
|
||||
|
||||
all = false;
|
||||
|
||||
double a = atan2(f.y, f.x);
|
||||
error += fabs(angle - a);
|
||||
}
|
||||
double res = all ? numeric_limits<double>::max() : error / (inner.cols * inner.rows);
|
||||
|
||||
if (writeError)
|
||||
cout << "Error " + name << " = " << res << endl;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Mat generateImage(const Size& sz, bool doBlur = true)
|
||||
{
|
||||
RNG rng;
|
||||
Mat mat(sz, CV_8U);
|
||||
mat = Scalar(0);
|
||||
for(int y = 0; y < mat.rows; ++y)
|
||||
for(int x = 0; x < mat.cols; ++x)
|
||||
mat.at<uchar>(y, x) = (uchar)rng;
|
||||
if (doBlur)
|
||||
blur(mat, mat, Size(3, 3));
|
||||
return mat;
|
||||
}
|
||||
|
||||
Mat generateSample(const Size& sz)
|
||||
{
|
||||
Mat smpl(sz, CV_8U);
|
||||
smpl = Scalar(0);
|
||||
Point sc(smpl.cols/2, smpl.rows/2);
|
||||
rectangle(smpl, Point(0,0), sc - Point(1,1), Scalar(255), CV_FILLED);
|
||||
rectangle(smpl, sc, Point(smpl.cols, smpl.rows), Scalar(255), CV_FILLED);
|
||||
return smpl;
|
||||
}
|
||||
|
||||
bool CV_OptFlowTest::runDense(const Point& d)
|
||||
{
|
||||
Size matSize(40, 40);
|
||||
Size movSize(8, 8);
|
||||
|
||||
Mat smpl = generateSample(movSize);
|
||||
Mat prev = generateImage(matSize);
|
||||
Mat curr = prev.clone();
|
||||
|
||||
Rect rect(Point(prev.cols/2, prev.rows/2) - Point(movSize.width/2, movSize.height/2), movSize);
|
||||
|
||||
Mat flowLK, flowBM, flowHS, flowFB, flowFB_G, flowBM_received, m1;
|
||||
|
||||
m1 = prev(rect); smpl.copyTo(m1);
|
||||
m1 = curr(Rect(rect.tl() + d, rect.br() + d)); smpl.copyTo(m1);
|
||||
|
||||
calcOpticalFlowLK( prev, curr, Size(15, 15), flowLK);
|
||||
calcOpticalFlowBM( prev, curr, Size(15, 15), Size(1, 1), Size(15, 15), 0, flowBM_received);
|
||||
calcOpticalFlowHS( prev, curr, 0, 5, TermCriteria(TermCriteria::MAX_ITER, 400, 0), flowHS);
|
||||
calcOpticalFlowFarneback( prev, curr, flowFB, 0.5, 3, std::max(d.x, d.y) + 10, 100, 6, 2, 0);
|
||||
calcOpticalFlowFarneback( prev, curr, flowFB_G, 0.5, 3, std::max(d.x, d.y) + 10, 100, 6, 2, OPTFLOW_FARNEBACK_GAUSSIAN);
|
||||
|
||||
flowBM.create(prev.size(), CV_32FC2);
|
||||
flowBM = Scalar(0);
|
||||
Point origin((flowBM.cols - flowBM_received.cols)/2, (flowBM.rows - flowBM_received.rows)/2);
|
||||
Mat wcp = flowBM(Rect(origin, flowBM_received.size()));
|
||||
flowBM_received.copyTo(wcp);
|
||||
|
||||
double errorLK = showFlowAndCalcError("LK", prev, flowLK, rect, d);
|
||||
double errorBM = showFlowAndCalcError("BM", prev, flowBM, rect, d);
|
||||
double errorFB = showFlowAndCalcError("FB", prev, flowFB, rect, d);
|
||||
double errorFBG = showFlowAndCalcError("FBG", prev, flowFB_G, rect, d);
|
||||
double errorHS = showFlowAndCalcError("HS", prev, flowHS, rect, d); (void)errorHS;
|
||||
//waitKey();
|
||||
|
||||
const double thres = 0.2;
|
||||
if (errorLK > thres || errorBM > thres || errorFB > thres || errorFBG > thres /*|| errorHS > thres */)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CV_OptFlowTest::runSparse()
|
||||
{
|
||||
Mat prev = imread(string(ts->get_data_path()) + "optflow/rock_1.bmp", 0);
|
||||
Mat next = imread(string(ts->get_data_path()) + "optflow/rock_2.bmp", 0);
|
||||
|
||||
if (prev.empty() || next.empty())
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return false;
|
||||
}
|
||||
|
||||
Mat cprev, cnext;
|
||||
cvtColor(prev, cprev, CV_GRAY2BGR);
|
||||
cvtColor(next, cnext, CV_GRAY2BGR);
|
||||
|
||||
vector<Point2f> prev_pts;
|
||||
vector<Point2f> next_ptsOpt;
|
||||
vector<Point2f> next_ptsAff;
|
||||
vector<uchar> status_Opt;
|
||||
vector<uchar> status_Aff;
|
||||
vector<float> error;
|
||||
vector<float> matrices;
|
||||
|
||||
Size netSize(10, 10);
|
||||
Point2f center = Point(prev.cols/2, prev.rows/2);
|
||||
|
||||
for(int i = 0 ; i < netSize.width; ++i)
|
||||
for(int j = 0 ; j < netSize.width; ++j)
|
||||
{
|
||||
Point2f p(i * float(prev.cols)/netSize.width, j * float(prev.rows)/netSize.height);
|
||||
prev_pts.push_back((p - center) * 0.5f + center);
|
||||
}
|
||||
|
||||
calcOpticalFlowPyrLK( prev, next, prev_pts, next_ptsOpt, status_Opt, error );
|
||||
calcAffineFlowPyrLK ( prev, next, prev_pts, next_ptsAff, status_Aff, error, matrices);
|
||||
|
||||
const double expected_shift = 25;
|
||||
const double thres = 1;
|
||||
for(size_t i = 0; i < prev_pts.size(); ++i)
|
||||
{
|
||||
circle(cprev, prev_pts[i], 2, CV_RGB(255, 0, 0));
|
||||
|
||||
if (status_Opt[i])
|
||||
{
|
||||
circle(cnext, next_ptsOpt[i], 2, CV_RGB(0, 0, 255));
|
||||
Point2f shift = prev_pts[i] - next_ptsOpt[i];
|
||||
|
||||
double n = sqrt(shift.ddot(shift));
|
||||
if (fabs(n - expected_shift) > thres)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (status_Aff[i])
|
||||
{
|
||||
circle(cnext, next_ptsAff[i], 4, CV_RGB(0, 255, 0));
|
||||
Point2f shift = prev_pts[i] - next_ptsAff[i];
|
||||
|
||||
double n = sqrt(shift.ddot(shift));
|
||||
if (fabs(n - expected_shift) > thres)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*namedWindow("P"); imshow("P", cprev);
|
||||
namedWindow("N"); imshow("N", cnext);
|
||||
waitKey();*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CV_OptFlowTest::run( int /* start_from */)
|
||||
{
|
||||
|
||||
if (!runDense(Point(3, 0)))
|
||||
return;
|
||||
|
||||
if (!runDense(Point(0, 3)))
|
||||
return;
|
||||
|
||||
//if (!runDense(Point(3, 3))) return; //probably LK works incorrectly in this case.
|
||||
|
||||
if (!runSparse())
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_OptFlowTest optFlow_test;
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
#include "cvtest.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class BruteForceMatcherTest : public CvTest
|
||||
{
|
||||
public:
|
||||
BruteForceMatcherTest();
|
||||
protected:
|
||||
void run( int );
|
||||
};
|
||||
|
||||
struct CV_EXPORTS L2Fake : public L2<float>
|
||||
{
|
||||
};
|
||||
|
||||
BruteForceMatcherTest::BruteForceMatcherTest() : CvTest( "BruteForceMatcher", "BruteForceMatcher::matchImpl")
|
||||
{
|
||||
support_testing_modes = CvTS::TIMING_MODE;
|
||||
}
|
||||
|
||||
void BruteForceMatcherTest::run( int )
|
||||
{
|
||||
const int dimensions = 64;
|
||||
const int descriptorsNumber = 5000;
|
||||
|
||||
Mat train = Mat( descriptorsNumber, dimensions, CV_32FC1);
|
||||
Mat query = Mat( descriptorsNumber, dimensions, CV_32FC1);
|
||||
|
||||
Mat permutation( 1, descriptorsNumber, CV_32SC1 );
|
||||
for( int i=0;i<descriptorsNumber;i++ )
|
||||
permutation.at<int>( 0, i ) = i;
|
||||
|
||||
//RNG rng = RNG( cvGetTickCount() );
|
||||
RNG rng = RNG( *ts->get_rng() );
|
||||
randShuffle( permutation, 1, &rng );
|
||||
|
||||
float boundary = 500.f;
|
||||
for( int row=0;row<descriptorsNumber;row++ )
|
||||
{
|
||||
for( int col=0;col<dimensions;col++ )
|
||||
{
|
||||
int bit = rng( 2 );
|
||||
train.at<float>( permutation.at<int>( 0, row ), col ) = bit*boundary + rng.uniform( 0.f, boundary );
|
||||
query.at<float>( row, col ) = bit*boundary + rng.uniform( 0.f, boundary );
|
||||
}
|
||||
}
|
||||
|
||||
vector<DMatch> specMatches, genericMatches;
|
||||
BruteForceMatcher<L2<float> > specMatcher;
|
||||
BruteForceMatcher<L2Fake > genericMatcher;
|
||||
|
||||
int64 time0 = cvGetTickCount();
|
||||
specMatcher.match( query, train, specMatches );
|
||||
int64 time1 = cvGetTickCount();
|
||||
genericMatcher.match( query, train, genericMatches );
|
||||
int64 time2 = cvGetTickCount();
|
||||
|
||||
float specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency();
|
||||
ts->printf( CvTS::LOG, "Matching by matrix multiplication time s: %f, us per pair: %f\n",
|
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
float genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency();
|
||||
ts->printf( CvTS::LOG, "Matching without matrix multiplication time s: %f, us per pair: %f\n",
|
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
if( (int)specMatches.size() != descriptorsNumber || (int)genericMatches.size() != descriptorsNumber )
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
for( int i=0;i<descriptorsNumber;i++ )
|
||||
{
|
||||
float epsilon = 0.01f;
|
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon &&
|
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx &&
|
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx;
|
||||
if( !isEquiv || specMatches[i].trainIdx != permutation.at<int>( 0, i ) )
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Test mask
|
||||
Mat mask( query.rows, train.rows, CV_8UC1 );
|
||||
rng.fill( mask, RNG::UNIFORM, 0, 2 );
|
||||
|
||||
|
||||
time0 = cvGetTickCount();
|
||||
specMatcher.match( query, train, specMatches, mask );
|
||||
time1 = cvGetTickCount();
|
||||
genericMatcher.match( query, train, genericMatches, mask );
|
||||
time2 = cvGetTickCount();
|
||||
|
||||
specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency();
|
||||
ts->printf( CvTS::LOG, "Matching by matrix multiplication time with mask s: %f, us per pair: %f\n",
|
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency();
|
||||
ts->printf( CvTS::LOG, "Matching without matrix multiplication time with mask s: %f, us per pair: %f\n",
|
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) );
|
||||
|
||||
if( specMatches.size() != genericMatches.size() )
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
|
||||
for( size_t i=0;i<specMatches.size();i++ )
|
||||
{
|
||||
//float epsilon = 1e-2;
|
||||
float epsilon = 10000000;
|
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon &&
|
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx &&
|
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx;
|
||||
if( !isEquiv )
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BruteForceMatcherTest taBruteForceMatcherTest;
|
||||
@@ -1,191 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
class CV_ChessboardDetectorTimingTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ChessboardDetectorTimingTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest():
|
||||
CvTest( "chessboard-detector-timing", "cvFindChessboardCorners" )
|
||||
{
|
||||
support_testing_modes = CvTS::TIMING_MODE;
|
||||
}
|
||||
|
||||
/* ///////////////////// chess_corner_test ///////////////////////// */
|
||||
void CV_ChessboardDetectorTimingTest::run( int start_from )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
/* test parameters */
|
||||
char filepath[1000];
|
||||
char filename[1000];
|
||||
|
||||
CvMat* _v = 0;
|
||||
CvPoint2D32f* v;
|
||||
|
||||
IplImage* img = 0;
|
||||
IplImage* gray = 0;
|
||||
IplImage* thresh = 0;
|
||||
|
||||
int idx, max_idx;
|
||||
int progress = 0;
|
||||
|
||||
sprintf( filepath, "%scameracalibration/", ts->get_data_path() );
|
||||
sprintf( filename, "%schessboard_timing_list.dat", filepath );
|
||||
printf("Reading file %s\n", filename);
|
||||
CvFileStorage* fs = cvOpenFileStorage( filename, 0, CV_STORAGE_READ );
|
||||
CvFileNode* board_list = fs ? cvGetFileNodeByName( fs, 0, "boards" ) : 0;
|
||||
|
||||
if( !fs || !board_list || !CV_NODE_IS_SEQ(board_list->tag) ||
|
||||
board_list->data.seq->total % 4 != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "chessboard_timing_list.dat can not be readed or is not valid" );
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
max_idx = board_list->data.seq->total/4;
|
||||
|
||||
for( idx = start_from; idx < max_idx; idx++ )
|
||||
{
|
||||
int count0 = -1;
|
||||
int count = 0;
|
||||
CvSize pattern_size;
|
||||
int result, result1 = 0;
|
||||
|
||||
const char* imgname = cvReadString((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4), "dummy.txt");
|
||||
int is_chessboard = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4+1), 0);
|
||||
pattern_size.width = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 2), -1);
|
||||
pattern_size.height = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 3), -1);
|
||||
|
||||
ts->update_context( this, idx-1, true );
|
||||
|
||||
/* read the image */
|
||||
sprintf( filename, "%s%s", filepath, imgname );
|
||||
|
||||
img = cvLoadImage( filename );
|
||||
|
||||
if( !img )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "one of chessboard images can't be read: %s\n", filename );
|
||||
if( max_idx == 1 )
|
||||
{
|
||||
code = CvTS::FAIL_MISSING_TEST_DATA;
|
||||
goto _exit_;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ts->printf(CvTS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
|
||||
|
||||
gray = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
|
||||
thresh = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
|
||||
cvCvtColor( img, gray, CV_BGR2GRAY );
|
||||
|
||||
|
||||
count0 = pattern_size.width*pattern_size.height;
|
||||
|
||||
/* allocate additional buffers */
|
||||
_v = cvCreateMat(1, count0, CV_32FC2);
|
||||
count = count0;
|
||||
|
||||
v = (CvPoint2D32f*)_v->data.fl;
|
||||
|
||||
int64 _time0 = cvGetTickCount();
|
||||
result = cvCheckChessboard(gray, pattern_size);
|
||||
int64 _time01 = cvGetTickCount();
|
||||
|
||||
OPENCV_CALL( result1 = cvFindChessboardCorners(
|
||||
gray, pattern_size, v, &count, 15 ));
|
||||
int64 _time1 = cvGetTickCount();
|
||||
|
||||
if( result != is_chessboard )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Error: chessboard was %sdetected in the image %s\n",
|
||||
result ? "" : "not ", imgname );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
if(result != result1)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
|
||||
result, result1);
|
||||
}
|
||||
|
||||
int num_pixels = gray->width*gray->height;
|
||||
float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us
|
||||
ts->printf(CvTS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
|
||||
check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
|
||||
|
||||
float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();
|
||||
ts->printf(CvTS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
|
||||
find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
|
||||
|
||||
cvReleaseMat( &_v );
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &gray );
|
||||
cvReleaseImage( &thresh );
|
||||
progress = update_progress( progress, idx-1, max_idx, 0 );
|
||||
}
|
||||
|
||||
_exit_:
|
||||
|
||||
/* release occupied memory */
|
||||
cvReleaseMat( &_v );
|
||||
cvReleaseFileStorage( &fs );
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &gray );
|
||||
cvReleaseImage( &thresh );
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_ChessboardDetectorTimingTest chessboard_detector_timing_test;
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,60 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
|
||||
CvTS test_system("cv");
|
||||
|
||||
const char* blacklist[] =
|
||||
{
|
||||
"calibrate-camera-artificial", //ticket 472
|
||||
"inpaint", //ticket 570
|
||||
"warp-resize", //ticket 429
|
||||
"_3d-rodrigues", //ticket 435
|
||||
0
|
||||
};
|
||||
|
||||
int main(int argC,char *argV[])
|
||||
{
|
||||
return test_system.run( argC, argV, blacklist );
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,134 +0,0 @@
|
||||
/*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 "cvtest.h"
|
||||
#include <string>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class CV_WatershedTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_WatershedTest();
|
||||
~CV_WatershedTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_WatershedTest::CV_WatershedTest(): CvTest( "segmentation-watershed", "cvWatershed" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_WatershedTest::~CV_WatershedTest() {}
|
||||
|
||||
void CV_WatershedTest::run( int /* start_from */)
|
||||
{
|
||||
string exp_path = string(ts->get_data_path()) + "watershed/wshed_exp.png";
|
||||
Mat exp = imread(exp_path, 0);
|
||||
Mat orig = imread(string(ts->get_data_path()) + "inpaint/orig.jpg");
|
||||
FileStorage fs(string(ts->get_data_path()) + "watershed/comp.xml", FileStorage::READ);
|
||||
|
||||
if (orig.empty() || !fs.isOpened())
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
CvSeq* cnts = (CvSeq*)fs["contours"].readObj();
|
||||
|
||||
Mat markers(orig.size(), CV_32SC1);
|
||||
markers = Scalar(0);
|
||||
IplImage iplmrks = markers;
|
||||
|
||||
vector<unsigned char> colors(1);
|
||||
for(int i = 0; cnts != 0; cnts = cnts->h_next, ++i )
|
||||
{
|
||||
cvDrawContours( &iplmrks, cnts, Scalar::all(i + 1), Scalar::all(i + 1), -1, CV_FILLED);
|
||||
Point* p = (Point*)cvGetSeqElem(cnts, 0);
|
||||
|
||||
//expected image was added with 1 in order to save to png
|
||||
//so now we substract 1 to get real color
|
||||
if(exp.data)
|
||||
colors.push_back(exp.ptr(p->y)[p->x] - 1);
|
||||
}
|
||||
fs.release();
|
||||
const int compNum = (int)(colors.size() - 1);
|
||||
|
||||
watershed(orig, markers);
|
||||
|
||||
for(int j = 0; j < markers.rows; ++j)
|
||||
{
|
||||
int* line = markers.ptr<int>(j);
|
||||
for(int i = 0; i < markers.cols; ++i)
|
||||
{
|
||||
int& pixel = line[i];
|
||||
|
||||
if (pixel == -1) // border
|
||||
continue;
|
||||
|
||||
if (pixel <= 0 || pixel > compNum)
|
||||
continue; // bad result, doing nothing and going to get error latter;
|
||||
|
||||
// repaint in saved color to compare with expected;
|
||||
if(exp.data)
|
||||
pixel = colors[pixel];
|
||||
}
|
||||
}
|
||||
|
||||
Mat markers8U;
|
||||
markers.convertTo(markers8U, CV_8U, 1, 1);
|
||||
|
||||
if( exp.empty() || orig.size() != exp.size() )
|
||||
{
|
||||
imwrite(exp_path, markers8U);
|
||||
exp = markers8U;
|
||||
}
|
||||
|
||||
if (0 != norm(markers8U, exp, NORM_INF))
|
||||
{
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
|
||||
return;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_WatershedTest watershed_test;
|
||||
@@ -1,53 +0,0 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for cxcoretest. See root CMakeLists.txt
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
project(opencv_test_core)
|
||||
|
||||
file(GLOB test_srcs "src/*.cpp")
|
||||
source_group("Src" FILES ${test_srcs})
|
||||
file(GLOB test_hdrs "src/*.h*")
|
||||
source_group("Include" FILES ${test_hdrs})
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/include/opencv"
|
||||
"${CMAKE_SOURCE_DIR}/modules/core/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
include_directories(../cxts)
|
||||
|
||||
set(the_target "opencv_test_core")
|
||||
|
||||
add_executable(${the_target} ${test_srcs} ${test_hdrs})
|
||||
|
||||
if(PCHSupport_FOUND)
|
||||
set(pch_header ${CMAKE_SOURCE_DIR}/tests/cxcore/src/cxcoretest.h)
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
||||
set(${the_target}_pch "src/precomp.cpp")
|
||||
endif()
|
||||
add_native_precompiled_header(${the_target} ${pch_header})
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
||||
add_precompiled_header(${the_target} ${pch_header})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Additional target properties
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||
)
|
||||
|
||||
|
||||
add_dependencies(${the_target} opencv_ts opencv_core)
|
||||
|
||||
# Add the required libraries for linking:
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_ts opencv_core)
|
||||
|
||||
enable_testing()
|
||||
get_target_property(LOC ${the_target} LOCATION)
|
||||
add_test(${the_target} "${LOC}")
|
||||
|
||||
if(WIN32)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
||||
endif()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,402 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////// tests for arithmetic, logic and statistical functions /////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "cxcoretest.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_ArrayOpTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ArrayOpTest();
|
||||
~CV_ArrayOpTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_ArrayOpTest::CV_ArrayOpTest() : CvTest( "nd-array-ops", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_ArrayOpTest::~CV_ArrayOpTest() {}
|
||||
|
||||
static string idx2string(const int* idx, int dims)
|
||||
{
|
||||
char buf[256];
|
||||
char* ptr = buf;
|
||||
for( int k = 0; k < dims; k++ )
|
||||
{
|
||||
sprintf(ptr, "%4d ", idx[k]);
|
||||
ptr += strlen(ptr);
|
||||
}
|
||||
ptr[-1] = '\0';
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
static const int* string2idx(const string& s, int* idx, int dims)
|
||||
{
|
||||
const char* ptr = s.c_str();
|
||||
for( int k = 0; k < dims; k++ )
|
||||
{
|
||||
int n = 0;
|
||||
sscanf(ptr, "%d%n", idx + k, &n);
|
||||
ptr += n;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
static double getValue(SparseMat& M, const int* idx, RNG& rng)
|
||||
{
|
||||
int d = M.dims();
|
||||
size_t hv = 0, *phv = 0;
|
||||
if( (unsigned)rng % 2 )
|
||||
{
|
||||
hv = d == 2 ? M.hash(idx[0], idx[1]) :
|
||||
d == 3 ? M.hash(idx[0], idx[1], idx[2]) : M.hash(idx);
|
||||
phv = &hv;
|
||||
}
|
||||
|
||||
const uchar* ptr = d == 2 ? M.ptr(idx[0], idx[1], false, phv) :
|
||||
d == 3 ? M.ptr(idx[0], idx[1], idx[2], false, phv) :
|
||||
M.ptr(idx, false, phv);
|
||||
return !ptr ? 0 : M.type() == CV_32F ? *(float*)ptr : M.type() == CV_64F ? *(double*)ptr : 0;
|
||||
}
|
||||
|
||||
static double getValue(const CvSparseMat* M, const int* idx)
|
||||
{
|
||||
int type = 0;
|
||||
const uchar* ptr = cvPtrND(M, idx, &type, 0);
|
||||
return !ptr ? 0 : type == CV_32F ? *(float*)ptr : type == CV_64F ? *(double*)ptr : 0;
|
||||
}
|
||||
|
||||
static void eraseValue(SparseMat& M, const int* idx, RNG& rng)
|
||||
{
|
||||
int d = M.dims();
|
||||
size_t hv = 0, *phv = 0;
|
||||
if( (unsigned)rng % 2 )
|
||||
{
|
||||
hv = d == 2 ? M.hash(idx[0], idx[1]) :
|
||||
d == 3 ? M.hash(idx[0], idx[1], idx[2]) : M.hash(idx);
|
||||
phv = &hv;
|
||||
}
|
||||
|
||||
if( d == 2 )
|
||||
M.erase(idx[0], idx[1], phv);
|
||||
else if( d == 3 )
|
||||
M.erase(idx[0], idx[1], idx[2], phv);
|
||||
else
|
||||
M.erase(idx, phv);
|
||||
}
|
||||
|
||||
static void eraseValue(CvSparseMat* M, const int* idx)
|
||||
{
|
||||
cvClearND(M, idx);
|
||||
}
|
||||
|
||||
static void setValue(SparseMat& M, const int* idx, double value, RNG& rng)
|
||||
{
|
||||
int d = M.dims();
|
||||
size_t hv = 0, *phv = 0;
|
||||
if( (unsigned)rng % 2 )
|
||||
{
|
||||
hv = d == 2 ? M.hash(idx[0], idx[1]) :
|
||||
d == 3 ? M.hash(idx[0], idx[1], idx[2]) : M.hash(idx);
|
||||
phv = &hv;
|
||||
}
|
||||
|
||||
uchar* ptr = d == 2 ? M.ptr(idx[0], idx[1], true, phv) :
|
||||
d == 3 ? M.ptr(idx[0], idx[1], idx[2], true, phv) :
|
||||
M.ptr(idx, true, phv);
|
||||
if( M.type() == CV_32F )
|
||||
*(float*)ptr = (float)value;
|
||||
else if( M.type() == CV_64F )
|
||||
*(double*)ptr = value;
|
||||
else
|
||||
CV_Error(CV_StsUnsupportedFormat, "");
|
||||
}
|
||||
|
||||
void CV_ArrayOpTest::run( int /* start_from */)
|
||||
{
|
||||
int errcount = 0;
|
||||
|
||||
// dense matrix operations
|
||||
{
|
||||
int sz3[] = {5, 10, 15};
|
||||
MatND A(3, sz3, CV_32F), B(3, sz3, CV_16SC4);
|
||||
CvMatND matA = A, matB = B;
|
||||
RNG rng;
|
||||
rng.fill(A, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
|
||||
rng.fill(B, CV_RAND_UNI, Scalar::all(-10), Scalar::all(10));
|
||||
|
||||
int idx0[] = {3,4,5}, idx1[] = {0, 9, 7};
|
||||
float val0 = 130;
|
||||
Scalar val1(-1000, 30, 3, 8);
|
||||
cvSetRealND(&matA, idx0, val0);
|
||||
cvSetReal3D(&matA, idx1[0], idx1[1], idx1[2], -val0);
|
||||
cvSetND(&matB, idx0, val1);
|
||||
cvSet3D(&matB, idx1[0], idx1[1], idx1[2], -val1);
|
||||
Ptr<CvMatND> matC = cvCloneMatND(&matB);
|
||||
|
||||
if( A.at<float>(idx0[0], idx0[1], idx0[2]) != val0 ||
|
||||
A.at<float>(idx1[0], idx1[1], idx1[2]) != -val0 ||
|
||||
cvGetReal3D(&matA, idx0[0], idx0[1], idx0[2]) != val0 ||
|
||||
cvGetRealND(&matA, idx1) != -val0 ||
|
||||
|
||||
Scalar(B.at<Vec4s>(idx0[0], idx0[1], idx0[2])) != val1 ||
|
||||
Scalar(B.at<Vec4s>(idx1[0], idx1[1], idx1[2])) != -val1 ||
|
||||
Scalar(cvGet3D(matC, idx0[0], idx0[1], idx0[2])) != val1 ||
|
||||
Scalar(cvGetND(matC, idx1)) != -val1 )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "one of cvSetReal3D, cvSetRealND, cvSet3D, cvSetND "
|
||||
"or the corresponding *Get* functions is not correct\n");
|
||||
errcount++;
|
||||
}
|
||||
}
|
||||
|
||||
RNG rng;
|
||||
const int MAX_DIM = 5, MAX_DIM_SZ = 10;
|
||||
// sparse matrix operations
|
||||
for( int si = 0; si < 10; si++ )
|
||||
{
|
||||
int depth = (unsigned)rng % 2 == 0 ? CV_32F : CV_64F;
|
||||
int dims = ((unsigned)rng % MAX_DIM) + 1;
|
||||
int i, k, size[MAX_DIM]={0}, idx[MAX_DIM]={0};
|
||||
vector<string> all_idxs;
|
||||
vector<double> all_vals;
|
||||
vector<double> all_vals2;
|
||||
string sidx, min_sidx, max_sidx;
|
||||
double min_val=0, max_val=0;
|
||||
|
||||
int p = 1;
|
||||
for( k = 0; k < dims; k++ )
|
||||
{
|
||||
size[k] = ((unsigned)rng % MAX_DIM_SZ) + 1;
|
||||
p *= size[k];
|
||||
}
|
||||
SparseMat M( dims, size, depth );
|
||||
map<string, double> M0;
|
||||
|
||||
int nz0 = (unsigned)rng % max(p/5,10);
|
||||
nz0 = min(max(nz0, 1), p);
|
||||
all_vals.resize(nz0);
|
||||
all_vals2.resize(nz0);
|
||||
Mat_<double> _all_vals(all_vals), _all_vals2(all_vals2);
|
||||
rng.fill(_all_vals, CV_RAND_UNI, Scalar(-1000), Scalar(1000));
|
||||
if( depth == CV_32F )
|
||||
{
|
||||
Mat _all_vals_f;
|
||||
_all_vals.convertTo(_all_vals_f, CV_32F);
|
||||
_all_vals_f.convertTo(_all_vals, CV_64F);
|
||||
}
|
||||
_all_vals.convertTo(_all_vals2, _all_vals2.type(), 2);
|
||||
if( depth == CV_32F )
|
||||
{
|
||||
Mat _all_vals2_f;
|
||||
_all_vals2.convertTo(_all_vals2_f, CV_32F);
|
||||
_all_vals2_f.convertTo(_all_vals2, CV_64F);
|
||||
}
|
||||
|
||||
minMaxLoc(_all_vals, &min_val, &max_val);
|
||||
double _norm0 = norm(_all_vals, CV_C);
|
||||
double _norm1 = norm(_all_vals, CV_L1);
|
||||
double _norm2 = norm(_all_vals, CV_L2);
|
||||
|
||||
for( i = 0; i < nz0; i++ )
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
for( k = 0; k < dims; k++ )
|
||||
idx[k] = (unsigned)rng % size[k];
|
||||
sidx = idx2string(idx, dims);
|
||||
if( M0.count(sidx) == 0 )
|
||||
break;
|
||||
}
|
||||
all_idxs.push_back(sidx);
|
||||
M0[sidx] = all_vals[i];
|
||||
if( all_vals[i] == min_val )
|
||||
min_sidx = sidx;
|
||||
if( all_vals[i] == max_val )
|
||||
max_sidx = sidx;
|
||||
setValue(M, idx, all_vals[i], rng);
|
||||
double v = getValue(M, idx, rng);
|
||||
if( v != all_vals[i] )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%d. immediately after SparseMat[%s]=%.20g the current value is %.20g\n",
|
||||
i, sidx.c_str(), all_vals[i], v);
|
||||
errcount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ptr<CvSparseMat> M2 = (CvSparseMat*)M;
|
||||
MatND Md;
|
||||
M.copyTo(Md);
|
||||
SparseMat M3; SparseMat(Md).convertTo(M3, Md.type(), 2);
|
||||
|
||||
int nz1 = (int)M.nzcount(), nz2 = (int)M3.nzcount();
|
||||
double norm0 = norm(M, CV_C);
|
||||
double norm1 = norm(M, CV_L1);
|
||||
double norm2 = norm(M, CV_L2);
|
||||
double eps = depth == CV_32F ? FLT_EPSILON*100 : DBL_EPSILON*1000;
|
||||
|
||||
if( nz1 != nz0 || nz2 != nz0)
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "%d: The number of non-zero elements before/after converting to/from dense matrix is not correct: %d/%d (while it should be %d)\n",
|
||||
si, nz1, nz2, nz0 );
|
||||
break;
|
||||
}
|
||||
|
||||
if( fabs(norm0 - _norm0) > fabs(_norm0)*eps ||
|
||||
fabs(norm1 - _norm1) > fabs(_norm1)*eps ||
|
||||
fabs(norm2 - _norm2) > fabs(_norm2)*eps )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "%d: The norms are different: %.20g/%.20g/%.20g vs %.20g/%.20g/%.20g\n",
|
||||
si, norm0, norm1, norm2, _norm0, _norm1, _norm2 );
|
||||
break;
|
||||
}
|
||||
|
||||
int n = (unsigned)rng % max(p/5,10);
|
||||
n = min(max(n, 1), p) + nz0;
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
double val1, val2, val3, val0;
|
||||
if(i < nz0)
|
||||
{
|
||||
sidx = all_idxs[i];
|
||||
string2idx(sidx, idx, dims);
|
||||
val0 = all_vals[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < dims; k++ )
|
||||
idx[k] = (unsigned)rng % size[k];
|
||||
sidx = idx2string(idx, dims);
|
||||
val0 = M0[sidx];
|
||||
}
|
||||
val1 = getValue(M, idx, rng);
|
||||
val2 = getValue(M2, idx);
|
||||
val3 = getValue(M3, idx, rng);
|
||||
|
||||
if( val1 != val0 || val2 != val0 || fabs(val3 - val0*2) > fabs(val0*2)*FLT_EPSILON )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "SparseMat M[%s] = %g/%g/%g (while it should be %g)\n", sidx.c_str(), val1, val2, val3, val0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
double val1, val2;
|
||||
if(i < nz0)
|
||||
{
|
||||
sidx = all_idxs[i];
|
||||
string2idx(sidx, idx, dims);
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < dims; k++ )
|
||||
idx[k] = (unsigned)rng % size[k];
|
||||
sidx = idx2string(idx, dims);
|
||||
}
|
||||
eraseValue(M, idx, rng);
|
||||
eraseValue(M2, idx);
|
||||
val1 = getValue(M, idx, rng);
|
||||
val2 = getValue(M2, idx);
|
||||
if( val1 != 0 || val2 != 0 )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "SparseMat: after deleting M[%s], it is =%g/%g (while it should be 0)\n", sidx.c_str(), val1, val2 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int nz = (int)M.nzcount();
|
||||
if( nz != 0 )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "The number of non-zero elements after removing all the elements = %d (while it should be 0)\n", nz );
|
||||
break;
|
||||
}
|
||||
|
||||
int idx1[MAX_DIM], idx2[MAX_DIM];
|
||||
double val1 = 0, val2 = 0;
|
||||
M3 = SparseMat(Md);
|
||||
minMaxLoc(M3, &val1, &val2, idx1, idx2);
|
||||
string s1 = idx2string(idx1, dims), s2 = idx2string(idx2, dims);
|
||||
if( val1 != min_val || val2 != max_val || s1 != min_sidx || s2 != max_sidx )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "%d. Sparse: The value and positions of minimum/maximum elements are different from the reference values and positions:\n\t"
|
||||
"(%g, %g, %s, %s) vs (%g, %g, %s, %s)\n", si, val1, val2, s1.c_str(), s2.c_str(),
|
||||
min_val, max_val, min_sidx.c_str(), max_sidx.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
minMaxLoc(Md, &val1, &val2, idx1, idx2);
|
||||
s1 = idx2string(idx1, dims), s2 = idx2string(idx2, dims);
|
||||
if( (min_val < 0 && (val1 != min_val || s1 != min_sidx)) ||
|
||||
(max_val > 0 && (val2 != max_val || s2 != max_sidx)) )
|
||||
{
|
||||
errcount++;
|
||||
ts->printf(CvTS::LOG, "%d. Dense: The value and positions of minimum/maximum elements are different from the reference values and positions:\n\t"
|
||||
"(%g, %g, %s, %s) vs (%g, %g, %s, %s)\n", si, val1, val2, s1.c_str(), s2.c_str(),
|
||||
min_val, max_val, min_sidx.c_str(), max_sidx.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(errcount == 0 ? CvTS::OK : CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
|
||||
CV_ArrayOpTest cv_ArrayOp_test;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,432 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class CV_IOTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_IOTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_IOTest::CV_IOTest():
|
||||
CvTest( "io", "cvOpenFileStorage, cvReleaseFileStorage, cvRead*, cvWrite*, cvStartWriteStruct, cvEndWriteStruct" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
|
||||
static SparseMat cvTsGetRandomSparseMat(int dims, const int* sz, int type,
|
||||
int nzcount, double a, double b, CvRNG* rng)
|
||||
{
|
||||
SparseMat m(dims, sz, type);
|
||||
int i, j;
|
||||
CV_Assert(CV_MAT_CN(type) == 1);
|
||||
for( i = 0; i < nzcount; i++ )
|
||||
{
|
||||
int idx[CV_MAX_DIM];
|
||||
for( j = 0; j < dims; j++ )
|
||||
idx[j] = cvTsRandInt(rng) % sz[j];
|
||||
double val = cvTsRandReal(rng)*(b - a) + a;
|
||||
uchar* ptr = m.ptr(idx, true, 0);
|
||||
if( type == CV_8U )
|
||||
*(uchar*)ptr = saturate_cast<uchar>(val);
|
||||
else if( type == CV_8S )
|
||||
*(schar*)ptr = saturate_cast<schar>(val);
|
||||
else if( type == CV_16U )
|
||||
*(ushort*)ptr = saturate_cast<ushort>(val);
|
||||
else if( type == CV_16S )
|
||||
*(short*)ptr = saturate_cast<short>(val);
|
||||
else if( type == CV_32S )
|
||||
*(int*)ptr = saturate_cast<int>(val);
|
||||
else if( type == CV_32F )
|
||||
*(float*)ptr = saturate_cast<float>(val);
|
||||
else
|
||||
*(double*)ptr = saturate_cast<double>(val);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static bool cvTsCheckSparse(const CvSparseMat* m1, const CvSparseMat* m2, double eps)
|
||||
{
|
||||
CvSparseMatIterator it1;
|
||||
CvSparseNode* node1;
|
||||
int depth = CV_MAT_DEPTH(m1->type);
|
||||
|
||||
if( m1->heap->active_count != m2->heap->active_count ||
|
||||
m1->dims != m2->dims || CV_MAT_TYPE(m1->type) != CV_MAT_TYPE(m2->type) )
|
||||
return false;
|
||||
|
||||
for( node1 = cvInitSparseMatIterator( m1, &it1 );
|
||||
node1 != 0; node1 = cvGetNextSparseNode( &it1 ))
|
||||
{
|
||||
uchar* v1 = (uchar*)CV_NODE_VAL(m1,node1);
|
||||
uchar* v2 = cvPtrND( m2, CV_NODE_IDX(m1,node1), 0, 0, &node1->hashval );
|
||||
if( !v2 )
|
||||
return false;
|
||||
if( depth == CV_8U || depth == CV_8S )
|
||||
{
|
||||
if( *v1 != *v2 )
|
||||
return false;
|
||||
}
|
||||
else if( depth == CV_16U || depth == CV_16S )
|
||||
{
|
||||
if( *(ushort*)v1 != *(ushort*)v2 )
|
||||
return false;
|
||||
}
|
||||
else if( depth == CV_32S )
|
||||
{
|
||||
if( *(int*)v1 != *(int*)v2 )
|
||||
return false;
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
if( fabs(*(float*)v1 - *(float*)v2) > eps*(fabs(*(float*)v2) + 1) )
|
||||
return false;
|
||||
}
|
||||
else if( fabs(*(double*)v1 - *(double*)v2) > eps*(fabs(*(double*)v2) + 1) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_IOTest::run( int )
|
||||
{
|
||||
double ranges[][2] = {{0, 256}, {-128, 128}, {0, 65536}, {-32768, 32768},
|
||||
{-1000000, 1000000}, {-10, 10}, {-10, 10}};
|
||||
CvRNG* rng = ts->get_rng();
|
||||
RNG rng0;
|
||||
test_case_count = 2;
|
||||
int progress = 0;
|
||||
MemStorage storage(cvCreateMemStorage(0));
|
||||
|
||||
for( int idx = 0; idx < test_case_count; idx++ )
|
||||
{
|
||||
ts->update_context( this, idx, false );
|
||||
progress = update_progress( progress, idx, test_case_count, 0 );
|
||||
|
||||
cvClearMemStorage(storage);
|
||||
|
||||
char buf[L_tmpnam+16];
|
||||
char* filename = tmpnam(buf);
|
||||
strcat(filename, idx % 2 ? ".yml" : ".xml");
|
||||
if(filename[0] == '\\')
|
||||
filename++;
|
||||
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
|
||||
int test_int = (int)cvTsRandInt(rng);
|
||||
double test_real = (cvTsRandInt(rng)%2?1:-1)*exp(cvTsRandReal(rng)*18-9);
|
||||
string test_string = "vw wv23424rt\"&<>&'@#$@$%$%&%IJUKYILFD@#$@%$&*&() ";
|
||||
|
||||
int depth = cvTsRandInt(rng) % (CV_64F+1);
|
||||
int cn = cvTsRandInt(rng) % 4 + 1;
|
||||
Mat test_mat(cvTsRandInt(rng)%30+1, cvTsRandInt(rng)%30+1, CV_MAKETYPE(depth, cn));
|
||||
|
||||
rng0.fill(test_mat, CV_RAND_UNI, Scalar::all(ranges[depth][0]), Scalar::all(ranges[depth][1]));
|
||||
if( depth >= CV_32F )
|
||||
{
|
||||
exp(test_mat, test_mat);
|
||||
Mat test_mat_scale(test_mat.size(), test_mat.type());
|
||||
rng0.fill(test_mat_scale, CV_RAND_UNI, Scalar::all(-1), Scalar::all(1));
|
||||
multiply(test_mat, test_mat_scale, test_mat);
|
||||
}
|
||||
|
||||
CvSeq* seq = cvCreateSeq(test_mat.type(), (int)sizeof(CvSeq),
|
||||
(int)test_mat.elemSize(), storage);
|
||||
cvSeqPushMulti(seq, test_mat.data, test_mat.cols*test_mat.rows);
|
||||
|
||||
CvGraph* graph = cvCreateGraph( CV_ORIENTED_GRAPH,
|
||||
sizeof(CvGraph), sizeof(CvGraphVtx),
|
||||
sizeof(CvGraphEdge), storage );
|
||||
int edges[][2] = {{0,1},{1,2},{2,0},{0,3},{3,4},{4,1}};
|
||||
int i, vcount = 5, ecount = 6;
|
||||
for( i = 0; i < vcount; i++ )
|
||||
cvGraphAddVtx(graph);
|
||||
for( i = 0; i < ecount; i++ )
|
||||
{
|
||||
CvGraphEdge* edge;
|
||||
cvGraphAddEdge(graph, edges[i][0], edges[i][1], 0, &edge);
|
||||
edge->weight = (float)(i+1);
|
||||
}
|
||||
|
||||
depth = cvTsRandInt(rng) % (CV_64F+1);
|
||||
cn = cvTsRandInt(rng) % 4 + 1;
|
||||
int sz[] = {cvTsRandInt(rng)%10+1, cvTsRandInt(rng)%10+1, cvTsRandInt(rng)%10+1};
|
||||
MatND test_mat_nd(3, sz, CV_MAKETYPE(depth, cn));
|
||||
|
||||
rng0.fill(test_mat_nd, CV_RAND_UNI, Scalar::all(ranges[depth][0]), Scalar::all(ranges[depth][1]));
|
||||
if( depth >= CV_32F )
|
||||
{
|
||||
exp(test_mat_nd, test_mat_nd);
|
||||
MatND test_mat_scale(test_mat_nd.dims, test_mat_nd.size, test_mat_nd.type());
|
||||
rng0.fill(test_mat_scale, CV_RAND_UNI, Scalar::all(-1), Scalar::all(1));
|
||||
multiply(test_mat_nd, test_mat_scale, test_mat_nd);
|
||||
}
|
||||
|
||||
int ssz[] = {cvTsRandInt(rng)%10+1, cvTsRandInt(rng)%10+1,
|
||||
cvTsRandInt(rng)%10+1,cvTsRandInt(rng)%10+1};
|
||||
SparseMat test_sparse_mat = cvTsGetRandomSparseMat(4, ssz, cvTsRandInt(rng)%(CV_64F+1),
|
||||
cvTsRandInt(rng) % 10000, 0, 100, rng);
|
||||
|
||||
fs << "test_int" << test_int << "test_real" << test_real << "test_string" << test_string;
|
||||
fs << "test_mat" << test_mat;
|
||||
fs << "test_mat_nd" << test_mat_nd;
|
||||
fs << "test_sparse_mat" << test_sparse_mat;
|
||||
|
||||
fs << "test_list" << "[" << 0.0000000000001 << 2 << CV_PI << -3435345 << "2-502 2-029 3egegeg" <<
|
||||
"{:" << "month" << 12 << "day" << 31 << "year" << 1969 << "}" << "]";
|
||||
fs << "test_map" << "{" << "x" << 1 << "y" << 2 << "width" << 100 << "height" << 200 << "lbp" << "[:";
|
||||
|
||||
const uchar arr[] = {0, 1, 1, 0, 1, 1, 0, 1};
|
||||
fs.writeRaw("u", arr, (int)(sizeof(arr)/sizeof(arr[0])));
|
||||
|
||||
fs << "]" << "}";
|
||||
cvWriteComment(*fs, "test comment", 0);
|
||||
|
||||
fs.writeObj("test_seq", seq);
|
||||
fs.writeObj("test_graph",graph);
|
||||
CvGraph* graph2 = (CvGraph*)cvClone(graph);
|
||||
|
||||
fs.release();
|
||||
|
||||
if(!fs.open(filename, FileStorage::READ))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "filename %s can not be read\n", filename );
|
||||
ts->set_failed_test_info( CvTS::FAIL_MISSING_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
int real_int = (int)fs["test_int"];
|
||||
double real_real = (double)fs["test_real"];
|
||||
string real_string = (string)fs["test_string"];
|
||||
|
||||
if( real_int != test_int ||
|
||||
fabs(real_real - test_real) > DBL_EPSILON*(fabs(test_real)+1) ||
|
||||
real_string != test_string )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the read scalars are not correct\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
CvMat* m = (CvMat*)fs["test_mat"].readObj();
|
||||
CvMat _test_mat = test_mat;
|
||||
double max_diff = 0;
|
||||
CvMat stub1, _test_stub1;
|
||||
cvReshape(m, &stub1, 1, 0);
|
||||
cvReshape(&_test_mat, &_test_stub1, 1, 0);
|
||||
CvPoint pt = {0,0};
|
||||
|
||||
if( !m || !CV_IS_MAT(m) || m->rows != test_mat.rows || m->cols != test_mat.cols ||
|
||||
cvTsCmpEps( &stub1, &_test_stub1, &max_diff, 0, &pt, true) < 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the read matrix is not correct: (%.20g vs %.20g) at (%d,%d)\n",
|
||||
cvGetReal2D(&stub1, pt.y, pt.x), cvGetReal2D(&_test_stub1, pt.y, pt.x),
|
||||
pt.y, pt.x );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
if( m && CV_IS_MAT(m))
|
||||
cvReleaseMat(&m);
|
||||
|
||||
CvMatND* m_nd = (CvMatND*)fs["test_mat_nd"].readObj();
|
||||
CvMatND _test_mat_nd = test_mat_nd;
|
||||
|
||||
if( !m_nd || !CV_IS_MATND(m_nd) )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the read nd-matrix is not correct\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
CvMat stub, _test_stub;
|
||||
cvGetMat(m_nd, &stub, 0, 1);
|
||||
cvGetMat(&_test_mat_nd, &_test_stub, 0, 1);
|
||||
cvReshape(&stub, &stub1, 1, 0);
|
||||
cvReshape(&_test_stub, &_test_stub1, 1, 0);
|
||||
|
||||
if( !CV_ARE_TYPES_EQ(&stub, &_test_stub) ||
|
||||
!CV_ARE_SIZES_EQ(&stub, &_test_stub) ||
|
||||
//cvNorm(&stub, &_test_stub, CV_L2) != 0 )
|
||||
cvTsCmpEps( &stub1, &_test_stub1, &max_diff, 0, &pt, true) < 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "readObj method: the read nd matrix is not correct: (%.20g vs %.20g) vs at (%d,%d)\n",
|
||||
cvGetReal2D(&stub1, pt.y, pt.x), cvGetReal2D(&_test_stub1, pt.y, pt.x),
|
||||
pt.y, pt.x );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
MatND mat_nd2;
|
||||
fs["test_mat_nd"] >> mat_nd2;
|
||||
CvMatND m_nd2 = mat_nd2;
|
||||
cvGetMat(&m_nd2, &stub, 0, 1);
|
||||
cvReshape(&stub, &stub1, 1, 0);
|
||||
|
||||
if( !CV_ARE_TYPES_EQ(&stub, &_test_stub) ||
|
||||
!CV_ARE_SIZES_EQ(&stub, &_test_stub) ||
|
||||
//cvNorm(&stub, &_test_stub, CV_L2) != 0 )
|
||||
cvTsCmpEps( &stub1, &_test_stub1, &max_diff, 0, &pt, true) < 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "C++ method: the read nd matrix is not correct: (%.20g vs %.20g) vs at (%d,%d)\n",
|
||||
cvGetReal2D(&stub1, pt.y, pt.x), cvGetReal2D(&_test_stub1, pt.y, pt.x),
|
||||
pt.y, pt.x );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
cvRelease((void**)&m_nd);
|
||||
|
||||
Ptr<CvSparseMat> m_s = (CvSparseMat*)fs["test_sparse_mat"].readObj();
|
||||
Ptr<CvSparseMat> _test_sparse_ = (CvSparseMat*)test_sparse_mat;
|
||||
Ptr<CvSparseMat> _test_sparse = (CvSparseMat*)cvClone(_test_sparse_);
|
||||
SparseMat m_s2;
|
||||
fs["test_sparse_mat"] >> m_s2;
|
||||
Ptr<CvSparseMat> _m_s2 = (CvSparseMat*)m_s2;
|
||||
|
||||
if( !m_s || !CV_IS_SPARSE_MAT(m_s) ||
|
||||
!cvTsCheckSparse(m_s, _test_sparse,0) ||
|
||||
!cvTsCheckSparse(_m_s2, _test_sparse,0))
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the read sparse matrix is not correct\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
FileNode tl = fs["test_list"];
|
||||
if( tl.type() != FileNode::SEQ || tl.size() != 6 ||
|
||||
fabs((double)tl[0] - 0.0000000000001) >= DBL_EPSILON ||
|
||||
(int)tl[1] != 2 ||
|
||||
fabs((double)tl[2] - CV_PI) >= DBL_EPSILON ||
|
||||
(int)tl[3] != -3435345 ||
|
||||
(string)tl[4] != "2-502 2-029 3egegeg" ||
|
||||
tl[5].type() != FileNode::MAP || tl[5].size() != 3 ||
|
||||
(int)tl[5]["month"] != 12 ||
|
||||
(int)tl[5]["day"] != 31 ||
|
||||
(int)tl[5]["year"] != 1969 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the test list is incorrect\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
FileNode tm = fs["test_map"];
|
||||
FileNode tm_lbp = tm["lbp"];
|
||||
|
||||
int real_x = (int)tm["x"];
|
||||
int real_y = (int)tm["y"];
|
||||
int real_width = (int)tm["width"];
|
||||
int real_height = (int)tm["height"];
|
||||
|
||||
|
||||
int real_lbp_val = 0;
|
||||
FileNodeIterator it;
|
||||
it = tm_lbp.begin();
|
||||
real_lbp_val |= (int)*it << 0;
|
||||
++it;
|
||||
real_lbp_val |= (int)*it << 1;
|
||||
it++;
|
||||
real_lbp_val |= (int)*it << 2;
|
||||
it += 1;
|
||||
real_lbp_val |= (int)*it << 3;
|
||||
FileNodeIterator it2(it);
|
||||
it2 += 4;
|
||||
real_lbp_val |= (int)*it2 << 7;
|
||||
--it2;
|
||||
real_lbp_val |= (int)*it2 << 6;
|
||||
it2--;
|
||||
real_lbp_val |= (int)*it2 << 5;
|
||||
it2 -= 1;
|
||||
real_lbp_val |= (int)*it2 << 4;
|
||||
it2 += -1;
|
||||
CV_Assert( it == it2 );
|
||||
|
||||
if( tm.type() != FileNode::MAP || tm.size() != 5 ||
|
||||
real_x != 1 ||
|
||||
real_y != 2 ||
|
||||
real_width != 100 ||
|
||||
real_height != 200 ||
|
||||
tm_lbp.type() != FileNode::SEQ ||
|
||||
tm_lbp.size() != 8 ||
|
||||
real_lbp_val != 0xb6 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the test map is incorrect\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
CvGraph* graph3 = (CvGraph*)fs["test_graph"].readObj();
|
||||
if(graph2->active_count != vcount || graph3->active_count != vcount ||
|
||||
graph2->edges->active_count != ecount || graph3->edges->active_count != ecount)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the cloned or read graph have wrong number of vertices or edges\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
for( i = 0; i < ecount; i++ )
|
||||
{
|
||||
CvGraphEdge* edge2 = cvFindGraphEdge(graph2, edges[i][0], edges[i][1]);
|
||||
CvGraphEdge* edge3 = cvFindGraphEdge(graph3, edges[i][0], edges[i][1]);
|
||||
if( !edge2 || edge2->weight != (float)(i+1) ||
|
||||
!edge3 || edge3->weight != (float)(i+1) )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "the cloned or read graph do not have the edge (%d, %d)\n", edges[i][0], edges[i][1] );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fs.release();
|
||||
remove(filename);
|
||||
}
|
||||
}
|
||||
|
||||
CV_IOTest opencv_io_test;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,308 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
#define CHECK_C
|
||||
|
||||
Size sz( 200, 500);
|
||||
|
||||
class CV_PCATest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_PCATest() : CvTest( "pca", "PCA funcs" ) {}
|
||||
protected:
|
||||
void run( int);
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
void CV_PCATest::run( int )
|
||||
{
|
||||
int code = CvTS::OK, err;
|
||||
int maxComponents = 1;
|
||||
Mat points( 1000, 3, CV_32FC1);
|
||||
|
||||
RNG rng = *ts->get_rng(); // get ts->rng seed
|
||||
rng.fill( points, RNG::NORMAL, Scalar::all(0.0), Scalar::all(1.0) );
|
||||
|
||||
float mp[] = { 3.0f, 3.0f, 3.0f }, cp[] = { 0.5f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.3f };
|
||||
Mat mean( 1, 3, CV_32FC1, mp ),
|
||||
cov( 3, 3, CV_32FC1, cp );
|
||||
for( int i = 0; i < points.rows; i++ )
|
||||
{
|
||||
Mat r(1, points.cols, CV_32FC1, points.ptr<float>(i));
|
||||
r = r * cov + mean;
|
||||
}
|
||||
|
||||
PCA pca( points, Mat(), CV_PCA_DATA_AS_ROW, maxComponents );
|
||||
|
||||
// check project
|
||||
Mat prjPoints = pca.project( points );
|
||||
err = 0;
|
||||
for( int i = 0; i < prjPoints.rows; i++ )
|
||||
{
|
||||
float val = prjPoints.at<float>(i,0);
|
||||
if( val > 3.0f || val < -3.0f )
|
||||
err++;
|
||||
}
|
||||
float projectErr = 0.02f;
|
||||
if( (float)err > prjPoints.rows * projectErr )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of project() (real = %f, permissible = %f)",
|
||||
(float)err/(float)prjPoints.rows, projectErr );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
// check backProject
|
||||
Mat points1 = pca.backProject( prjPoints );
|
||||
err = 0;
|
||||
for( int i = 0; i < points.rows; i++ )
|
||||
{
|
||||
if( fabs(points1.at<float>(i,0) - mean.at<float>(0,0)) > 0.15 ||
|
||||
fabs(points1.at<float>(i,1) - points.at<float>(i,1)) > 0.05 ||
|
||||
fabs(points1.at<float>(i,2) - mean.at<float>(0,2)) > 0.15 )
|
||||
err++;
|
||||
}
|
||||
float backProjectErr = 0.05f;
|
||||
if( (float)err > prjPoints.rows*backProjectErr )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of backProject() (real = %f, permissible = %f)",
|
||||
(float)err/(float)prjPoints.rows, backProjectErr );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
CvRNG *oldRng = ts->get_rng(); // set ts->rng seed
|
||||
*oldRng = rng.state;
|
||||
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
#else
|
||||
void CV_PCATest::run( int )
|
||||
{
|
||||
int code = CvTS::OK;
|
||||
|
||||
double diffPrjEps, diffBackPrjEps,
|
||||
prjEps, backPrjEps,
|
||||
evalEps, evecEps;
|
||||
int maxComponents = 100;
|
||||
Mat rPoints(sz, CV_32FC1), rTestPoints(sz, CV_32FC1);
|
||||
RNG rng = *ts->get_rng();
|
||||
|
||||
rng.fill( rPoints, RNG::UNIFORM, Scalar::all(0.0), Scalar::all(1.0) );
|
||||
rng.fill( rTestPoints, RNG::UNIFORM, Scalar::all(0.0), Scalar::all(1.0) );
|
||||
|
||||
PCA rPCA( rPoints, Mat(), CV_PCA_DATA_AS_ROW, maxComponents ), cPCA;
|
||||
|
||||
// 1. check C++ PCA & ROW
|
||||
Mat rPrjTestPoints = rPCA.project( rTestPoints );
|
||||
Mat rBackPrjTestPoints = rPCA.backProject( rPrjTestPoints );
|
||||
|
||||
Mat avg(1, sz.width, CV_32FC1 );
|
||||
reduce( rPoints, avg, 0, CV_REDUCE_AVG );
|
||||
Mat Q = rPoints - repeat( avg, rPoints.rows, 1 ), Qt = Q.t(), eval, evec;
|
||||
Q = Qt * Q;
|
||||
Q = Q /(float)rPoints.rows;
|
||||
|
||||
eigen( Q, eval, evec );
|
||||
/*SVD svd(Q);
|
||||
evec = svd.vt;
|
||||
eval = svd.w;*/
|
||||
|
||||
Mat subEval( maxComponents, 1, eval.type(), eval.data ),
|
||||
subEvec( maxComponents, evec.cols, evec.type(), evec.data );
|
||||
|
||||
#ifdef CHECK_C
|
||||
Mat prjTestPoints, backPrjTestPoints, cPoints = rPoints.t(), cTestPoints = rTestPoints.t();
|
||||
CvMat _points, _testPoints, _avg, _eval, _evec, _prjTestPoints, _backPrjTestPoints;
|
||||
#endif
|
||||
|
||||
// check eigen()
|
||||
double eigenEps = 1e-6;
|
||||
double err;
|
||||
for(int i = 0; i < Q.rows; i++ )
|
||||
{
|
||||
Mat v = evec.row(i).t();
|
||||
Mat Qv = Q * v;
|
||||
|
||||
Mat lv = eval.at<float>(i,0) * v;
|
||||
err = norm( Qv, lv );
|
||||
if( err > eigenEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of eigen(); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
}
|
||||
// check pca eigenvalues
|
||||
evalEps = 1e-6, evecEps = 1;
|
||||
err = norm( rPCA.eigenvalues, subEval );
|
||||
if( err > evalEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "pca.eigenvalues is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
// check pca eigenvectors
|
||||
err = norm( rPCA.eigenvectors, subEvec, CV_RELATIVE_L2 );
|
||||
if( err > evecEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "pca.eigenvectors is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
|
||||
prjEps = 1.265, backPrjEps = 1.265;
|
||||
for( int i = 0; i < rTestPoints.rows; i++ )
|
||||
{
|
||||
// check pca project
|
||||
Mat subEvec_t = subEvec.t();
|
||||
Mat prj = rTestPoints.row(i) - avg; prj *= subEvec_t;
|
||||
err = norm(rPrjTestPoints.row(i), prj, CV_RELATIVE_L2);
|
||||
if( err > prjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
// check pca backProject
|
||||
Mat backPrj = rPrjTestPoints.row(i) * subEvec + avg;
|
||||
err = norm( rBackPrjTestPoints.row(i), backPrj, CV_RELATIVE_L2 );
|
||||
if( err > backPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. check C++ PCA & COL
|
||||
cPCA( rPoints.t(), Mat(), CV_PCA_DATA_AS_COL, maxComponents );
|
||||
diffPrjEps = 1, diffBackPrjEps = 1;
|
||||
err = norm(cPCA.project(rTestPoints.t()), rPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
err = norm(cPCA.backProject(rPrjTestPoints.t()), rBackPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
|
||||
#ifdef CHECK_C
|
||||
// 3. check C PCA & ROW
|
||||
_points = rPoints;
|
||||
_testPoints = rTestPoints;
|
||||
_avg = avg;
|
||||
_eval = eval;
|
||||
_evec = evec;
|
||||
prjTestPoints.create(rTestPoints.rows, maxComponents, rTestPoints.type() );
|
||||
backPrjTestPoints.create(rPoints.size(), rPoints.type() );
|
||||
_prjTestPoints = prjTestPoints;
|
||||
_backPrjTestPoints = backPrjTestPoints;
|
||||
|
||||
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_ROW );
|
||||
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
|
||||
cvBackProjectPCA( &_prjTestPoints, &_avg, &_evec, &_backPrjTestPoints );
|
||||
|
||||
err = norm(prjTestPoints, rPrjTestPoints, CV_RELATIVE_L2);
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
err = norm(backPrjTestPoints, rBackPrjTestPoints, CV_RELATIVE_L2);
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
|
||||
// 3. check C PCA & COL
|
||||
_points = cPoints;
|
||||
_testPoints = cTestPoints;
|
||||
avg = avg.t(); _avg = avg;
|
||||
eval = eval.t(); _eval = eval;
|
||||
evec = evec.t(); _evec = evec;
|
||||
prjTestPoints = prjTestPoints.t(); _prjTestPoints = prjTestPoints;
|
||||
backPrjTestPoints = backPrjTestPoints.t(); _backPrjTestPoints = backPrjTestPoints;
|
||||
|
||||
cvCalcPCA( &_points, &_avg, &_eval, &_evec, CV_PCA_DATA_AS_COL );
|
||||
cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints );
|
||||
cvBackProjectPCA( &_prjTestPoints, &_avg, &_evec, &_backPrjTestPoints );
|
||||
|
||||
err = norm(prjTestPoints, rPrjTestPoints.t(), CV_RELATIVE_L2 );
|
||||
if( err > diffPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
err = norm(backPrjTestPoints, rBackPrjTestPoints.t(), CV_RELATIVE_L2);
|
||||
if( err > diffBackPrjEps )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
goto exit_func;
|
||||
}
|
||||
#endif
|
||||
|
||||
exit_func:
|
||||
|
||||
CvRNG* _rng = ts->get_rng();
|
||||
*_rng = rng.state;
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
CV_PCATest pca_test;
|
||||
@@ -1,344 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
|
||||
class CV_RandTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_RandTest();
|
||||
protected:
|
||||
void run(int);
|
||||
bool check_pdf(const Mat& hist, double scale, int dist_type,
|
||||
double& refval, double& realval);
|
||||
};
|
||||
|
||||
|
||||
CV_RandTest::CV_RandTest():
|
||||
CvTest( "rand", "cvRandArr, cvRNG" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
|
||||
static double chi2_p95(int n)
|
||||
{
|
||||
static float chi2_tab95[] = {
|
||||
3.841f, 5.991f, 7.815f, 9.488f, 11.07f, 12.59f, 14.07f, 15.51f,
|
||||
16.92f, 18.31f, 19.68f, 21.03f, 21.03f, 22.36f, 23.69f, 25.00f,
|
||||
26.30f, 27.59f, 28.87f, 30.14f, 31.41f, 32.67f, 33.92f, 35.17f,
|
||||
36.42f, 37.65f, 38.89f, 40.11f, 41.34f, 42.56f, 43.77f };
|
||||
static const double xp = 1.64;
|
||||
CV_Assert(n >= 1);
|
||||
|
||||
if( n <= 30 )
|
||||
return chi2_tab95[n-1];
|
||||
return n + sqrt((double)2*n)*xp + 0.6666666666666*(xp*xp - 1);
|
||||
}
|
||||
|
||||
bool CV_RandTest::check_pdf(const Mat& hist, double scale,
|
||||
int dist_type, double& refval, double& realval)
|
||||
{
|
||||
Mat hist0(hist.size(), CV_32F);
|
||||
const int* H = (const int*)hist.data;
|
||||
float* H0 = ((float*)hist0.data);
|
||||
int i, hsz = hist.cols;
|
||||
|
||||
double sum = 0;
|
||||
for( i = 0; i < hsz; i++ )
|
||||
sum += H[i];
|
||||
CV_Assert( fabs(1./sum - scale) < FLT_EPSILON );
|
||||
|
||||
if( dist_type == CV_RAND_UNI )
|
||||
{
|
||||
float scale0 = (float)(1./hsz);
|
||||
for( i = 0; i < hsz; i++ )
|
||||
H0[i] = scale0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double sum = 0, r = (hsz-1.)/2;
|
||||
double alpha = 2*sqrt(2.)/r, beta = -alpha*r;
|
||||
for( i = 0; i < hsz; i++ )
|
||||
{
|
||||
double x = i*alpha + beta;
|
||||
H0[i] = (float)exp(-x*x);
|
||||
sum += H0[i];
|
||||
}
|
||||
sum = 1./sum;
|
||||
for( i = 0; i < hsz; i++ )
|
||||
H0[i] = (float)(H0[i]*sum);
|
||||
}
|
||||
|
||||
double chi2 = 0;
|
||||
for( i = 0; i < hsz; i++ )
|
||||
{
|
||||
double a = H0[i];
|
||||
double b = H[i]*scale;
|
||||
if( a > DBL_EPSILON )
|
||||
chi2 += (a - b)*(a - b)/(a + b);
|
||||
}
|
||||
realval = chi2;
|
||||
|
||||
double chi2_pval = chi2_p95(hsz - 1 - (dist_type == CV_RAND_NORMAL ? 2 : 0));
|
||||
refval = chi2_pval*0.01;
|
||||
return realval <= refval;
|
||||
}
|
||||
|
||||
void CV_RandTest::run( int )
|
||||
{
|
||||
static int _ranges[][2] =
|
||||
{{ 0, 256 }, { -128, 128 }, { 0, 65536 }, { -32768, 32768 },
|
||||
{ -1000000, 1000000 }, { -1000, 1000 }, { -1000, 1000 }};
|
||||
|
||||
const int MAX_SDIM = 10;
|
||||
const int N = 2000000;
|
||||
const int maxSlice = 1000;
|
||||
const int MAX_HIST_SIZE = 1000;
|
||||
int progress = 0;
|
||||
|
||||
CvRNG* rng = ts->get_rng();
|
||||
RNG tested_rng = theRNG();
|
||||
test_case_count = 200;
|
||||
|
||||
for( int idx = 0; idx < test_case_count; idx++ )
|
||||
{
|
||||
progress = update_progress( progress, idx, test_case_count, 0 );
|
||||
ts->update_context( this, idx, false );
|
||||
|
||||
int depth = cvTsRandInt(rng) % (CV_64F+1);
|
||||
int c, cn = (cvTsRandInt(rng) % 4) + 1;
|
||||
int type = CV_MAKETYPE(depth, cn);
|
||||
int dist_type = cvTsRandInt(rng) % (CV_RAND_NORMAL+1);
|
||||
int i, k, SZ = N/cn;
|
||||
Scalar A, B;
|
||||
|
||||
bool do_sphere_test = dist_type == CV_RAND_UNI;
|
||||
Mat arr[2], hist[4];
|
||||
int W[] = {0,0,0,0};
|
||||
|
||||
arr[0].create(1, SZ, type);
|
||||
arr[1].create(1, SZ, type);
|
||||
bool fast_algo = dist_type == CV_RAND_UNI && depth < CV_32F;
|
||||
|
||||
for( c = 0; c < cn; c++ )
|
||||
{
|
||||
int a, b, hsz;
|
||||
if( dist_type == CV_RAND_UNI )
|
||||
{
|
||||
a = (int)(cvTsRandInt(rng) % (_ranges[depth][1] -
|
||||
_ranges[depth][0])) + _ranges[depth][0];
|
||||
do
|
||||
{
|
||||
b = (int)(cvTsRandInt(rng) % (_ranges[depth][1] -
|
||||
_ranges[depth][0])) + _ranges[depth][0];
|
||||
}
|
||||
while( abs(a-b) <= 1 );
|
||||
if( a > b )
|
||||
std::swap(a, b);
|
||||
|
||||
unsigned r = (unsigned)(b - a);
|
||||
fast_algo = fast_algo && r <= 256 && (r & (r-1)) == 0;
|
||||
hsz = min((unsigned)(b - a), (unsigned)MAX_HIST_SIZE);
|
||||
do_sphere_test = do_sphere_test && b - a >= 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
int vrange = _ranges[depth][1] - _ranges[depth][0];
|
||||
int meanrange = vrange/16;
|
||||
int mindiv = MAX(vrange/20, 5);
|
||||
int maxdiv = MIN(vrange/8, 10000);
|
||||
|
||||
a = cvTsRandInt(rng) % meanrange - meanrange/2 +
|
||||
(_ranges[depth][0] + _ranges[depth][1])/2;
|
||||
b = cvTsRandInt(rng) % (maxdiv - mindiv) + mindiv;
|
||||
hsz = min((unsigned)b*9, (unsigned)MAX_HIST_SIZE);
|
||||
}
|
||||
A[c] = a;
|
||||
B[c] = b;
|
||||
hist[c].create(1, hsz, CV_32S);
|
||||
}
|
||||
|
||||
cv::RNG saved_rng = tested_rng;
|
||||
int maxk = fast_algo ? 0 : 1;
|
||||
for( k = 0; k <= maxk; k++ )
|
||||
{
|
||||
tested_rng = saved_rng;
|
||||
int sz = 0, dsz = 0, slice;
|
||||
for( slice = 0; slice < maxSlice; slice++, sz += dsz )
|
||||
{
|
||||
dsz = slice+1 < maxSlice ? cvTsRandInt(rng) % (SZ - sz + 1) : SZ - sz;
|
||||
Mat aslice = arr[k].colRange(sz, sz + dsz);
|
||||
tested_rng.fill(aslice, dist_type, A, B);
|
||||
}
|
||||
}
|
||||
|
||||
if( maxk >= 1 && norm(arr[0], arr[1], NORM_INF) != 0 )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "RNG output depends on the array lengths (some generated numbers get lost?)" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
for( c = 0; c < cn; c++ )
|
||||
{
|
||||
const uchar* data = arr[0].data;
|
||||
int* H = hist[c].ptr<int>();
|
||||
int HSZ = hist[c].cols;
|
||||
double minVal = dist_type == CV_RAND_UNI ? A[c] : A[c] - B[c]*4;
|
||||
double maxVal = dist_type == CV_RAND_UNI ? B[c] : A[c] + B[c]*4;
|
||||
double scale = HSZ/(maxVal - minVal);
|
||||
double delta = -minVal*scale;
|
||||
|
||||
hist[c] = Scalar::all(0);
|
||||
|
||||
for( i = c; i < SZ*cn; i += cn )
|
||||
{
|
||||
double val = depth == CV_8U ? ((const uchar*)data)[i] :
|
||||
depth == CV_8S ? ((const schar*)data)[i] :
|
||||
depth == CV_16U ? ((const ushort*)data)[i] :
|
||||
depth == CV_16S ? ((const short*)data)[i] :
|
||||
depth == CV_32S ? ((const int*)data)[i] :
|
||||
depth == CV_32F ? ((const float*)data)[i] :
|
||||
((const double*)data)[i];
|
||||
int ival = cvFloor(val*scale + delta);
|
||||
if( (unsigned)ival < (unsigned)HSZ )
|
||||
{
|
||||
H[ival]++;
|
||||
W[c]++;
|
||||
}
|
||||
else if( dist_type == CV_RAND_UNI )
|
||||
{
|
||||
if( (minVal <= val && val < maxVal) || (depth >= CV_32F && val == maxVal) )
|
||||
{
|
||||
H[ival < 0 ? 0 : HSZ-1]++;
|
||||
W[c]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
putchar('^');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( dist_type == CV_RAND_UNI && W[c] != SZ )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Uniform RNG gave values out of the range [%g,%g) on channel %d/%d\n",
|
||||
A[c], B[c], c, cn);
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
if( dist_type == CV_RAND_NORMAL && W[c] < SZ*.90)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Normal RNG gave too many values out of the range (%g+4*%g,%g+4*%g) on channel %d/%d\n",
|
||||
A[c], B[c], A[c], B[c], c, cn);
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
double refval = 0, realval = 0;
|
||||
|
||||
if( !check_pdf(hist[c], 1./W[c], dist_type, refval, realval) )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "RNG failed Chi-square test "
|
||||
"(got %g vs probable maximum %g) on channel %d/%d\n",
|
||||
realval, refval, c, cn);
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Monte-Carlo test. Compute volume of SDIM-dimensional sphere
|
||||
// inscribed in [-1,1]^SDIM cube.
|
||||
if( do_sphere_test )
|
||||
{
|
||||
int SDIM = cvTsRandInt(rng) % (MAX_SDIM-1) + 2;
|
||||
int N0 = (SZ*cn/SDIM), N = 0;
|
||||
double r2 = 0;
|
||||
const uchar* data = arr[0].data;
|
||||
double scale[4], delta[4];
|
||||
for( c = 0; c < cn; c++ )
|
||||
{
|
||||
scale[c] = 2./(B[c] - A[c]);
|
||||
delta[c] = -A[c]*scale[c] - 1;
|
||||
}
|
||||
|
||||
for( i = k = c = 0; i <= SZ*cn - SDIM; i++, k++, c++ )
|
||||
{
|
||||
double val = depth == CV_8U ? ((const uchar*)data)[i] :
|
||||
depth == CV_8S ? ((const schar*)data)[i] :
|
||||
depth == CV_16U ? ((const ushort*)data)[i] :
|
||||
depth == CV_16S ? ((const short*)data)[i] :
|
||||
depth == CV_32S ? ((const int*)data)[i] :
|
||||
depth == CV_32F ? ((const float*)data)[i] : ((const double*)data)[i];
|
||||
c &= c < cn ? -1 : 0;
|
||||
val = val*scale[c] + delta[c];
|
||||
r2 += val*val;
|
||||
if( k == SDIM-1 )
|
||||
{
|
||||
N += r2 <= 1;
|
||||
r2 = 0;
|
||||
k = -1;
|
||||
}
|
||||
}
|
||||
|
||||
double V = ((double)N/N0)*(1 << SDIM);
|
||||
|
||||
// the theoretically computed volume
|
||||
int sdim = SDIM % 2;
|
||||
double V0 = sdim + 1;
|
||||
for( sdim += 2; sdim <= SDIM; sdim += 2 )
|
||||
V0 *= 2*CV_PI/sdim;
|
||||
|
||||
if( fabs(V - V0) > 0.3*fabs(V0) )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "RNG failed %d-dim sphere volume test (got %g instead of %g)\n",
|
||||
SDIM, V, V0);
|
||||
ts->printf( CvTS::LOG, "depth = %d, N0 = %d\n", depth, N0);
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CV_RandTest rand_test;
|
||||
@@ -1,308 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
|
||||
using namespace cv;
|
||||
|
||||
|
||||
class CV_ReduceTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_ReduceTest() : CvTest( "reduce", "reduce" ) {}
|
||||
protected:
|
||||
void run( int);
|
||||
int checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim, double eps );
|
||||
int checkCase( int srcType, int dstType, int dim, Size sz );
|
||||
int checkDim( int dim, Size sz );
|
||||
int checkSize( Size sz );
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
void testReduce( const Mat& src, Mat& sum, Mat& avg, Mat& max, Mat& min, int dim )
|
||||
{
|
||||
assert( src.channels() == 1 );
|
||||
if( dim == 0 ) // row
|
||||
{
|
||||
sum.create( 1, src.cols, CV_64FC1 );
|
||||
max.create( 1, src.cols, CV_64FC1 );
|
||||
min.create( 1, src.cols, CV_64FC1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
sum.create( src.rows, 1, CV_64FC1 );
|
||||
max.create( src.rows, 1, CV_64FC1 );
|
||||
min.create( src.rows, 1, CV_64FC1 );
|
||||
}
|
||||
sum.setTo(Scalar(0));
|
||||
max.setTo(Scalar(-DBL_MAX));
|
||||
min.setTo(Scalar(DBL_MAX));
|
||||
|
||||
const Mat_<Type>& src_ = src;
|
||||
Mat_<double>& sum_ = (Mat_<double>&)sum;
|
||||
Mat_<double>& min_ = (Mat_<double>&)min;
|
||||
Mat_<double>& max_ = (Mat_<double>&)max;
|
||||
|
||||
if( dim == 0 )
|
||||
{
|
||||
for( int ri = 0; ri < src.rows; ri++ )
|
||||
{
|
||||
for( int ci = 0; ci < src.cols; ci++ )
|
||||
{
|
||||
sum_(0, ci) += src_(ri, ci);
|
||||
max_(0, ci) = std::max( max_(0, ci), (double)src_(ri, ci) );
|
||||
min_(0, ci) = std::min( min_(0, ci), (double)src_(ri, ci) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int ci = 0; ci < src.cols; ci++ )
|
||||
{
|
||||
for( int ri = 0; ri < src.rows; ri++ )
|
||||
{
|
||||
sum_(ri, 0) += src_(ri, ci);
|
||||
max_(ri, 0) = std::max( max_(ri, 0), (double)src_(ri, ci) );
|
||||
min_(ri, 0) = std::min( min_(ri, 0), (double)src_(ri, ci) );
|
||||
}
|
||||
}
|
||||
}
|
||||
sum.convertTo( avg, CV_64FC1 );
|
||||
avg = avg * (1.0 / (dim==0 ? (double)src.rows : (double)src.cols));
|
||||
}
|
||||
|
||||
void getMatTypeStr( int type, string& str)
|
||||
{
|
||||
str = type == CV_8UC1 ? "CV_8UC1" :
|
||||
type == CV_8SC1 ? "CV_8SC1" :
|
||||
type == CV_16UC1 ? "CV_16UC1" :
|
||||
type == CV_16SC1 ? "CV_16SC1" :
|
||||
type == CV_32SC1 ? "CV_32SC1" :
|
||||
type == CV_32FC1 ? "CV_32FC1" :
|
||||
type == CV_64FC1 ? "CV_64FC1" : "unsupported matrix type";
|
||||
}
|
||||
|
||||
int CV_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat& opRes, int dim, double eps )
|
||||
{
|
||||
int srcType = src.type();
|
||||
bool support = false;
|
||||
if( opType == CV_REDUCE_SUM || opType == CV_REDUCE_AVG )
|
||||
{
|
||||
if( srcType == CV_8U && (dstType == CV_32S || dstType == CV_32F || dstType == CV_64F) )
|
||||
support = true;
|
||||
if( srcType == CV_16U && (dstType == CV_32F || dstType == CV_64F) )
|
||||
support = true;
|
||||
if( srcType == CV_16S && (dstType == CV_32F || dstType == CV_64F) )
|
||||
support = true;
|
||||
if( srcType == CV_32F && (dstType == CV_32F || dstType == CV_64F) )
|
||||
support = true;
|
||||
if( srcType == CV_64F && dstType == CV_64F)
|
||||
support = true;
|
||||
}
|
||||
else if( opType == CV_REDUCE_MAX )
|
||||
{
|
||||
if( srcType == CV_8U && dstType == CV_8U )
|
||||
support = true;
|
||||
if( srcType == CV_32F && dstType == CV_32F )
|
||||
support = true;
|
||||
if( srcType == CV_64F && dstType == CV_64F )
|
||||
support = true;
|
||||
}
|
||||
else if( opType == CV_REDUCE_MIN )
|
||||
{
|
||||
if( srcType == CV_8U && dstType == CV_8U)
|
||||
support = true;
|
||||
if( srcType == CV_32F && dstType == CV_32F)
|
||||
support = true;
|
||||
if( srcType == CV_64F && dstType == CV_64F)
|
||||
support = true;
|
||||
}
|
||||
if( !support )
|
||||
return CvTS::OK;
|
||||
|
||||
assert( opRes.type() == CV_64FC1 );
|
||||
Mat _dst, dst;
|
||||
reduce( src, _dst, dim, opType, dstType );
|
||||
_dst.convertTo( dst, CV_64FC1 );
|
||||
if( norm( opRes, dst, NORM_INF ) > eps )
|
||||
{
|
||||
char msg[100];
|
||||
const char* opTypeStr = opType == CV_REDUCE_SUM ? "CV_REDUCE_SUM" :
|
||||
opType == CV_REDUCE_AVG ? "CV_REDUCE_AVG" :
|
||||
opType == CV_REDUCE_MAX ? "CV_REDUCE_MAX" :
|
||||
opType == CV_REDUCE_MIN ? "CV_REDUCE_MIN" : "unknown operation type";
|
||||
string srcTypeStr, dstTypeStr;
|
||||
getMatTypeStr( src.type(), srcTypeStr );
|
||||
getMatTypeStr( dstType, dstTypeStr );
|
||||
const char* dimStr = dim == 0 ? "ROWS" : "COLS";
|
||||
|
||||
sprintf( msg, "bad accuracy with srcType = %s, dstType = %s, opType = %s, dim = %s",
|
||||
srcTypeStr.c_str(), dstTypeStr.c_str(), opTypeStr, dimStr );
|
||||
ts->printf( CvTS::LOG, msg );
|
||||
return CvTS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int CV_ReduceTest::checkCase( int srcType, int dstType, int dim, Size sz )
|
||||
{
|
||||
int code = CvTS::OK, tempCode;
|
||||
Mat src, sum, avg, max, min;
|
||||
|
||||
src.create( sz, srcType );
|
||||
randu( src, Scalar(0), Scalar(100) );
|
||||
|
||||
if( srcType == CV_8UC1 )
|
||||
testReduce<uchar>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_8SC1 )
|
||||
testReduce<char>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_16UC1 )
|
||||
testReduce<unsigned short int>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_16SC1 )
|
||||
testReduce<short int>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_32SC1 )
|
||||
testReduce<int>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_32FC1 )
|
||||
testReduce<float>( src, sum, avg, max, min, dim );
|
||||
else if( srcType == CV_64FC1 )
|
||||
testReduce<double>( src, sum, avg, max, min, dim );
|
||||
else
|
||||
assert( 0 );
|
||||
|
||||
// 1. sum
|
||||
tempCode = checkOp( src, dstType, CV_REDUCE_SUM, sum, dim,
|
||||
srcType == CV_32FC1 && dstType == CV_32FC1 ? 0.05 : FLT_EPSILON );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// 2. avg
|
||||
tempCode = checkOp( src, dstType, CV_REDUCE_AVG, avg, dim,
|
||||
dstType == CV_32SC1 ? 0.6 : 0.00007 );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// 3. max
|
||||
tempCode = checkOp( src, dstType, CV_REDUCE_MAX, max, dim, FLT_EPSILON );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// 4. min
|
||||
tempCode = checkOp( src, dstType, CV_REDUCE_MIN, min, dim, FLT_EPSILON );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int CV_ReduceTest::checkDim( int dim, Size sz )
|
||||
{
|
||||
int code = CvTS::OK, tempCode;
|
||||
|
||||
// CV_8UC1
|
||||
tempCode = checkCase( CV_8UC1, CV_8UC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_8UC1, CV_32SC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_8UC1, CV_32FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_8UC1, CV_64FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// CV_16UC1
|
||||
tempCode = checkCase( CV_16UC1, CV_32FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_16UC1, CV_64FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// CV_16SC1
|
||||
tempCode = checkCase( CV_16SC1, CV_32FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_16SC1, CV_64FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// CV_32FC1
|
||||
tempCode = checkCase( CV_32FC1, CV_32FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkCase( CV_32FC1, CV_64FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
// CV_64FC1
|
||||
tempCode = checkCase( CV_64FC1, CV_64FC1, dim, sz );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int CV_ReduceTest::checkSize( Size sz )
|
||||
{
|
||||
int code = CvTS::OK, tempCode;
|
||||
|
||||
tempCode = checkDim( 0, sz ); // rows
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkDim( 1, sz ); // cols
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void CV_ReduceTest::run( int )
|
||||
{
|
||||
int code = CvTS::OK, tempCode;
|
||||
|
||||
tempCode = checkSize( Size(1,1) );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkSize( Size(1,100) );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkSize( Size(100,1) );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
tempCode = checkSize( Size(1000,500) );
|
||||
code = tempCode != CvTS::OK ? tempCode : code;
|
||||
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
CV_ReduceTest reduce_test;
|
||||
@@ -1,168 +0,0 @@
|
||||
// 2008-05-14, Xavier Delacour <xavier.delacour@gmail.com>
|
||||
|
||||
#include "cxcoretest.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
typedef std::complex<double> complex_type;
|
||||
|
||||
struct pred_complex
|
||||
{
|
||||
bool operator() (const complex_type& lhs, const complex_type& rhs) const
|
||||
{
|
||||
return fabs(lhs.real() - rhs.real()) > fabs(rhs.real())*FLT_EPSILON ? lhs.real() < rhs.real() : lhs.imag() < rhs.imag();
|
||||
}
|
||||
};
|
||||
|
||||
struct pred_double
|
||||
{
|
||||
bool operator() (const double& lhs, const double& rhs) const
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
};
|
||||
|
||||
class CV_SolvePolyTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_SolvePolyTest();
|
||||
~CV_SolvePolyTest();
|
||||
protected:
|
||||
virtual void run( int start_from );
|
||||
};
|
||||
|
||||
CV_SolvePolyTest::CV_SolvePolyTest() : CvTest( "solve-poly", "cvSolvePoly" ) {}
|
||||
|
||||
CV_SolvePolyTest::~CV_SolvePolyTest() {}
|
||||
|
||||
void CV_SolvePolyTest::run( int )
|
||||
{
|
||||
CvRNG rng = cvRNG();
|
||||
int fig = 100;
|
||||
double range = 50;
|
||||
double err_eps = 1e-4;
|
||||
|
||||
for (int idx = 0, max_idx = 1000, progress = 0; idx < max_idx; ++idx)
|
||||
{
|
||||
progress = update_progress(progress, idx-1, max_idx, 0);
|
||||
int n = cvRandInt(&rng) % 13 + 1;
|
||||
std::vector<complex_type> r(n), ar(n), c(n + 1, 0);
|
||||
std::vector<double> a(n + 1), u(n * 2), ar1(n), ar2(n);
|
||||
|
||||
int rr_odds = 3; // odds that we get a real root
|
||||
for (int j = 0; j < n;)
|
||||
{
|
||||
if (cvRandInt(&rng) % rr_odds == 0 || j == n - 1)
|
||||
r[j++] = cvRandReal(&rng) * range;
|
||||
else
|
||||
{
|
||||
r[j] = complex_type(cvRandReal(&rng) * range,
|
||||
cvRandReal(&rng) * range + 1);
|
||||
r[j + 1] = std::conj(r[j]);
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0, k = 1 << n, jj, kk; j < k; ++j)
|
||||
{
|
||||
int p = 0;
|
||||
complex_type v(1);
|
||||
for (jj = 0, kk = 1; jj < n && !(j & kk); ++jj, ++p, kk <<= 1)
|
||||
;
|
||||
for (; jj < n; ++jj, kk <<= 1)
|
||||
{
|
||||
if (j & kk)
|
||||
v *= -r[jj];
|
||||
else
|
||||
++p;
|
||||
}
|
||||
c[p] += v;
|
||||
}
|
||||
|
||||
bool pass = false;
|
||||
double div = 0, s = 0;
|
||||
int cubic_case = idx & 1;
|
||||
for (int maxiter = 100; !pass && maxiter < 10000; maxiter *= 2, cubic_case = (cubic_case + 1) % 2)
|
||||
{
|
||||
for (int j = 0; j < n + 1; ++j)
|
||||
a[j] = c[j].real();
|
||||
|
||||
CvMat amat, umat;
|
||||
cvInitMatHeader(&amat, n + 1, 1, CV_64FC1, &a[0]);
|
||||
cvInitMatHeader(&umat, n, 1, CV_64FC2, &u[0]);
|
||||
cvSolvePoly(&amat, &umat, maxiter, fig);
|
||||
|
||||
for (int j = 0; j < n; ++j)
|
||||
ar[j] = complex_type(u[j * 2], u[j * 2 + 1]);
|
||||
|
||||
std::sort(r.begin(), r.end(), pred_complex());
|
||||
std::sort(ar.begin(), ar.end(), pred_complex());
|
||||
|
||||
pass = true;
|
||||
if( n == 3 )
|
||||
{
|
||||
ar2.resize(n);
|
||||
cv::Mat _umat2(3, 1, CV_64F, &ar2[0]), umat2 = _umat2;
|
||||
cvFlip(&amat, &amat, 0);
|
||||
int nr2;
|
||||
if( cubic_case == 0 )
|
||||
nr2 = cv::solveCubic(cv::Mat(&amat),umat2);
|
||||
else
|
||||
nr2 = cv::solveCubic(cv::Mat_<float>(cv::Mat(&amat)), umat2);
|
||||
cvFlip(&amat, &amat, 0);
|
||||
if(nr2 > 0)
|
||||
std::sort(ar2.begin(), ar2.begin()+nr2, pred_double());
|
||||
ar2.resize(nr2);
|
||||
|
||||
int nr1 = 0;
|
||||
for(int j = 0; j < n; j++)
|
||||
if( fabs(r[j].imag()) < DBL_EPSILON )
|
||||
ar1[nr1++] = r[j].real();
|
||||
|
||||
pass = pass && nr1 == nr2;
|
||||
if( nr2 > 0 )
|
||||
{
|
||||
div = s = 0;
|
||||
for(int j = 0; j < nr1; j++)
|
||||
{
|
||||
s += fabs(ar1[j]);
|
||||
div += fabs(ar1[j] - ar2[j]);
|
||||
}
|
||||
div /= s;
|
||||
pass = pass && div < err_eps;
|
||||
}
|
||||
}
|
||||
|
||||
div = s = 0;
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
s += fabs(r[j].real()) + fabs(r[j].imag());
|
||||
div += sqrt(pow(r[j].real() - ar[j].real(), 2) + pow(r[j].imag() - ar[j].imag(), 2));
|
||||
}
|
||||
div /= s;
|
||||
pass = pass && div < err_eps;
|
||||
}
|
||||
|
||||
if (!pass)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ts->printf( CvTS::LOG, "too big diff = %g\n", div );
|
||||
|
||||
for (size_t j=0;j<ar2.size();++j)
|
||||
ts->printf( CvTS::LOG, "ar2[%d]=%g\n", j, ar2[j]);
|
||||
ts->printf(CvTS::LOG, "\n");
|
||||
|
||||
for (size_t j=0;j<r.size();++j)
|
||||
ts->printf( CvTS::LOG, "r[%d]=(%g, %g)\n", j, r[j].real(), r[j].imag());
|
||||
ts->printf( CvTS::LOG, "\n" );
|
||||
for (size_t j=0;j<ar.size();++j)
|
||||
ts->printf( CvTS::LOG, "ar[%d]=(%g, %g)\n", j, ar[j].real(), ar[j].imag());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CV_SolvePolyTest solve_poly_test;
|
||||
@@ -1,68 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
#ifndef _CXCORE_TEST_H_
|
||||
#define _CXCORE_TEST_H_
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include "cxts.h"
|
||||
|
||||
/****************************************************************************************/
|
||||
/* Warnings Disabling */
|
||||
/****************************************************************************************/
|
||||
#if _MSC_VER > 1000
|
||||
#pragma warning(disable : 4514) /* unreferenced inline function has been */
|
||||
/* removed */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant */
|
||||
/* for no warnings in _ASSERT */
|
||||
#pragma warning(disable : 4996) /* deprecated function */
|
||||
#endif
|
||||
|
||||
#endif /* _CXCORE_TEST_H_ */
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,61 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
|
||||
CvTS test_system("core");
|
||||
|
||||
const char* blacklist[] =
|
||||
{
|
||||
//"matrix-dotproduct", //ticket 447
|
||||
//"ds-graphscan", //ticket 504
|
||||
//"matrix-invert", //ticket 536
|
||||
//"pca", //ticket 566
|
||||
//"rand", //ticket 449
|
||||
0
|
||||
};
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
return test_system.run( argc, argv, blacklist );
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
@@ -1,164 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_MatrOpTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_MatrOpTest();
|
||||
~CV_MatrOpTest();
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool TestMat();
|
||||
bool TestMatND();
|
||||
bool TestSparseMat();
|
||||
|
||||
|
||||
bool checkMatSetError(const Mat& m1, const Mat& m2);
|
||||
};
|
||||
|
||||
CV_MatrOpTest::CV_MatrOpTest(): CvTest( "matrix-operations", "?" )
|
||||
{
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
|
||||
}
|
||||
CV_MatrOpTest::~CV_MatrOpTest() {}
|
||||
|
||||
bool CV_MatrOpTest::checkMatSetError(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
if (norm(m1, m2, NORM_INF) == 0)
|
||||
return true;
|
||||
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CV_MatrOpTest::TestMat()
|
||||
{
|
||||
Mat one_3x1(3, 1, CV_32F, Scalar(1.0));
|
||||
Mat shi_3x1(3, 1, CV_32F, Scalar(1.2));
|
||||
Mat shi_2x1(2, 1, CV_32F, Scalar(-1));
|
||||
Scalar shift = Scalar::all(15);
|
||||
|
||||
float data[] = { sqrt(2.f)/2, -sqrt(2.f)/2, 1.f, sqrt(2.f)/2, sqrt(2.f)/2, 10.f };
|
||||
Mat rot_2x3(2, 3, CV_32F, data);
|
||||
|
||||
Mat res = rot_2x3 * (one_3x1 + shi_3x1 + shi_3x1 + shi_3x1) - shi_2x1 + shift;
|
||||
|
||||
Mat tmp, res2;
|
||||
add(one_3x1, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
add(tmp, shi_3x1, tmp);
|
||||
gemm(rot_2x3, tmp, 1, shi_2x1, -1, res2, 0);
|
||||
add(res2, Mat(2, 1, CV_32F, shift), res2);
|
||||
|
||||
if (!checkMatSetError(res, res2))
|
||||
return false;
|
||||
|
||||
Mat mat4x4(4, 4, CV_32F);
|
||||
randu(mat4x4, Scalar(0), Scalar(10));
|
||||
|
||||
Mat roi1 = mat4x4(Rect(Point(1, 1), Size(2, 2)));
|
||||
Mat roi2 = mat4x4(Range(1, 3), Range(1, 3));
|
||||
|
||||
if (!checkMatSetError(roi1, roi2))
|
||||
return false;
|
||||
|
||||
if (!checkMatSetError(mat4x4, mat4x4(Rect(Point(0,0), mat4x4.size()))))
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_MatrOpTest::TestMatND()
|
||||
{
|
||||
int sizes[] = { 3, 3, 3};
|
||||
cv::MatND nd(3, sizes, CV_32F);
|
||||
|
||||
/* MatND res = nd * nd + nd;
|
||||
MatND res2;
|
||||
cv::gemm(nd, nd, 1, nd, 1, res2);
|
||||
|
||||
if (!checkMatSetError(res1, res2))
|
||||
return false;*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_MatrOpTest::TestSparseMat()
|
||||
{
|
||||
int sizes[] = { 10, 10, 10};
|
||||
SparseMat mat(sizeof(sizes)/sizeof(sizes[0]), sizes, CV_32F);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CV_MatrOpTest::run( int /* start_from */)
|
||||
{
|
||||
if (!TestMat())
|
||||
return;
|
||||
|
||||
if (!TestMatND())
|
||||
return;
|
||||
|
||||
if (!TestSparseMat())
|
||||
return;
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
CV_MatrOpTest cv_MatrOp_test;
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*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 "cxcoretest.h"
|
||||
@@ -1,69 +0,0 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for cxts. See root CMakeLists.txt
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
project(opencv_ts)
|
||||
|
||||
file(GLOB lib_srcs "*.cpp")
|
||||
source_group("Src" FILES ${lib_srcs})
|
||||
file(GLOB lib_hdrs "*.h*")
|
||||
source_group("Include" FILES ${lib_hdrs})
|
||||
|
||||
include_directories(.
|
||||
"${CMAKE_SOURCE_DIR}/modules/core/include")
|
||||
|
||||
if(WIN32 AND MSVC)
|
||||
set(pch_header "_cxts.h")
|
||||
set(pch_src "precomp.cpp")
|
||||
list(REMOVE_ITEM lib_srcs ${CMAKE_CURRENT_SOURCE_DIR}/${pch_src})
|
||||
set(lib_srcs ${CMAKE_CURRENT_SOURCE_DIR}/${pch_src} ${lib_srcs})
|
||||
foreach(src_file ${lib_srcs})
|
||||
if(${src_file} MATCHES ${pch_src})
|
||||
set_source_files_properties(
|
||||
${src_file}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "/Yc${pch_header}"
|
||||
)
|
||||
else()
|
||||
set_source_files_properties(
|
||||
${src_file}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "/Yu${pch_header}"
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
set(the_target "opencv_ts")
|
||||
|
||||
add_library(${the_target} ${lib_srcs} ${lib_hdrs})
|
||||
|
||||
# For dynamic link numbering convenions
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
VERSION ${OPENCV_VERSION}
|
||||
SOVERSION ${OPENCV_SOVERSION}
|
||||
OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}"
|
||||
)
|
||||
|
||||
# Additional target properties
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||
DEFINE_SYMBOL "CVAPI_EXPORTS"
|
||||
)
|
||||
|
||||
add_dependencies(${the_target} opencv_core)
|
||||
|
||||
# Add the required libraries for linking:
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core)
|
||||
|
||||
if(WIN32)
|
||||
install(TARGETS ${the_target}
|
||||
RUNTIME DESTINATION bin COMPONENT main
|
||||
LIBRARY DESTINATION lib COMPONENT main
|
||||
ARCHIVE DESTINATION lib COMPONENT main)
|
||||
endif()
|
||||
@@ -1,60 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
#ifndef __CXTS_INTERNAL_H__
|
||||
#define __CXTS_INTERNAL_H__
|
||||
|
||||
#if (defined WIN32 || defined _WIN32) && (_MSC_VER >= 1200 || defined _ICL)
|
||||
#pragma warning( disable: 4251 4514 4996 )
|
||||
#endif
|
||||
|
||||
#include "cxts.h"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#endif/*__CXTS_INTERNAL_H__*/
|
||||
|
||||
2182
tests/cxts/cxts.cpp
2182
tests/cxts/cxts.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,837 +0,0 @@
|
||||
/*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*/
|
||||
|
||||
#ifndef __CXTS_H__
|
||||
#define __CXTS_H__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4710 )
|
||||
#endif
|
||||
|
||||
#define CV_TS_VERSION "CxTest 0.1"
|
||||
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
#define __END__ __CV_END__
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
// Helper class for growing vector (to avoid dependency from STL)
|
||||
template < typename T > class CvTestVec
|
||||
{
|
||||
public:
|
||||
CvTestVec() { _max_size = _size = 0; _buf = 0; }
|
||||
~CvTestVec() { delete[] _buf; }
|
||||
T& operator []( int i ) { assert( (unsigned)i < (unsigned)_size ); return _buf[i]; }
|
||||
T at( int i ) { assert( (unsigned)i < (unsigned)_size ); return _buf[i]; }
|
||||
T pop() { assert( _size > 0 ); return _buf[--_size]; }
|
||||
void push( const T& elem )
|
||||
{
|
||||
if( _size >= _max_size )
|
||||
{
|
||||
int i, _new_size = _max_size < 16 ? 16 : _max_size*3/2;
|
||||
T* temp = new T[_new_size];
|
||||
for( i = 0; i < _size; i++ )
|
||||
temp[i] = _buf[i];
|
||||
delete[] _buf;
|
||||
_max_size = _new_size;
|
||||
_buf = temp;
|
||||
}
|
||||
_buf[_size++] = elem;
|
||||
}
|
||||
|
||||
int size() { return _size; }
|
||||
T* data() { return _buf; }
|
||||
void clear() { _size = 0; }
|
||||
|
||||
protected:
|
||||
T* _buf;
|
||||
int _size, _max_size;
|
||||
};
|
||||
|
||||
/*****************************************************************************************\
|
||||
* Base class for tests *
|
||||
\*****************************************************************************************/
|
||||
|
||||
class CvTest;
|
||||
class CvTS;
|
||||
|
||||
class CV_EXPORTS CvTest
|
||||
{
|
||||
public:
|
||||
// constructor(s) and destructor
|
||||
CvTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
|
||||
virtual ~CvTest();
|
||||
|
||||
virtual int init( CvTS* system );
|
||||
|
||||
// writes default parameters to file storage
|
||||
virtual int write_defaults(CvTS* ts);
|
||||
|
||||
// the main procedure of the test
|
||||
virtual void run( int start_from );
|
||||
|
||||
// the wrapper for run that cares of exceptions
|
||||
virtual void safe_run( int start_from );
|
||||
|
||||
const char* get_name() const { return name; }
|
||||
const char* get_func_list() const { return tested_functions; }
|
||||
const char* get_description() const { return description; }
|
||||
const char* get_group_name( char* buffer ) const;
|
||||
CvTest* get_next() { return next; }
|
||||
static CvTest* get_first_test();
|
||||
static const char* get_parent_name( const char* name, char* buffer );
|
||||
|
||||
// returns true if and only if the different test cases do not depend on each other
|
||||
// (so that test system could get right to a problematic test case)
|
||||
virtual bool can_do_fast_forward();
|
||||
|
||||
// deallocates all the memory.
|
||||
// called by init() (before initialization) and by the destructor
|
||||
virtual void clear();
|
||||
|
||||
// returns the testing modes supported by the particular test
|
||||
int get_support_testing_modes();
|
||||
|
||||
enum { TIMING_EXTRA_PARAMS=5 };
|
||||
|
||||
protected:
|
||||
static CvTest* first;
|
||||
static CvTest* last;
|
||||
static int test_count;
|
||||
CvTest* next;
|
||||
|
||||
const char** default_timing_param_names; // the names of timing parameters to write
|
||||
const CvFileNode* timing_param_names; // and the read param names
|
||||
const CvFileNode** timing_param_current; // the current tuple of timing parameters
|
||||
const CvFileNode** timing_param_seqs; // the array of parameter sequences
|
||||
int* timing_param_idxs; // the array of indices
|
||||
int timing_param_count; // the number of parameters in the tuple
|
||||
int support_testing_modes;
|
||||
|
||||
int test_case_count; // the total number of test cases
|
||||
|
||||
// called from write_defaults
|
||||
virtual int write_default_params(CvFileStorage* fs);
|
||||
|
||||
// read test params
|
||||
virtual int read_params( CvFileStorage* fs );
|
||||
|
||||
// returns the number of tests or -1 if it is unknown a-priori
|
||||
virtual int get_test_case_count();
|
||||
|
||||
// prepares data for the next test case. rng seed is updated by the function
|
||||
virtual int prepare_test_case( int test_case_idx );
|
||||
|
||||
// checks if the test output is valid and accurate
|
||||
virtual int validate_test_results( int test_case_idx );
|
||||
|
||||
// calls the tested function. the method is called from run_test_case()
|
||||
virtual void run_func(); // runs tested func(s)
|
||||
|
||||
// prints results of timing test
|
||||
virtual void print_time( int test_case_idx, double time_usecs, double time_cpu_clocks );
|
||||
|
||||
// updates progress bar
|
||||
virtual int update_progress( int progress, int test_case_idx, int count, double dt );
|
||||
|
||||
// finds test parameter
|
||||
const CvFileNode* find_param( CvFileStorage* fs, const char* param_name );
|
||||
|
||||
// writes parameters
|
||||
void write_param( CvFileStorage* fs, const char* paramname, int val );
|
||||
void write_param( CvFileStorage* fs, const char* paramname, double val );
|
||||
void write_param( CvFileStorage* fs, const char* paramname, const char* val );
|
||||
void write_string_list( CvFileStorage* fs, const char* paramname, const char** val, int count=-1 );
|
||||
void write_int_list( CvFileStorage* fs, const char* paramname, const int* val,
|
||||
int count, int stop_value=INT_MIN );
|
||||
void write_real_list( CvFileStorage* fs, const char* paramname, const double* val,
|
||||
int count, double stop_value=DBL_MIN );
|
||||
void start_write_param( CvFileStorage* fs );
|
||||
|
||||
// returns the specified parameter from the current parameter tuple
|
||||
const CvFileNode* find_timing_param( const char* paramname );
|
||||
|
||||
// gets the next tuple of timing parameters
|
||||
int get_next_timing_param_tuple();
|
||||
|
||||
// name of the test (it is possible to locate a test by its name)
|
||||
const char* name;
|
||||
|
||||
// comma-separated list of functions that are invoked
|
||||
// (and, thus, tested explicitly or implicitly) by the test
|
||||
// methods of classes can be grouped using {}.
|
||||
// a few examples:
|
||||
// "cvCanny, cvAdd, cvSub, cvMul"
|
||||
// "CvImage::{Create, CopyOf}, cvMatMulAdd, CvCalibFilter::{PushFrame, SetCameraCount}"
|
||||
const char* tested_functions;
|
||||
|
||||
// description of the test
|
||||
const char* description;
|
||||
|
||||
// pointer to the system that includes the test
|
||||
CvTS* ts;
|
||||
|
||||
int hdr_state;
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************************\
|
||||
* Information about a failed test *
|
||||
\*****************************************************************************************/
|
||||
|
||||
typedef struct CvTestInfo
|
||||
{
|
||||
// pointer to the test
|
||||
CvTest* test;
|
||||
|
||||
// failure code (CV_FAIL*)
|
||||
int code;
|
||||
|
||||
// seed value right before the data for the failed test case is prepared.
|
||||
uint64 rng_seed;
|
||||
|
||||
// seed value right before running the test
|
||||
uint64 rng_seed0;
|
||||
|
||||
// index of test case, can be then passed to CvTest::proceed_to_test_case()
|
||||
int test_case_idx;
|
||||
|
||||
// index of the corrupted or leaked block
|
||||
int alloc_index;
|
||||
|
||||
// index of the first block in the group
|
||||
// (used to adjust alloc_index when some test/test cases are skipped).
|
||||
int base_alloc_index;
|
||||
}
|
||||
CvTestInfo;
|
||||
|
||||
/*****************************************************************************************\
|
||||
* Base Class for test system *
|
||||
\*****************************************************************************************/
|
||||
|
||||
class CvTestMemoryManager;
|
||||
|
||||
typedef CvTestVec<int> CvTestIntVec;
|
||||
typedef CvTestVec<void*> CvTestPtrVec;
|
||||
typedef CvTestVec<CvTestInfo> CvTestInfoVec;
|
||||
|
||||
class CV_EXPORTS CvTS
|
||||
{
|
||||
public:
|
||||
|
||||
// constructor(s) and destructor
|
||||
CvTS(const char* _module_name=0);
|
||||
virtual ~CvTS();
|
||||
|
||||
enum
|
||||
{
|
||||
NUL=0,
|
||||
SUMMARY_IDX=0,
|
||||
SUMMARY=1 << SUMMARY_IDX,
|
||||
LOG_IDX=1,
|
||||
LOG=1 << LOG_IDX,
|
||||
CSV_IDX=2,
|
||||
CSV=1 << CSV_IDX,
|
||||
CONSOLE_IDX=3,
|
||||
CONSOLE=1 << CONSOLE_IDX,
|
||||
MAX_IDX=4
|
||||
};
|
||||
|
||||
// low-level printing functions that are used by individual tests and by the system itself
|
||||
virtual void printf( int streams, const char* fmt, ... );
|
||||
virtual void vprintf( int streams, const char* fmt, va_list arglist );
|
||||
|
||||
// runs the tests (the whole set or some selected tests)
|
||||
virtual int run( int argc, char** argv, const char** blacklist=0 );
|
||||
|
||||
// updates the context: current test, test case, rng state
|
||||
virtual void update_context( CvTest* test, int test_case_idx, bool update_ts_context );
|
||||
|
||||
const CvTestInfo* get_current_test_info() { return ¤t_test_info; }
|
||||
|
||||
// sets information about a failed test
|
||||
virtual void set_failed_test_info( int fail_code, int alloc_index = -1 );
|
||||
|
||||
// types of tests
|
||||
enum
|
||||
{
|
||||
CORRECTNESS_CHECK_MODE = 1,
|
||||
TIMING_MODE = 2
|
||||
};
|
||||
|
||||
// the modes of timing tests:
|
||||
enum { AVG_TIME = 1, MIN_TIME = 2 };
|
||||
|
||||
// test error codes
|
||||
enum
|
||||
{
|
||||
// everything is Ok
|
||||
OK=0,
|
||||
|
||||
// generic error: stub value to be used
|
||||
// temporarily if the error's cause is unknown
|
||||
FAIL_GENERIC=-1,
|
||||
|
||||
// the test is missing some essential data to proceed further
|
||||
FAIL_MISSING_TEST_DATA=-2,
|
||||
|
||||
// the tested function raised an error via cxcore error handler
|
||||
FAIL_ERROR_IN_CALLED_FUNC=-3,
|
||||
|
||||
// an exception has been raised;
|
||||
// for memory and arithmetic exception
|
||||
// there are two specialized codes (see below...)
|
||||
FAIL_EXCEPTION=-4,
|
||||
|
||||
// a memory exception
|
||||
// (access violation, access to missed page, stack overflow etc.)
|
||||
FAIL_MEMORY_EXCEPTION=-5,
|
||||
|
||||
// arithmetic exception (overflow, division by zero etc.)
|
||||
FAIL_ARITHM_EXCEPTION=-6,
|
||||
|
||||
// the tested function corrupted memory (no exception have been raised)
|
||||
FAIL_MEMORY_CORRUPTION_BEGIN=-7,
|
||||
FAIL_MEMORY_CORRUPTION_END=-8,
|
||||
|
||||
// the tested function (or test ifself) do not deallocate some memory
|
||||
FAIL_MEMORY_LEAK=-9,
|
||||
|
||||
// the tested function returned invalid object, e.g. matrix, containing NaNs,
|
||||
// structure with NULL or out-of-range fields (while it should not)
|
||||
FAIL_INVALID_OUTPUT=-10,
|
||||
|
||||
// the tested function returned valid object, but it does not match to
|
||||
// the original (or produced by the test) object
|
||||
FAIL_MISMATCH=-11,
|
||||
|
||||
// the tested function returned valid object (a single number or numerical array),
|
||||
// but it differs too much from the original (or produced by the test) object
|
||||
FAIL_BAD_ACCURACY=-12,
|
||||
|
||||
// the tested function hung. Sometimes, can be determined by unexpectedly long
|
||||
// processing time (in this case there should be possibility to interrupt such a function
|
||||
FAIL_HANG=-13,
|
||||
|
||||
// unexpected responce on passing bad arguments to the tested function
|
||||
// (the function crashed, proceed succesfully (while it should not), or returned
|
||||
// error code that is different from what is expected)
|
||||
FAIL_BAD_ARG_CHECK=-14,
|
||||
|
||||
// the test data (in whole or for the particular test case) is invalid
|
||||
FAIL_INVALID_TEST_DATA=-15,
|
||||
|
||||
// the test has been skipped because it is not in the selected subset of the tests to run,
|
||||
// because it has been run already within the same run with the same parameters, or because
|
||||
// of some other reason and this is not considered as an error.
|
||||
// Normally CvTS::run() (or overrided method in the derived class) takes care of what
|
||||
// needs to be run, so this code should not occur.
|
||||
SKIPPED=1
|
||||
};
|
||||
|
||||
// get file storage
|
||||
CvFileStorage* get_file_storage() { return fs; }
|
||||
|
||||
// get RNG to generate random input data for a test
|
||||
CvRNG* get_rng() { return &rng; }
|
||||
|
||||
// returns the current error code
|
||||
int get_err_code() { return current_test_info.code; }
|
||||
|
||||
// retrieves the first registered test
|
||||
CvTest* get_first_test() { return CvTest::get_first_test(); }
|
||||
|
||||
// retrieves one of global options of the test system
|
||||
int is_debug_mode() { return params.debug_mode; }
|
||||
|
||||
// returns the current testing mode
|
||||
int get_testing_mode() { return params.test_mode; }
|
||||
|
||||
// returns the current timing mode
|
||||
int get_timing_mode() { return params.timing_mode; }
|
||||
|
||||
// returns the test extensivity scale
|
||||
double get_test_case_count_scale() { return params.test_case_count_scale; }
|
||||
|
||||
int find_written_param( CvTest* test, const char* paramname,
|
||||
int valtype, const void* val );
|
||||
|
||||
const char* get_data_path() { return params.data_path ? params.data_path : ""; }
|
||||
|
||||
protected:
|
||||
// deallocates memory buffers and closes all the streams;
|
||||
// called by init() and from destructor. It does not remove any tests!!!
|
||||
virtual void clear();
|
||||
|
||||
// retrieves information about the test libraries (names, versions, build dates etc.)
|
||||
virtual const char* get_libs_info( const char** loaded_ipp_modules );
|
||||
|
||||
// returns textual description of failure code
|
||||
virtual const char* str_from_code( int code );
|
||||
|
||||
// prints header of summary of test suite run.
|
||||
// It goes before the results of individual tests and contains information about tested libraries
|
||||
// (as reported by get_libs_info()), information about test environment (CPU, test machine name),
|
||||
// date and time etc.
|
||||
virtual void print_summary_header( int streams );
|
||||
|
||||
// prints tailer of summary of test suite run.
|
||||
// it goes after the results of individual tests and contains the number of
|
||||
// failed tests, total running time, exit code (whether the system has been crashed,
|
||||
// interrupted by the user etc.), names of files with additional information etc.
|
||||
virtual void print_summary_tailer( int streams );
|
||||
|
||||
// reads common parameters of the test system; called from init()
|
||||
virtual int read_params( CvFileStorage* fs );
|
||||
|
||||
// checks, whether the test needs to be run (1) or not (0); called from run()
|
||||
virtual int filter( CvTest* test, int& filter_state, const char** blacklist=0 );
|
||||
|
||||
// makes base name of output files
|
||||
virtual void make_output_stream_base_name( const char* config_name );
|
||||
|
||||
// forms default test configuration file that can be
|
||||
// customized further
|
||||
virtual void write_default_params( CvFileStorage* fs );
|
||||
|
||||
// enables/disables the specific output stream[s]
|
||||
virtual void enable_output_streams( int streams, int flag );
|
||||
|
||||
// sets memory and exception handlers
|
||||
virtual void set_handlers( bool on );
|
||||
|
||||
// changes the path to test data files
|
||||
virtual void set_data_path( const char* data_path );
|
||||
|
||||
// prints the information about command-line parameters
|
||||
virtual void print_help();
|
||||
|
||||
// changes the text color in console
|
||||
virtual void set_color(int color);
|
||||
|
||||
// a sequence of tests to run
|
||||
CvTestPtrVec* selected_tests;
|
||||
|
||||
// a sequence of written test params
|
||||
CvTestPtrVec* written_params;
|
||||
|
||||
// a sequence of failed tests
|
||||
CvTestInfoVec* failed_tests;
|
||||
|
||||
// base name for output streams
|
||||
char* ostrm_base_name;
|
||||
const char* ostrm_suffixes[MAX_IDX];
|
||||
|
||||
// parameters that can be read from file storage
|
||||
CvFileStorage* fs;
|
||||
|
||||
enum { CHOOSE_TESTS = 0, CHOOSE_FUNCTIONS = 1 };
|
||||
|
||||
// common parameters:
|
||||
struct
|
||||
{
|
||||
// if non-zero, the tests are run in unprotected mode to debug possible crashes,
|
||||
// otherwise the system tries to catch the exceptions and continue with other tests
|
||||
int debug_mode;
|
||||
|
||||
// if > 0, the header is not print
|
||||
int skip_header;
|
||||
|
||||
// if > 0, the blacklist is ignored
|
||||
int ignore_blacklist;
|
||||
|
||||
// if non-zero, the system includes only failed tests into summary
|
||||
bool print_only_failed;
|
||||
|
||||
// rerun failed tests in debug mode
|
||||
bool rerun_failed;
|
||||
|
||||
// if non-zero, the failed tests are rerun immediately
|
||||
bool rerun_immediately;
|
||||
|
||||
// choose_tests or choose_functions;
|
||||
int test_filter_mode;
|
||||
|
||||
// correctness or performance [or bad-arg, stress etc.]
|
||||
int test_mode;
|
||||
|
||||
// timing mode
|
||||
int timing_mode;
|
||||
|
||||
// pattern for choosing tests
|
||||
const char* test_filter_pattern;
|
||||
|
||||
// RNG seed, passed to and updated by every test executed.
|
||||
uint64 rng_seed;
|
||||
|
||||
// relative or absolute path of directory containing subfolders with test data
|
||||
const char* resource_path;
|
||||
|
||||
// whether to use IPP, MKL etc. or not
|
||||
int use_optimized;
|
||||
|
||||
// extensivity of the tests, scale factor for test_case_count
|
||||
double test_case_count_scale;
|
||||
|
||||
// the path to data files used by tests
|
||||
char* data_path;
|
||||
|
||||
// whether the output to console should be colored
|
||||
int color_terminal;
|
||||
}
|
||||
params;
|
||||
|
||||
// these are allocated within a test to try keep them valid in case of stack corruption
|
||||
CvRNG rng;
|
||||
|
||||
// test system start time
|
||||
time_t start_time;
|
||||
|
||||
// test system version (=CV_TS_VERSION by default)
|
||||
const char* version;
|
||||
|
||||
// name of config file
|
||||
const char* config_name;
|
||||
|
||||
const char* module_name;
|
||||
|
||||
// information about the current test
|
||||
CvTestInfo current_test_info;
|
||||
|
||||
// memory manager used to detect memory corruptions and leaks
|
||||
CvTestMemoryManager* memory_manager;
|
||||
|
||||
// output streams
|
||||
struct StreamInfo
|
||||
{
|
||||
FILE* f;
|
||||
//const char* filename;
|
||||
int default_handle; // for stderr
|
||||
int enable;
|
||||
};
|
||||
|
||||
StreamInfo output_streams[MAX_IDX];
|
||||
int ostream_testname_mask;
|
||||
std::string logbuf;
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************************\
|
||||
* Subclass of CvTest for testing functions that process dense arrays *
|
||||
\*****************************************************************************************/
|
||||
|
||||
class CV_EXPORTS CvArrTest : public CvTest
|
||||
{
|
||||
public:
|
||||
// constructor(s) and destructor
|
||||
CvArrTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
|
||||
virtual ~CvArrTest();
|
||||
|
||||
virtual int write_default_params( CvFileStorage* fs );
|
||||
virtual void clear();
|
||||
|
||||
protected:
|
||||
|
||||
virtual int read_params( CvFileStorage* fs );
|
||||
virtual int prepare_test_case( int test_case_idx );
|
||||
virtual int validate_test_results( int test_case_idx );
|
||||
|
||||
virtual void prepare_to_validation( int test_case_idx );
|
||||
virtual void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
|
||||
virtual void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
virtual void fill_array( int test_case_idx, int i, int j, CvMat* arr );
|
||||
virtual void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
|
||||
virtual double get_success_error_level( int test_case_idx, int i, int j );
|
||||
virtual void print_time( int test_case_idx, double time_usecs, double time_cpu_clocks );
|
||||
virtual void print_timing_params( int test_case_idx, char* ptr, int params_left=TIMING_EXTRA_PARAMS );
|
||||
|
||||
bool cvmat_allowed;
|
||||
bool iplimage_allowed;
|
||||
bool optional_mask;
|
||||
bool element_wise_relative_error;
|
||||
|
||||
int min_log_array_size;
|
||||
int max_log_array_size;
|
||||
|
||||
int max_arr; // = MAX_ARR by default, the number of different types of arrays
|
||||
int max_hdr; // size of header buffer
|
||||
enum { INPUT, INPUT_OUTPUT, OUTPUT, REF_INPUT_OUTPUT, REF_OUTPUT, TEMP, MASK, MAX_ARR };
|
||||
|
||||
const CvSize* size_list;
|
||||
const CvSize* whole_size_list;
|
||||
const int* depth_list;
|
||||
const int* cn_list;
|
||||
|
||||
CvTestPtrVec* test_array;
|
||||
CvMat* test_mat[MAX_ARR];
|
||||
CvMat* hdr;
|
||||
float buf[4];
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS CvBadArgTest : public CvTest
|
||||
{
|
||||
public:
|
||||
// constructor(s) and destructor
|
||||
CvBadArgTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
|
||||
virtual ~CvBadArgTest();
|
||||
|
||||
protected:
|
||||
virtual int run_test_case( int expected_code, const char* descr );
|
||||
virtual void run_func(void) = 0;
|
||||
int test_case_idx;
|
||||
int progress;
|
||||
double t, freq;
|
||||
|
||||
template<class F>
|
||||
int run_test_case( int expected_code, const char* descr, F f)
|
||||
{
|
||||
double new_t = (double)cv::getTickCount(), dt;
|
||||
if( test_case_idx < 0 )
|
||||
{
|
||||
test_case_idx = 0;
|
||||
progress = 0;
|
||||
dt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = (new_t - t)/(freq*1000);
|
||||
t = new_t;
|
||||
}
|
||||
progress = update_progress(progress, test_case_idx, 0, dt);
|
||||
|
||||
int errcount = 0;
|
||||
bool thrown = false;
|
||||
if(!descr)
|
||||
descr = "";
|
||||
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
thrown = true;
|
||||
if( e.code != expected_code )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
|
||||
descr, test_case_idx, e.code, expected_code);
|
||||
errcount = 1;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
thrown = true;
|
||||
ts->printf(CvTS::LOG, "%s (test case #%d): unknown exception was thrown (the function has likely crashed)\n",
|
||||
descr, test_case_idx);
|
||||
errcount = 1;
|
||||
}
|
||||
if(!thrown)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "%s (test case #%d): no expected exception was thrown\n",
|
||||
descr, test_case_idx);
|
||||
errcount = 1;
|
||||
}
|
||||
test_case_idx++;
|
||||
|
||||
return errcount;
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************\
|
||||
* Utility Functions *
|
||||
\****************************************************************************************/
|
||||
|
||||
CV_EXPORTS const char* cvTsGetTypeName( int type );
|
||||
CV_EXPORTS int cvTsTypeByName( const char* type_name );
|
||||
|
||||
inline int cvTsClipInt( int val, int min_val, int max_val )
|
||||
{
|
||||
if( val < min_val )
|
||||
val = min_val;
|
||||
if( val > max_val )
|
||||
val = max_val;
|
||||
return val;
|
||||
}
|
||||
|
||||
// return min & max values for given type, e.g. for CV_8S ~ -128 and 127, respectively.
|
||||
CV_EXPORTS double cvTsMinVal( int type );
|
||||
CV_EXPORTS double cvTsMaxVal( int type );
|
||||
|
||||
// returns c-norm of the array
|
||||
CV_EXPORTS double cvTsMaxVal( const CvMat* arr );
|
||||
|
||||
inline CvMat* cvTsGetMat( const CvMat* arr, CvMat* stub, int* coi=0 )
|
||||
{
|
||||
return cvGetMat( arr, stub, coi );
|
||||
}
|
||||
|
||||
// fills array with random numbers
|
||||
CV_EXPORTS void cvTsRandUni( CvRNG* rng, CvMat* a, CvScalar param1, CvScalar param2 );
|
||||
|
||||
inline unsigned cvTsRandInt( CvRNG* rng )
|
||||
{
|
||||
uint64 temp = *rng;
|
||||
temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);
|
||||
*rng = temp;
|
||||
return (unsigned)temp;
|
||||
}
|
||||
|
||||
inline double cvTsRandReal( CvRNG* rng )
|
||||
{
|
||||
return cvTsRandInt( rng ) * 2.3283064365386962890625e-10 /* 2^-32 */;
|
||||
}
|
||||
|
||||
// fills c with zeros
|
||||
CV_EXPORTS void cvTsZero( CvMat* c, const CvMat* mask=0 );
|
||||
|
||||
// initializes scaled identity matrix
|
||||
CV_EXPORTS void cvTsSetIdentity( CvMat* c, CvScalar diag_value );
|
||||
|
||||
// copies a to b (whole matrix or only the selected region)
|
||||
CV_EXPORTS void cvTsCopy( const CvMat* a, CvMat* b, const CvMat* mask=0 );
|
||||
|
||||
// converts one array to another
|
||||
CV_EXPORTS void cvTsConvert( const CvMat* src, CvMat* dst );
|
||||
|
||||
// working with multi-channel arrays
|
||||
CV_EXPORTS void cvTsExtract( const CvMat* a, CvMat* plane, int coi );
|
||||
CV_EXPORTS void cvTsInsert( const CvMat* plane, CvMat* a, int coi );
|
||||
|
||||
// c = alpha*a + beta*b + gamma
|
||||
CV_EXPORTS void cvTsAdd( const CvMat* a, CvScalar alpha, const CvMat* b, CvScalar beta,
|
||||
CvScalar gamma, CvMat* c, int calc_abs );
|
||||
|
||||
// c = a*b*alpha
|
||||
CV_EXPORTS void cvTsMul( const CvMat* _a, const CvMat* _b, CvScalar alpha, CvMat* _c );
|
||||
|
||||
// c = a*alpha/b
|
||||
CV_EXPORTS void cvTsDiv( const CvMat* _a, const CvMat* _b, CvScalar alpha, CvMat* _c );
|
||||
|
||||
enum { CV_TS_MIN = 0, CV_TS_MAX = 1 };
|
||||
|
||||
// min/max
|
||||
CV_EXPORTS void cvTsMinMax( const CvMat* _a, const CvMat* _b, CvMat* _c, int op_type );
|
||||
CV_EXPORTS void cvTsMinMaxS( const CvMat* _a, double scalar, CvMat* _c, int op_type );
|
||||
|
||||
// checks that the array does not have NaNs and/or Infs and all the elements are
|
||||
// within [min_val,max_val). idx is the index of the first "bad" element.
|
||||
CV_EXPORTS int cvTsCheck( const CvMat* data, double min_val, double max_val, CvPoint* idx );
|
||||
|
||||
// compares two arrays. max_diff is the maximum actual difference,
|
||||
// success_err_level is maximum allowed difference, idx is the index of the first
|
||||
// element for which difference is >success_err_level
|
||||
// (or index of element with the maximum difference)
|
||||
CV_EXPORTS int cvTsCmpEps( const CvMat* data, const CvMat* etalon, double* max_diff,
|
||||
double success_err_level, CvPoint* idx,
|
||||
bool element_wise_relative_error );
|
||||
|
||||
// a wrapper for the previous function. in case of error prints the message to log file.
|
||||
CV_EXPORTS int cvTsCmpEps2( CvTS* ts, const CvArr* _a, const CvArr* _b, double success_err_level,
|
||||
bool element_wise_relative_error, const char* desc );
|
||||
|
||||
CV_EXPORTS int cvTsCmpEps2_64f( CvTS* ts, const double* val, const double* ref_val, int len,
|
||||
double eps, const char* param_name );
|
||||
|
||||
// compares two arrays. the result is 8s image that takes values -1, 0, 1
|
||||
CV_EXPORTS void cvTsCmp( const CvMat* a, const CvMat* b, CvMat* result, int cmp_op );
|
||||
|
||||
// compares array and a scalar.
|
||||
CV_EXPORTS void cvTsCmpS( const CvMat* a, double fval, CvMat* result, int cmp_op );
|
||||
|
||||
// retrieves C, L1 or L2 norm of array or its region
|
||||
CV_EXPORTS double cvTsNorm( const CvMat* _arr, const CvMat* _mask, int norm_type, int coi );
|
||||
|
||||
// retrieves mean, standard deviation and the number of nonzero mask pixels
|
||||
CV_EXPORTS int cvTsMeanStdDevNonZero( const CvMat* _arr, const CvMat* _mask,
|
||||
CvScalar* _mean, CvScalar* _stddev, int coi );
|
||||
|
||||
// retrieves global extremums and their positions
|
||||
CV_EXPORTS void cvTsMinMaxLoc( const CvMat* _arr, const CvMat* _mask,
|
||||
double* _minval, double* _maxval,
|
||||
CvPoint* _minidx, CvPoint* _maxidx, int coi );
|
||||
|
||||
enum { CV_TS_LOGIC_AND = 0, CV_TS_LOGIC_OR = 1, CV_TS_LOGIC_XOR = 2, CV_TS_LOGIC_NOT = 3 };
|
||||
|
||||
CV_EXPORTS void cvTsLogic( const CvMat* a, const CvMat* b, CvMat* c, int logic_op );
|
||||
CV_EXPORTS void cvTsLogicS( const CvMat* a, CvScalar s, CvMat* c, int logic_op );
|
||||
|
||||
enum { CV_TS_GEMM_A_T = 1, CV_TS_GEMM_B_T = 2, CV_TS_GEMM_C_T = 4 };
|
||||
|
||||
CV_EXPORTS void cvTsGEMM( const CvMat* a, const CvMat* b, double alpha,
|
||||
const CvMat* c, double beta, CvMat* d, int flags );
|
||||
|
||||
CV_EXPORTS void cvTsConvolve2D( const CvMat* a, CvMat* b, const CvMat* kernel, CvPoint anchor );
|
||||
// op_type == CV_TS_MIN/CV_TS_MAX
|
||||
CV_EXPORTS void cvTsMinMaxFilter( const CvMat* a, CvMat* b,
|
||||
const IplConvKernel* element, int op_type );
|
||||
|
||||
enum { CV_TS_BORDER_REPLICATE=0, CV_TS_BORDER_REFLECT=1, CV_TS_BORDER_FILL=2 };
|
||||
|
||||
CV_EXPORTS void cvTsPrepareToFilter( const CvMat* a, CvMat* b, CvPoint ofs,
|
||||
int border_mode = CV_TS_BORDER_REPLICATE,
|
||||
CvScalar fill_val=cvScalarAll(0));
|
||||
|
||||
CV_EXPORTS double cvTsCrossCorr( const CvMat* a, const CvMat* b );
|
||||
|
||||
CV_EXPORTS CvMat* cvTsSelect( const CvMat* a, CvMat* header, CvRect rect );
|
||||
|
||||
CV_EXPORTS CvMat* cvTsTranspose( const CvMat* a, CvMat* b );
|
||||
CV_EXPORTS void cvTsFlip( const CvMat* a, CvMat* b, int flip_type );
|
||||
|
||||
CV_EXPORTS void cvTsTransform( const CvMat* a, CvMat* b, const CvMat* transmat, const CvMat* shift );
|
||||
|
||||
// modifies values that are close to zero
|
||||
CV_EXPORTS void cvTsPatchZeros( CvMat* mat, double level );
|
||||
|
||||
#endif/*__CXTS_H__*/
|
||||
|
||||
@@ -1,691 +0,0 @@
|
||||
/*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 "_cxts.h"
|
||||
|
||||
static const int default_test_case_count = 500;
|
||||
static const int default_max_log_array_size = 9;
|
||||
|
||||
CvArrTest::CvArrTest( const char* _test_name, const char* _test_funcs, const char* _test_descr ) :
|
||||
CvTest( _test_name, _test_funcs, _test_descr )
|
||||
{
|
||||
test_case_count = default_test_case_count;
|
||||
|
||||
iplimage_allowed = true;
|
||||
cvmat_allowed = true;
|
||||
optional_mask = false;
|
||||
min_log_array_size = 0;
|
||||
max_log_array_size = default_max_log_array_size;
|
||||
element_wise_relative_error = true;
|
||||
|
||||
size_list = 0;
|
||||
whole_size_list = 0;
|
||||
depth_list = 0;
|
||||
cn_list = 0;
|
||||
|
||||
max_arr = MAX_ARR;
|
||||
test_array = new CvTestPtrVec[max_arr];
|
||||
max_hdr = 0;
|
||||
hdr = 0;
|
||||
|
||||
support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE + CvTS::TIMING_MODE;
|
||||
}
|
||||
|
||||
|
||||
CvArrTest::~CvArrTest()
|
||||
{
|
||||
clear();
|
||||
delete[] test_array;
|
||||
test_array = 0;
|
||||
}
|
||||
|
||||
|
||||
int CvArrTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvTest::write_default_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
write_param( fs, "min_log_array_size", min_log_array_size );
|
||||
write_param( fs, "max_log_array_size", max_log_array_size );
|
||||
}
|
||||
else if( ts->get_testing_mode() == CvTS::TIMING_MODE )
|
||||
{
|
||||
int i;
|
||||
|
||||
start_write_param( fs ); // make sure we have written the entry header containing the test name
|
||||
if( size_list )
|
||||
{
|
||||
cvStartWriteStruct( fs, "size", CV_NODE_SEQ+CV_NODE_FLOW );
|
||||
for( i = 0; size_list[i].width >= 0; i++ )
|
||||
{
|
||||
cvStartWriteStruct( fs, 0, CV_NODE_SEQ+CV_NODE_FLOW );
|
||||
cvWriteInt( fs, 0, size_list[i].width );
|
||||
cvWriteInt( fs, 0, size_list[i].height );
|
||||
if( whole_size_list &&
|
||||
(whole_size_list[i].width > size_list[i].width ||
|
||||
whole_size_list[i].height > size_list[i].height) )
|
||||
{
|
||||
cvWriteInt( fs, 0, whole_size_list[i].width );
|
||||
cvWriteInt( fs, 0, whole_size_list[i].height );
|
||||
}
|
||||
cvEndWriteStruct( fs );
|
||||
}
|
||||
cvEndWriteStruct(fs);
|
||||
}
|
||||
|
||||
if( depth_list )
|
||||
{
|
||||
cvStartWriteStruct( fs, "depth", CV_NODE_SEQ+CV_NODE_FLOW );
|
||||
for( i = 0; depth_list[i] >= 0; i++ )
|
||||
cvWriteString( fs, 0, cvTsGetTypeName(depth_list[i]) );
|
||||
cvEndWriteStruct(fs);
|
||||
}
|
||||
|
||||
write_int_list( fs, "channels", cn_list, -1, -1 );
|
||||
|
||||
if( optional_mask )
|
||||
{
|
||||
static const int use_mask[] = { 0, 1 };
|
||||
write_int_list( fs, "use_mask", use_mask, 2 );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::clear()
|
||||
{
|
||||
if( test_array )
|
||||
{
|
||||
int i, j, n;
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
n = test_array[i].size();
|
||||
for( j = 0; j < n; j++ )
|
||||
cvRelease( &test_array[i][j] );
|
||||
}
|
||||
}
|
||||
delete[] hdr;
|
||||
hdr = 0;
|
||||
max_hdr = 0;
|
||||
CvTest::clear();
|
||||
}
|
||||
|
||||
|
||||
int CvArrTest::read_params( CvFileStorage* fs )
|
||||
{
|
||||
int code = CvTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE )
|
||||
{
|
||||
min_log_array_size = cvReadInt( find_param( fs, "min_log_array_size" ), min_log_array_size );
|
||||
max_log_array_size = cvReadInt( find_param( fs, "max_log_array_size" ), max_log_array_size );
|
||||
test_case_count = cvReadInt( find_param( fs, "test_case_count" ), test_case_count );
|
||||
test_case_count = cvRound( test_case_count*ts->get_test_case_count_scale() );
|
||||
|
||||
min_log_array_size = cvTsClipInt( min_log_array_size, 0, 20 );
|
||||
max_log_array_size = cvTsClipInt( max_log_array_size, min_log_array_size, 20 );
|
||||
test_case_count = cvTsClipInt( test_case_count, 0, 100000 );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::get_test_array_types_and_sizes( int /*test_case_idx*/, CvSize** sizes, int** types )
|
||||
{
|
||||
CvRNG* rng = ts->get_rng();
|
||||
CvSize size;
|
||||
double val;
|
||||
int i, j;
|
||||
|
||||
val = cvRandReal(rng) * (max_log_array_size - min_log_array_size) + min_log_array_size;
|
||||
size.width = cvRound( exp(val*CV_LOG2) );
|
||||
val = cvRandReal(rng) * (max_log_array_size - min_log_array_size) + min_log_array_size;
|
||||
size.height = cvRound( exp(val*CV_LOG2) );
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
int count = test_array[i].size();
|
||||
for( j = 0; j < count; j++ )
|
||||
{
|
||||
sizes[i][j] = size;
|
||||
types[i][j] = CV_8UC1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::get_timing_test_array_types_and_sizes( int /*test_case_idx*/, CvSize** sizes, int** types,
|
||||
CvSize** whole_sizes, bool *are_images )
|
||||
{
|
||||
const CvFileNode* size_node = find_timing_param( "size" );
|
||||
const CvFileNode* depth_node = find_timing_param( "depth" );
|
||||
const CvFileNode* channels_node = find_timing_param( "channels" );
|
||||
int i, j;
|
||||
int depth = 0, channels = 1;
|
||||
CvSize size = {1,1}, whole_size = size;
|
||||
|
||||
if( size_node && CV_NODE_IS_SEQ(size_node->tag) )
|
||||
{
|
||||
CvSeq* seq = size_node->data.seq;
|
||||
size.width = cvReadInt((const CvFileNode*)cvGetSeqElem(seq,0), 1);
|
||||
size.height = cvReadInt((const CvFileNode*)cvGetSeqElem(seq,1), 1);
|
||||
whole_size = size;
|
||||
if( seq->total > 2 )
|
||||
{
|
||||
whole_size.width = cvReadInt((const CvFileNode*)cvGetSeqElem(seq,2), 1);
|
||||
whole_size.height = cvReadInt((const CvFileNode*)cvGetSeqElem(seq,3), 1);
|
||||
whole_size.width = MAX( whole_size.width, size.width );
|
||||
whole_size.height = MAX( whole_size.height, size.height );
|
||||
}
|
||||
}
|
||||
|
||||
if( depth_node && CV_NODE_IS_STRING(depth_node->tag) )
|
||||
{
|
||||
depth = cvTsTypeByName( depth_node->data.str.ptr );
|
||||
if( depth < 0 || depth > CV_64F )
|
||||
depth = 0;
|
||||
}
|
||||
|
||||
if( channels_node && CV_NODE_IS_INT(channels_node->tag) )
|
||||
{
|
||||
channels = cvReadInt( channels_node, 1 );
|
||||
if( channels < 0 || channels > CV_CN_MAX )
|
||||
channels = 1;
|
||||
}
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
int count = test_array[i].size();
|
||||
for( j = 0; j < count; j++ )
|
||||
{
|
||||
sizes[i][j] = size;
|
||||
whole_sizes[i][j] = whole_size;
|
||||
if( i != MASK )
|
||||
types[i][j] = CV_MAKETYPE(depth,channels);
|
||||
else
|
||||
types[i][j] = CV_8UC1;
|
||||
if( i == REF_OUTPUT || i == REF_INPUT_OUTPUT )
|
||||
sizes[i][j] = cvSize(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
if( are_images )
|
||||
*are_images = false; // by default CvMat is used in performance tests
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::print_timing_params( int /*test_case_idx*/, char* ptr, int params_left )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < params_left; i++ )
|
||||
{
|
||||
sprintf( ptr, "-," );
|
||||
ptr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::print_time( int test_case_idx, double time_clocks, double time_cpu_clocks )
|
||||
{
|
||||
int in_type = -1, out_type = -1;
|
||||
CvSize size = { -1, -1 };
|
||||
const CvFileNode* size_node = find_timing_param( "size" );
|
||||
char str[1024], *ptr = str;
|
||||
int len;
|
||||
bool have_mask;
|
||||
double cpe;
|
||||
|
||||
if( size_node )
|
||||
{
|
||||
if( !CV_NODE_IS_SEQ(size_node->tag) )
|
||||
{
|
||||
size.width = cvReadInt(size_node,-1);
|
||||
size.height = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
size.width = cvReadInt((const CvFileNode*)cvGetSeqElem(size_node->data.seq,0),-1);
|
||||
size.height = cvReadInt((const CvFileNode*)cvGetSeqElem(size_node->data.seq,1),-1);
|
||||
}
|
||||
}
|
||||
|
||||
if( test_array[INPUT].size() )
|
||||
{
|
||||
in_type = CV_MAT_TYPE(test_mat[INPUT][0].type);
|
||||
if( size.width == -1 )
|
||||
size = cvGetMatSize(&test_mat[INPUT][0]);
|
||||
}
|
||||
|
||||
if( test_array[OUTPUT].size() )
|
||||
{
|
||||
out_type = CV_MAT_TYPE(test_mat[OUTPUT][0].type);
|
||||
if( in_type < 0 )
|
||||
in_type = out_type;
|
||||
if( size.width == -1 )
|
||||
size = cvGetMatSize(&test_mat[OUTPUT][0]);
|
||||
}
|
||||
|
||||
if( out_type < 0 && test_array[INPUT_OUTPUT].size() )
|
||||
{
|
||||
out_type = CV_MAT_TYPE(test_mat[INPUT_OUTPUT][0].type);
|
||||
if( in_type < 0 )
|
||||
in_type = out_type;
|
||||
if( size.width == -1 )
|
||||
size = cvGetMatSize(&test_mat[INPUT_OUTPUT][0]);
|
||||
}
|
||||
|
||||
have_mask = test_array[MASK].size() > 0 && test_array[MASK][0] != 0;
|
||||
|
||||
if( in_type < 0 && out_type < 0 )
|
||||
return;
|
||||
|
||||
if( out_type < 0 )
|
||||
out_type = in_type;
|
||||
|
||||
ptr = strchr( (char*)tested_functions, ',' );
|
||||
if( ptr )
|
||||
{
|
||||
len = (int)(ptr - tested_functions);
|
||||
strncpy( str, tested_functions, len );
|
||||
}
|
||||
else
|
||||
{
|
||||
len = (int)strlen( tested_functions );
|
||||
strcpy( str, tested_functions );
|
||||
}
|
||||
ptr = str + len;
|
||||
*ptr = '\0';
|
||||
if( have_mask )
|
||||
{
|
||||
sprintf( ptr, "(Mask)" );
|
||||
ptr += strlen(ptr);
|
||||
}
|
||||
*ptr++ = ',';
|
||||
sprintf( ptr, "%s", cvTsGetTypeName(in_type) );
|
||||
ptr += strlen(ptr);
|
||||
|
||||
if( CV_MAT_DEPTH(out_type) != CV_MAT_DEPTH(in_type) )
|
||||
{
|
||||
sprintf( ptr, "%s", cvTsGetTypeName(out_type) );
|
||||
ptr += strlen(ptr);
|
||||
}
|
||||
*ptr++ = ',';
|
||||
|
||||
sprintf( ptr, "C%d", CV_MAT_CN(in_type) );
|
||||
ptr += strlen(ptr);
|
||||
|
||||
if( CV_MAT_CN(out_type) != CV_MAT_CN(in_type) )
|
||||
{
|
||||
sprintf( ptr, "C%d", CV_MAT_CN(out_type) );
|
||||
ptr += strlen(ptr);
|
||||
}
|
||||
*ptr++ = ',';
|
||||
|
||||
sprintf( ptr, "%dx%d,", size.width, size.height );
|
||||
ptr += strlen(ptr);
|
||||
|
||||
print_timing_params( test_case_idx, ptr );
|
||||
ptr += strlen(ptr);
|
||||
cpe = time_cpu_clocks / ((double)size.width * size.height);
|
||||
if( cpe >= 100 )
|
||||
sprintf( ptr, "%.0f,", cpe );
|
||||
else
|
||||
sprintf( ptr, "%.1f,", cpe );
|
||||
ptr += strlen(ptr);
|
||||
sprintf( ptr, "%g", time_clocks*1e6/cv::getTickFrequency() );
|
||||
|
||||
ts->printf( CvTS::CSV, "%s\n", str );
|
||||
}
|
||||
|
||||
|
||||
static const int icvTsTypeToDepth[] =
|
||||
{
|
||||
IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U, IPL_DEPTH_16S,
|
||||
IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F
|
||||
};
|
||||
|
||||
|
||||
int CvArrTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = 1;
|
||||
CvSize** sizes = (CvSize**)malloc( max_arr*sizeof(sizes[0]) );
|
||||
CvSize** whole_sizes = (CvSize**)malloc( max_arr*sizeof(whole_sizes[0]) );
|
||||
int** types = (int**)malloc( max_arr*sizeof(types[0]) );
|
||||
int i, j, total = 0;
|
||||
CvRNG* rng = ts->get_rng();
|
||||
bool is_image = false;
|
||||
bool is_timing_test = false;
|
||||
|
||||
CV_FUNCNAME( "CvArrTest::prepare_test_case" );
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
is_timing_test = ts->get_testing_mode() == CvTS::TIMING_MODE;
|
||||
|
||||
if( is_timing_test )
|
||||
{
|
||||
if( !get_next_timing_param_tuple() )
|
||||
{
|
||||
code = -1;
|
||||
EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
int count = test_array[i].size();
|
||||
count = MAX(count, 1);
|
||||
sizes[i] = (CvSize*)malloc( count*sizeof(sizes[i][0]) );
|
||||
types[i] = (int*)malloc( count*sizeof(types[i][0]) );
|
||||
whole_sizes[i] = (CvSize*)malloc( count*sizeof(whole_sizes[i][0]) );
|
||||
}
|
||||
|
||||
if( !is_timing_test )
|
||||
get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
else
|
||||
{
|
||||
get_timing_test_array_types_and_sizes( test_case_idx, sizes, types,
|
||||
whole_sizes, &is_image );
|
||||
}
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
int count = test_array[i].size();
|
||||
total += count;
|
||||
for( j = 0; j < count; j++ )
|
||||
{
|
||||
unsigned t = cvRandInt(rng);
|
||||
bool create_mask = true, use_roi = false;
|
||||
CvSize size = sizes[i][j], whole_size = size;
|
||||
CvRect roi = {0,0,0,0};
|
||||
|
||||
if( !is_timing_test )
|
||||
{
|
||||
is_image = !cvmat_allowed ? true : iplimage_allowed ? (t & 1) != 0 : false;
|
||||
create_mask = (t & 6) == 0; // ~ each of 3 tests will use mask
|
||||
use_roi = (t & 8) != 0;
|
||||
if( use_roi )
|
||||
{
|
||||
whole_size.width += cvRandInt(rng) % 10;
|
||||
whole_size.height += cvRandInt(rng) % 10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
whole_size = whole_sizes[i][j];
|
||||
use_roi = whole_size.width != size.width || whole_size.height != size.height;
|
||||
create_mask = cvReadInt(find_timing_param( "use_mask" ),0) != 0;
|
||||
}
|
||||
|
||||
cvRelease( &test_array[i][j] );
|
||||
if( size.width > 0 && size.height > 0 &&
|
||||
types[i][j] >= 0 && (i != MASK || create_mask) )
|
||||
{
|
||||
if( use_roi )
|
||||
{
|
||||
roi.width = size.width;
|
||||
roi.height = size.height;
|
||||
if( whole_size.width > size.width )
|
||||
{
|
||||
if( !is_timing_test )
|
||||
roi.x = cvRandInt(rng) % (whole_size.width - size.width);
|
||||
else
|
||||
roi.x = 1;
|
||||
}
|
||||
|
||||
if( whole_size.height > size.height )
|
||||
{
|
||||
if( !is_timing_test )
|
||||
roi.y = cvRandInt(rng) % (whole_size.height - size.height);
|
||||
else
|
||||
roi.y = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( is_image )
|
||||
{
|
||||
CV_CALL( test_array[i][j] = cvCreateImage( whole_size,
|
||||
icvTsTypeToDepth[CV_MAT_DEPTH(types[i][j])],
|
||||
CV_MAT_CN(types[i][j]) ));
|
||||
if( use_roi )
|
||||
cvSetImageROI( (IplImage*)test_array[i][j], roi );
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_CALL( test_array[i][j] = cvCreateMat( whole_size.height,
|
||||
whole_size.width, types[i][j] ));
|
||||
if( use_roi )
|
||||
{
|
||||
CvMat submat, *mat = (CvMat*)test_array[i][j];
|
||||
cvGetSubRect( test_array[i][j], &submat, roi );
|
||||
submat.refcount = mat->refcount;
|
||||
*mat = submat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( total > max_hdr )
|
||||
{
|
||||
delete hdr;
|
||||
max_hdr = total;
|
||||
hdr = new CvMat[max_hdr];
|
||||
}
|
||||
|
||||
total = 0;
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
int count = test_array[i].size();
|
||||
test_mat[i] = count > 0 ? hdr + total : 0;
|
||||
for( j = 0; j < count; j++ )
|
||||
{
|
||||
CvArr* arr = test_array[i][j];
|
||||
CvMat* mat = &test_mat[i][j];
|
||||
if( !arr )
|
||||
memset( mat, 0, sizeof(*mat) );
|
||||
else if( CV_IS_MAT( arr ))
|
||||
{
|
||||
*mat = *(CvMat*)arr;
|
||||
mat->refcount = 0;
|
||||
}
|
||||
else
|
||||
cvGetMat( arr, mat, 0, 0 );
|
||||
if( mat->data.ptr )
|
||||
fill_array( test_case_idx, i, j, mat );
|
||||
}
|
||||
total += count;
|
||||
}
|
||||
|
||||
__END__;
|
||||
|
||||
for( i = 0; i < max_arr; i++ )
|
||||
{
|
||||
if( sizes )
|
||||
free( sizes[i] );
|
||||
if( whole_sizes )
|
||||
free( whole_sizes[i] );
|
||||
if( types )
|
||||
free( types[i] );
|
||||
}
|
||||
|
||||
free( sizes );
|
||||
free( whole_sizes );
|
||||
free( types );
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::get_minmax_bounds( int i, int /*j*/, int type, CvScalar* low, CvScalar* high )
|
||||
{
|
||||
double l, u;
|
||||
|
||||
if( i == MASK )
|
||||
{
|
||||
l = -2;
|
||||
u = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
l = cvTsMinVal(type);
|
||||
u = cvTsMaxVal(type);
|
||||
}
|
||||
|
||||
*low = cvScalarAll(l);
|
||||
*high = cvScalarAll(u);
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::fill_array( int /*test_case_idx*/, int i, int j, CvMat* arr )
|
||||
{
|
||||
if( i == REF_INPUT_OUTPUT )
|
||||
cvTsCopy( &test_mat[INPUT_OUTPUT][j], arr, 0 );
|
||||
else if( i == INPUT || i == INPUT_OUTPUT || i == MASK )
|
||||
{
|
||||
int type = cvGetElemType( arr );
|
||||
CvScalar low, high;
|
||||
|
||||
get_minmax_bounds( i, j, type, &low, &high );
|
||||
cvTsRandUni( ts->get_rng(), arr, low, high );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double CvArrTest::get_success_error_level( int /*test_case_idx*/, int i, int j )
|
||||
{
|
||||
int elem_depth = CV_MAT_DEPTH(cvGetElemType(test_array[i][j]));
|
||||
assert( i == OUTPUT || i == INPUT_OUTPUT );
|
||||
return elem_depth < CV_32F ? 0 : elem_depth == CV_32F ? FLT_EPSILON*100: DBL_EPSILON*5000;
|
||||
}
|
||||
|
||||
|
||||
void CvArrTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
int CvArrTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
static const char* arr_names[] = { "input", "input/output", "output",
|
||||
"ref input/output", "ref output",
|
||||
"temporary", "mask" };
|
||||
int i, j;
|
||||
prepare_to_validation( test_case_idx );
|
||||
|
||||
for( i = 0; i < 2; i++ )
|
||||
{
|
||||
int i0 = i == 0 ? OUTPUT : INPUT_OUTPUT;
|
||||
int i1 = i == 0 ? REF_OUTPUT : REF_INPUT_OUTPUT;
|
||||
int count = test_array[i0].size();
|
||||
|
||||
assert( count == test_array[i1].size() );
|
||||
for( j = 0; j < count; j++ )
|
||||
{
|
||||
double err_level;
|
||||
CvPoint idx = {0,0};
|
||||
double max_diff = 0;
|
||||
int code;
|
||||
char msg[100];
|
||||
|
||||
if( !test_array[i1][j] )
|
||||
continue;
|
||||
|
||||
err_level = get_success_error_level( test_case_idx, i0, j );
|
||||
code = cvTsCmpEps( &test_mat[i0][j], &test_mat[i1][j], &max_diff, err_level, &idx,
|
||||
element_wise_relative_error );
|
||||
|
||||
switch( code )
|
||||
{
|
||||
case -1:
|
||||
sprintf( msg, "Too big difference (=%g)", max_diff );
|
||||
code = CvTS::FAIL_BAD_ACCURACY;
|
||||
break;
|
||||
case -2:
|
||||
strcpy( msg, "Invalid output" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
case -3:
|
||||
strcpy( msg, "Invalid output in the reference array" );
|
||||
code = CvTS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
ts->printf( CvTS::LOG, "%s in %s array %d at (%d,%d)\n", msg,
|
||||
arr_names[i0], j, idx.x, idx.y );
|
||||
for( i0 = 0; i0 < max_arr; i0++ )
|
||||
{
|
||||
int count = test_array[i0].size();
|
||||
if( i0 == REF_INPUT_OUTPUT || i0 == OUTPUT || i0 == TEMP )
|
||||
continue;
|
||||
for( i1 = 0; i1 < count; i1++ )
|
||||
{
|
||||
CvArr* arr = test_array[i0][i1];
|
||||
if( arr )
|
||||
{
|
||||
CvSize size = cvGetSize(arr);
|
||||
int type = cvGetElemType(arr);
|
||||
ts->printf( CvTS::LOG, "%s array %d type=%sC%d, size=(%d,%d)\n",
|
||||
arr_names[i0], i1, cvTsGetTypeName(type),
|
||||
CV_MAT_CN(type), size.width, size.height );
|
||||
}
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info( code );
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user