1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Normalize line endings and whitespace

This commit is contained in:
OpenCV Buildbot
2012-10-17 03:18:30 +04:00
committed by Andrey Kamaev
parent 69020da607
commit 04384a71e4
1516 changed files with 258846 additions and 258162 deletions
+255 -255
View File
@@ -1,255 +1,255 @@
/*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 "test_precomp.hpp"
#include <time.h>
#include <limits>
using namespace cv;
using namespace std;
#define CORE_COUNTNONZERO_ERROR_COUNT 1
#define MESSAGE_ERROR_COUNT "Count non zero elements returned by OpenCV function is incorrect."
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
const int FLOAT_TYPE [2] = {CV_32F, CV_64F};
const int INT_TYPE [5] = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32S};
#define MAX_WIDTH 100
#define MAX_HEIGHT 100
class CV_CountNonZeroTest: public cvtest::BaseTest
{
public:
CV_CountNonZeroTest();
~CV_CountNonZeroTest();
protected:
void run (int);
private:
float eps_32;
double eps_64;
Mat src;
int current_type;
void generate_src_data(cv::Size size, int type);
void generate_src_data(cv::Size size, int type, int count_non_zero);
void generate_src_stat_data(cv::Size size, int type, int distribution);
int get_count_non_zero();
void print_information(int right, int result);
};
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(std::numeric_limits<float>::min()), eps_64(std::numeric_limits<double>::min()), src(Mat()), current_type(-1) {}
CV_CountNonZeroTest::~CV_CountNonZeroTest() {}
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type)
{
src.create(size, CV_MAKETYPE(type, 1));
for (int j = 0; j < size.width; ++j)
for (int i = 0; i < size.height; ++i)
switch (type)
{
case CV_8U: { src.at<uchar>(i, j) = cv::randu<uchar>(); break; }
case CV_8S: { src.at<char>(i, j) = cv::randu<uchar>() - 128; break; }
case CV_16U: { src.at<ushort>(i, j) = cv::randu<ushort>(); break; }
case CV_16S: { src.at<short>(i, j) = cv::randu<short>(); break; }
case CV_32S: { src.at<int>(i, j) = cv::randu<int>(); break; }
case CV_32F: { src.at<float>(i, j) = cv::randu<float>(); break; }
case CV_64F: { src.at<double>(i, j) = cv::randu<double>(); break; }
default: break;
}
}
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int count_non_zero)
{
src = Mat::zeros(size, CV_MAKETYPE(type, 1));
int n = 0; RNG& rng = ts->get_rng();
while (n < count_non_zero)
{
int i = rng.next()%size.height, j = rng.next()%size.width;
switch (type)
{
case CV_8U: { if (!src.at<uchar>(i, j)) {src.at<uchar>(i, j) = cv::randu<uchar>(); n += (src.at<uchar>(i, j) > 0);} break; }
case CV_8S: { if (!src.at<char>(i, j)) {src.at<char>(i, j) = cv::randu<uchar>() - 128; n += abs(sign(src.at<char>(i, j)));} break; }
case CV_16U: { if (!src.at<ushort>(i, j)) {src.at<ushort>(i, j) = cv::randu<ushort>(); n += (src.at<ushort>(i, j) > 0);} break; }
case CV_16S: { if (!src.at<short>(i, j)) {src.at<short>(i, j) = cv::randu<short>(); n += abs(sign(src.at<short>(i, j)));} break; }
case CV_32S: { if (!src.at<int>(i, j)) {src.at<int>(i, j) = cv::randu<int>(); n += abs(sign(src.at<int>(i, j)));} break; }
case CV_32F: { if (fabs(src.at<float>(i, j)) <= eps_32) {src.at<float>(i, j) = cv::randu<float>(); n += (fabs(src.at<float>(i, j)) > eps_32);} break; }
case CV_64F: { if (fabs(src.at<double>(i, j)) <= eps_64) {src.at<double>(i, j) = cv::randu<double>(); n += (fabs(src.at<double>(i, j)) > eps_64);} break; }
default: break;
}
}
}
void CV_CountNonZeroTest::generate_src_stat_data(cv::Size size, int type, int distribution)
{
src.create(size, CV_MAKETYPE(type, 1));
double mean = 0.0, sigma = 1.0;
double left = -1.0, right = 1.0;
RNG& rng = ts->get_rng();
if (distribution == RNG::NORMAL)
rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma));
else if (distribution == RNG::UNIFORM)
rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right));
}
int CV_CountNonZeroTest::get_count_non_zero()
{
int result = 0;
for (int i = 0; i < src.rows; ++i)
for (int j = 0; j < src.cols; ++j)
{
if (current_type == CV_8U) result += (src.at<uchar>(i, j) > 0);
else if (current_type == CV_8S) result += abs(sign(src.at<char>(i, j)));
else if (current_type == CV_16U) result += (src.at<ushort>(i, j) > 0);
else if (current_type == CV_16S) result += abs(sign(src.at<short>(i, j)));
else if (current_type == CV_32S) result += abs(sign(src.at<int>(i, j)));
else if (current_type == CV_32F) result += (fabs(src.at<float>(i, j)) > eps_32);
else result += (fabs(src.at<double>(i, j)) > eps_64);
}
return result;
}
void CV_CountNonZeroTest::print_information(int right, int result)
{
cout << endl; cout << "Checking for the work of countNonZero function..." << endl; cout << endl;
cout << "Type of Mat: ";
switch (current_type)
{
case 0: {cout << "CV_8U"; break;}
case 1: {cout << "CV_8S"; break;}
case 2: {cout << "CV_16U"; break;}
case 3: {cout << "CV_16S"; break;}
case 4: {cout << "CV_32S"; break;}
case 5: {cout << "CV_32F"; break;}
case 6: {cout << "CV_64F"; break;}
default: break;
}
cout << endl;
cout << "Number of rows: " << src.rows << " Number of cols: " << src.cols << endl;
cout << "True count non zero elements: " << right << " Result: " << result << endl;
cout << endl;
}
void CV_CountNonZeroTest::run(int)
{
const size_t N = 1500;
for (int k = 1; k <= 3; ++k)
for (size_t i = 0; i < N; ++i)
{
RNG& rng = ts->get_rng();
int w = rng.next()%MAX_WIDTH + 1, h = rng.next()%MAX_HEIGHT + 1;
current_type = rng.next()%7;
switch (k)
{
case 1: {
generate_src_data(Size(w, h), current_type);
int right = get_count_non_zero(), result = countNonZero(src);
if (result != right)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: RANDOM" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
case 2: {
int count_non_zero = rng.next()%(w*h);
generate_src_data(Size(w, h), current_type, count_non_zero);
int result = countNonZero(src);
if (result != count_non_zero)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: HALF-RANDOM" << endl;
print_information(count_non_zero, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
case 3: {
int distribution = cv::randu<uchar>()%2;
generate_src_stat_data(Size(w, h), current_type, distribution);
int right = get_count_non_zero(), result = countNonZero(src);
if (right != result)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: STATISTIC" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
default: break;
}
}
}
TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }
/*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 "test_precomp.hpp"
#include <time.h>
#include <limits>
using namespace cv;
using namespace std;
#define CORE_COUNTNONZERO_ERROR_COUNT 1
#define MESSAGE_ERROR_COUNT "Count non zero elements returned by OpenCV function is incorrect."
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
const int FLOAT_TYPE [2] = {CV_32F, CV_64F};
const int INT_TYPE [5] = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32S};
#define MAX_WIDTH 100
#define MAX_HEIGHT 100
class CV_CountNonZeroTest: public cvtest::BaseTest
{
public:
CV_CountNonZeroTest();
~CV_CountNonZeroTest();
protected:
void run (int);
private:
float eps_32;
double eps_64;
Mat src;
int current_type;
void generate_src_data(cv::Size size, int type);
void generate_src_data(cv::Size size, int type, int count_non_zero);
void generate_src_stat_data(cv::Size size, int type, int distribution);
int get_count_non_zero();
void print_information(int right, int result);
};
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(std::numeric_limits<float>::min()), eps_64(std::numeric_limits<double>::min()), src(Mat()), current_type(-1) {}
CV_CountNonZeroTest::~CV_CountNonZeroTest() {}
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type)
{
src.create(size, CV_MAKETYPE(type, 1));
for (int j = 0; j < size.width; ++j)
for (int i = 0; i < size.height; ++i)
switch (type)
{
case CV_8U: { src.at<uchar>(i, j) = cv::randu<uchar>(); break; }
case CV_8S: { src.at<char>(i, j) = cv::randu<uchar>() - 128; break; }
case CV_16U: { src.at<ushort>(i, j) = cv::randu<ushort>(); break; }
case CV_16S: { src.at<short>(i, j) = cv::randu<short>(); break; }
case CV_32S: { src.at<int>(i, j) = cv::randu<int>(); break; }
case CV_32F: { src.at<float>(i, j) = cv::randu<float>(); break; }
case CV_64F: { src.at<double>(i, j) = cv::randu<double>(); break; }
default: break;
}
}
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int count_non_zero)
{
src = Mat::zeros(size, CV_MAKETYPE(type, 1));
int n = 0; RNG& rng = ts->get_rng();
while (n < count_non_zero)
{
int i = rng.next()%size.height, j = rng.next()%size.width;
switch (type)
{
case CV_8U: { if (!src.at<uchar>(i, j)) {src.at<uchar>(i, j) = cv::randu<uchar>(); n += (src.at<uchar>(i, j) > 0);} break; }
case CV_8S: { if (!src.at<char>(i, j)) {src.at<char>(i, j) = cv::randu<uchar>() - 128; n += abs(sign(src.at<char>(i, j)));} break; }
case CV_16U: { if (!src.at<ushort>(i, j)) {src.at<ushort>(i, j) = cv::randu<ushort>(); n += (src.at<ushort>(i, j) > 0);} break; }
case CV_16S: { if (!src.at<short>(i, j)) {src.at<short>(i, j) = cv::randu<short>(); n += abs(sign(src.at<short>(i, j)));} break; }
case CV_32S: { if (!src.at<int>(i, j)) {src.at<int>(i, j) = cv::randu<int>(); n += abs(sign(src.at<int>(i, j)));} break; }
case CV_32F: { if (fabs(src.at<float>(i, j)) <= eps_32) {src.at<float>(i, j) = cv::randu<float>(); n += (fabs(src.at<float>(i, j)) > eps_32);} break; }
case CV_64F: { if (fabs(src.at<double>(i, j)) <= eps_64) {src.at<double>(i, j) = cv::randu<double>(); n += (fabs(src.at<double>(i, j)) > eps_64);} break; }
default: break;
}
}
}
void CV_CountNonZeroTest::generate_src_stat_data(cv::Size size, int type, int distribution)
{
src.create(size, CV_MAKETYPE(type, 1));
double mean = 0.0, sigma = 1.0;
double left = -1.0, right = 1.0;
RNG& rng = ts->get_rng();
if (distribution == RNG::NORMAL)
rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma));
else if (distribution == RNG::UNIFORM)
rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right));
}
int CV_CountNonZeroTest::get_count_non_zero()
{
int result = 0;
for (int i = 0; i < src.rows; ++i)
for (int j = 0; j < src.cols; ++j)
{
if (current_type == CV_8U) result += (src.at<uchar>(i, j) > 0);
else if (current_type == CV_8S) result += abs(sign(src.at<char>(i, j)));
else if (current_type == CV_16U) result += (src.at<ushort>(i, j) > 0);
else if (current_type == CV_16S) result += abs(sign(src.at<short>(i, j)));
else if (current_type == CV_32S) result += abs(sign(src.at<int>(i, j)));
else if (current_type == CV_32F) result += (fabs(src.at<float>(i, j)) > eps_32);
else result += (fabs(src.at<double>(i, j)) > eps_64);
}
return result;
}
void CV_CountNonZeroTest::print_information(int right, int result)
{
cout << endl; cout << "Checking for the work of countNonZero function..." << endl; cout << endl;
cout << "Type of Mat: ";
switch (current_type)
{
case 0: {cout << "CV_8U"; break;}
case 1: {cout << "CV_8S"; break;}
case 2: {cout << "CV_16U"; break;}
case 3: {cout << "CV_16S"; break;}
case 4: {cout << "CV_32S"; break;}
case 5: {cout << "CV_32F"; break;}
case 6: {cout << "CV_64F"; break;}
default: break;
}
cout << endl;
cout << "Number of rows: " << src.rows << " Number of cols: " << src.cols << endl;
cout << "True count non zero elements: " << right << " Result: " << result << endl;
cout << endl;
}
void CV_CountNonZeroTest::run(int)
{
const size_t N = 1500;
for (int k = 1; k <= 3; ++k)
for (size_t i = 0; i < N; ++i)
{
RNG& rng = ts->get_rng();
int w = rng.next()%MAX_WIDTH + 1, h = rng.next()%MAX_HEIGHT + 1;
current_type = rng.next()%7;
switch (k)
{
case 1: {
generate_src_data(Size(w, h), current_type);
int right = get_count_non_zero(), result = countNonZero(src);
if (result != right)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: RANDOM" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
case 2: {
int count_non_zero = rng.next()%(w*h);
generate_src_data(Size(w, h), current_type, count_non_zero);
int result = countNonZero(src);
if (result != count_non_zero)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: HALF-RANDOM" << endl;
print_information(count_non_zero, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
case 3: {
int distribution = cv::randu<uchar>()%2;
generate_src_stat_data(Size(w, h), current_type, distribution);
int right = get_count_non_zero(), result = countNonZero(src);
if (right != result)
{
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: STATISTIC" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return;
}
break;
}
default: break;
}
}
}
TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }
+89 -89
View File
@@ -13,12 +13,12 @@ static Mat initDFTWave( int n, bool inv )
Complexd wi, w1;
Mat wave(1, n, CV_64FC2);
Complexd* w = wave.ptr<Complexd>();
w1.re = cos(angle);
w1.im = sin(angle);
w[0].re = wi.re = 1.;
w[0].im = wi.im = 0.;
for( i = 1; i < n; i++ )
{
double t = wi.re*w1.re - wi.im*w1.im;
@@ -26,7 +26,7 @@ static Mat initDFTWave( int n, bool inv )
wi.re = t;
w[i] = wi;
}
return wave;
}
@@ -41,18 +41,18 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
size_t srcstep = esz, dststep = esz;
const uchar* src0 = _src.data;
uchar* dst0 = _dst.data;
CV_Assert( _src.cols + _src.rows - 1 == n );
if( wave.empty() )
wave = initDFTWave( n, (flags & DFT_INVERSE) != 0 );
const Complexd* w = wave.ptr<Complexd>();
if( !_src.isContinuous() )
srcstep = _src.step;
if( !_dst.isContinuous() )
dststep = _dst.step;
if( _src.type() == CV_32FC2 )
{
for( i = 0; i < n; i++ )
@@ -61,7 +61,7 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
Complexd sum(0,0);
int delta = i;
k = 0;
for( j = 0; j < n; j++ )
{
const Complexf* src = (const Complexf*)(src0 + j*srcstep);
@@ -70,7 +70,7 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
k += delta;
k -= (k >= n ? n : 0);
}
dst->re = (float)(sum.re*scale);
dst->im = (float)(sum.im*scale);
}
@@ -83,7 +83,7 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
Complexd sum(0,0);
int delta = i;
k = 0;
for( j = 0; j < n; j++ )
{
const Complexd* src = (const Complexd*)(src0 + j*srcstep);
@@ -92,7 +92,7 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
k += delta;
k -= (k >= n ? n : 0);
}
dst->re = sum.re*scale;
dst->im = sum.im*scale;
}
@@ -109,19 +109,19 @@ static void DFT_2D( const Mat& src, Mat& dst, int flags )
dst.create(src.size(), src.type());
Mat tmp( src.cols, src.rows, src.type());
Mat wave = initDFTWave( dst.cols, (flags & DFT_INVERSE) != 0 );
// 1. row-wise transform
for( i = 0; i < dst.rows; i++ )
{
Mat srci = src.row(i).reshape(cn, src.cols), dsti = tmp.col(i);
DFT_1D(srci, dsti, flags, wave );
}
if( (flags & DFT_ROWS) == 0 )
{
if( dst.cols != dst.rows )
wave = initDFTWave( dst.rows, (flags & DFT_INVERSE) != 0 );
// 2. column-wise transform
for( i = 0; i < dst.cols; i++ )
{
@@ -139,7 +139,7 @@ static Mat initDCTWave( int n, bool inv )
int i, k;
double angle = CV_PI*0.5/n;
Mat wave(n, n, CV_64F);
double scale = sqrt(1./n);
for( k = 0; k < n; k++ )
wave.at<double>(0, k) = scale;
@@ -147,10 +147,10 @@ static Mat initDCTWave( int n, bool inv )
for( i = 1; i < n; i++ )
for( k = 0; k < n; k++ )
wave.at<double>(i, k) = scale*cos( angle*i*(2*k + 1) );
if( inv )
cv::transpose( wave, wave );
return wave;
}
@@ -162,27 +162,27 @@ static void DCT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
Mat wave = _wave;
int srcstep = 1, dststep = 1;
double* w;
CV_Assert( _src.cols + _src.rows - 1 == n);
if( wave.empty() )
wave = initDCTWave( n, (flags & DFT_INVERSE) != 0 );
w = wave.ptr<double>();
if( !_src.isContinuous() )
srcstep = (int)(_src.step/_src.elemSize());
if( !_dst.isContinuous() )
dststep = (int)(_dst.step/_dst.elemSize());
if( _src.type() == CV_32FC1 )
{
float *dst = _dst.ptr<float>();
for( i = 0; i < n; i++, dst += dststep )
{
const float* src = _src.ptr<float>();
double sum = 0;
for( j = 0; j < n; j++, src += srcstep )
sum += src[0]*w[j];
w += n;
@@ -192,12 +192,12 @@ static void DCT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat(
else if( _src.type() == CV_64FC1 )
{
double *dst = _dst.ptr<double>();
for( i = 0; i < n; i++, dst += dststep )
{
const double* src = _src.ptr<double>();
double sum = 0;
for( j = 0; j < n; j++, src += srcstep )
sum += src[0]*w[j];
w += n;
@@ -216,7 +216,7 @@ static void DCT_2D( const Mat& src, Mat& dst, int flags )
dst.create( src.size(), src.type() );
Mat tmp(dst.cols, dst.rows, dst.type() );
Mat wave = initDCTWave( dst.cols, (flags & DCT_INVERSE) != 0 );
// 1. row-wise transform
for( i = 0; i < dst.rows; i++ )
{
@@ -224,12 +224,12 @@ static void DCT_2D( const Mat& src, Mat& dst, int flags )
Mat dsti = tmp.col(i);
DCT_1D(srci, dsti, flags, wave);
}
if( (flags & DCT_ROWS) == 0 )
{
if( dst.cols != dst.rows )
wave = initDCTWave( dst.rows, (flags & DCT_INVERSE) != 0 );
// 2. column-wise transform
for( i = 0; i < dst.cols; i++ )
{
@@ -258,7 +258,7 @@ static void convertFromCCS( const Mat& _src0, const Mat& _src1, Mat& _dst, int f
dstrow = _dst.row(i);
convertFromCCS( src0row, src1row, dstrow, 0 );
}
if( is2d )
{
src0row = _src0.col(0);
@@ -277,45 +277,45 @@ static void convertFromCCS( const Mat& _src0, const Mat& _src1, Mat& _dst, int f
int i, n = _dst.cols + _dst.rows - 1, n2 = (n+1) >> 1;
int cn = _src0.channels();
int srcstep = cn, dststep = 1;
if( !_dst.isContinuous() )
dststep = (int)(_dst.step/_dst.elemSize());
if( !_src0.isContinuous() )
srcstep = (int)(_src0.step/_src0.elemSize1());
if( _dst.depth() == CV_32F )
{
Complexf* dst = _dst.ptr<Complexf>();
const float* src0 = _src0.ptr<float>();
const float* src1 = _src1.ptr<float>();
int delta0, delta1;
dst->re = src0[0];
dst->im = 0;
if( (n & 1) == 0 )
{
dst[n2*dststep].re = src0[(cn == 1 ? n-1 : n2)*srcstep];
dst[n2*dststep].im = 0;
}
delta0 = srcstep;
delta1 = delta0 + (cn == 1 ? srcstep : 1);
if( cn == 1 )
srcstep *= 2;
for( i = 1; i < n2; i++, delta0 += srcstep, delta1 += srcstep )
{
float t0 = src0[delta0];
float t1 = src0[delta1];
dst[i*dststep].re = t0;
dst[i*dststep].im = t1;
t0 = src1[delta0];
t1 = -src1[delta1];
dst[(n-i)*dststep].re = t0;
dst[(n-i)*dststep].im = t1;
}
@@ -326,32 +326,32 @@ static void convertFromCCS( const Mat& _src0, const Mat& _src1, Mat& _dst, int f
const double* src0 = _src0.ptr<double>();
const double* src1 = _src1.ptr<double>();
int delta0, delta1;
dst->re = src0[0];
dst->im = 0;
if( (n & 1) == 0 )
{
dst[n2*dststep].re = src0[(cn == 1 ? n-1 : n2)*srcstep];
dst[n2*dststep].im = 0;
}
delta0 = srcstep;
delta1 = delta0 + (cn == 1 ? srcstep : 1);
if( cn == 1 )
srcstep *= 2;
for( i = 1; i < n2; i++, delta0 += srcstep, delta1 += srcstep )
{
double t0 = src0[delta0];
double t1 = src0[delta1];
dst[i*dststep].re = t0;
dst[i*dststep].im = t1;
t0 = src1[delta0];
t1 = -src1[delta1];
dst[(n-i)*dststep].re = t0;
dst[(n-i)*dststep].im = t1;
}
@@ -364,9 +364,9 @@ static void fixCCS( Mat& mat, int cols, int flags )
{
int i, rows = mat.rows;
int rows2 = (flags & DFT_ROWS) ? rows : rows/2 + 1, cols2 = cols/2 + 1;
CV_Assert( cols2 == mat.cols );
if( mat.type() == CV_32FC2 )
{
for( i = 0; i < rows2; i++ )
@@ -383,7 +383,7 @@ static void fixCCS( Mat& mat, int cols, int flags )
Complexf* row2 = mat.ptr<Complexf>(rows-i);
row2[0].re = row[0].re;
row2[0].im = -row[0].im;
if( cols % 2 == 0 )
{
row2[cols2-1].re = row[cols2-1].re;
@@ -408,7 +408,7 @@ static void fixCCS( Mat& mat, int cols, int flags )
Complexd* row2 = mat.ptr<Complexd>(rows-i);
row2[0].re = row[0].re;
row2[0].im = -row[0].im;
if( cols % 2 == 0 )
{
row2[cols2-1].re = row[cols2-1].re;
@@ -418,16 +418,16 @@ static void fixCCS( Mat& mat, int cols, int flags )
}
}
}
static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
{
dst.create(src1.rows, src1.cols, src1.type());
int i, j, depth = src1.depth(), cols = src1.cols*2;
CV_Assert( src1.size == src2.size && src1.type() == src2.type() &&
(src1.type() == CV_32FC2 || src1.type() == CV_64FC2) );
for( i = 0; i < dst.rows; i++ )
{
if( depth == CV_32F )
@@ -435,13 +435,13 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
const float* a = src1.ptr<float>(i);
const float* b = src2.ptr<float>(i);
float* c = dst.ptr<float>(i);
if( !(flags & CV_DXT_MUL_CONJ) )
for( j = 0; j < cols; j += 2 )
{
double re = (double)a[j]*b[j] - (double)a[j+1]*b[j+1];
double im = (double)a[j+1]*b[j] + (double)a[j]*b[j+1];
c[j] = (float)re;
c[j+1] = (float)im;
}
@@ -450,7 +450,7 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
{
double re = (double)a[j]*b[j] + (double)a[j+1]*b[j+1];
double im = (double)a[j+1]*b[j] - (double)a[j]*b[j+1];
c[j] = (float)re;
c[j+1] = (float)im;
}
@@ -460,13 +460,13 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
const double* a = src1.ptr<double>(i);
const double* b = src2.ptr<double>(i);
double* c = dst.ptr<double>(i);
if( !(flags & CV_DXT_MUL_CONJ) )
for( j = 0; j < cols; j += 2 )
{
double re = a[j]*b[j] - a[j+1]*b[j+1];
double im = a[j+1]*b[j] + a[j]*b[j+1];
c[j] = re;
c[j+1] = im;
}
@@ -475,14 +475,14 @@ static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
{
double re = a[j]*b[j] + a[j+1]*b[j+1];
double im = a[j+1]*b[j] - a[j]*b[j+1];
c[j] = re;
c[j+1] = im;
}
}
}
}
}
}
@@ -519,7 +519,7 @@ spectrum_mode(_spectrum_mode), inplace(false), temp_dst(false)
test_array[REF_OUTPUT].push_back(NULL);
test_array[TEMP].push_back(NULL);
test_array[TEMP].push_back(NULL);
max_log_array_size = 9;
element_wise_relative_error = spectrum_mode;
}
@@ -535,16 +535,16 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
int cn = !allow_complex || !(bits & 256) ? 1 : 2;
Size size;
Base::get_test_array_types_and_sizes( test_case_idx, sizes, types );
flags = bits & (CV_DXT_INVERSE | CV_DXT_SCALE | CV_DXT_ROWS | CV_DXT_MUL_CONJ);
if( spectrum_mode )
flags &= ~CV_DXT_INVERSE;
types[TEMP][0] = types[TEMP][1] = types[INPUT][0] =
types[OUTPUT][0] = CV_MAKETYPE(depth, cn);
size = sizes[INPUT][0];
temp_dst = false;
if( flags & CV_DXT_ROWS && (bits&1024) )
{
if( bits&16 )
@@ -553,7 +553,7 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
size.height = 1;
flags &= ~CV_DXT_ROWS;
}
const int P2_MIN_SIZE = 32;
if( ((bits >> 10) & 1) == 0 )
{
@@ -562,19 +562,19 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
size.height = (size.height / P2_MIN_SIZE)*P2_MIN_SIZE;
size.height = MAX(size.height, 1);
}
if( !allow_odd )
{
if( size.width > 1 && (size.width&1) != 0 )
size.width = (size.width + 1) & -2;
if( size.height > 1 && (size.height&1) != 0 && !(flags & CV_DXT_ROWS) )
size.height = (size.height + 1) & -2;
}
sizes[INPUT][0] = sizes[OUTPUT][0] = size;
sizes[TEMP][0] = sizes[TEMP][1] = cvSize(0,0);
if( spectrum_mode )
{
if( cn == 1 )
@@ -590,7 +590,7 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
types[TEMP][0] = depth + 8; // CV_??FC2
sizes[TEMP][0] = size;
size = cvSize(size.width/2+1, size.height);
if( flags & CV_DXT_INVERSE )
{
if( cn == 2 )
@@ -605,7 +605,7 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
{
if( allow_complex )
types[OUTPUT][0] = depth + 8;
if( cn == 2 )
{
types[INPUT][0] = depth;
@@ -620,13 +620,13 @@ void CxCore_DXTBaseTest::get_test_array_types_and_sizes( int test_case_idx,
temp_dst = true;
}
}
inplace = false;
if( spectrum_mode ||
(!temp_dst && types[INPUT][0] == types[OUTPUT][0]) ||
(temp_dst && types[INPUT][0] == types[TEMP][1]) )
inplace = (bits & 64) != 0;
types[REF_OUTPUT][0] = types[OUTPUT][0];
sizes[REF_OUTPUT][0] = sizes[OUTPUT][0];
}
@@ -645,17 +645,17 @@ int CxCore_DXTBaseTest::prepare_test_case( int test_case_idx )
{
int in_type = test_mat[INPUT][0].type();
int out_type = test_mat[OUTPUT][0].type();
if( CV_MAT_CN(in_type) == 2 && CV_MAT_CN(out_type) == 1 )
cvtest::fixCCS( test_mat[INPUT][0], test_mat[OUTPUT][0].cols, flags );
if( inplace )
cvtest::copy( test_mat[INPUT][test_case_idx & (int)spectrum_mode],
temp_dst ? test_mat[TEMP][1] :
in_type == out_type ? test_mat[OUTPUT][0] :
test_mat[TEMP][0] );
}
return code;
}
@@ -680,7 +680,7 @@ void CxCore_DFTTest::run_func()
{
Mat& dst = temp_dst ? test_mat[TEMP][1] : test_mat[OUTPUT][0];
const Mat& src = inplace ? dst : test_mat[INPUT][0];
if(!(flags & CV_DXT_INVERSE))
cv::dft( src, dst, flags );
else
@@ -696,11 +696,11 @@ void CxCore_DFTTest::prepare_to_validation( int /*test_case_idx*/ )
Mat* tmp_dst = &dst;
int src_cn = src.channels();
int dst_cn = dst.channels();
if( src_cn != 2 || dst_cn != 2 )
{
tmp_src = &test_mat[TEMP][0];
if( !(flags & CV_DXT_INVERSE ) )
{
Mat& cvdft_dst = test_mat[TEMP][1];
@@ -715,12 +715,12 @@ void CxCore_DFTTest::prepare_to_validation( int /*test_case_idx*/ )
tmp_dst = &test_mat[TEMP][1];
}
}
if( src.rows == 1 || (src.cols == 1 && !(flags & CV_DXT_ROWS)) )
cvtest::DFT_1D( *tmp_src, *tmp_dst, flags );
else
cvtest::DFT_2D( *tmp_src, *tmp_dst, flags );
if( tmp_dst != &dst )
cvtest::extract( *tmp_dst, dst, 0 );
}
@@ -745,7 +745,7 @@ void CxCore_DCTTest::run_func()
{
Mat& dst = test_mat[OUTPUT][0];
const Mat& src = inplace ? dst : test_mat[INPUT][0];
if(!(flags & CV_DXT_INVERSE))
cv::dct( src, dst, flags );
else
@@ -757,7 +757,7 @@ void CxCore_DCTTest::prepare_to_validation( int /*test_case_idx*/ )
{
const Mat& src = test_mat[INPUT][0];
Mat& dst = test_mat[REF_OUTPUT][0];
if( src.rows == 1 || (src.cols == 1 && !(flags & CV_DXT_ROWS)) )
cvtest::DCT_1D( src, dst, flags );
else
@@ -786,7 +786,7 @@ void CxCore_MulSpectrumsTest::run_func()
Mat& dst = !test_mat[TEMP].empty() && !test_mat[TEMP][0].empty() ?
test_mat[TEMP][0] : test_mat[OUTPUT][0];
const Mat* src1 = &test_mat[INPUT][0], *src2 = &test_mat[INPUT][1];
if( inplace )
{
if( ts->get_current_test_info()->test_case_idx & 1 )
@@ -794,7 +794,7 @@ void CxCore_MulSpectrumsTest::run_func()
else
src1 = &dst;
}
cv::mulSpectrums( *src1, *src2, dst, flags, (flags & CV_DXT_MUL_CONJ) != 0 );
}
@@ -806,7 +806,7 @@ void CxCore_MulSpectrumsTest::prepare_to_validation( int /*test_case_idx*/ )
Mat& dst = test_mat[OUTPUT][0];
Mat& dst0 = test_mat[REF_OUTPUT][0];
int cn = src1->channels();
if( cn == 1 )
{
cvtest::convertFromCCS( *src1, *src1, dst, flags );
@@ -814,7 +814,7 @@ void CxCore_MulSpectrumsTest::prepare_to_validation( int /*test_case_idx*/ )
src1 = &dst;
src2 = &dst0;
}
cvtest::mulComplex( *src1, *src2, dst0, flags );
if( cn == 1 )
{
+411 -411
View File
@@ -1,411 +1,411 @@
/*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 "test_precomp.hpp"
#include <time.h>
using namespace cv;
using namespace std;
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
#define CORE_EIGEN_ERROR_COUNT 1
#define CORE_EIGEN_ERROR_SIZE 2
#define CORE_EIGEN_ERROR_DIFF 3
#define CORE_EIGEN_ERROR_ORTHO 4
#define CORE_EIGEN_ERROR_ORDER 5
#define MESSAGE_ERROR_COUNT "Matrix of eigen values must have the same rows as source matrix and 1 column."
#define MESSAGE_ERROR_SIZE "Source matrix and matrix of eigen vectors must have the same sizes."
#define MESSAGE_ERROR_DIFF_1 "Accurasy of eigen values computing less than required."
#define MESSAGE_ERROR_DIFF_2 "Accuracy of eigen vectors computing less than required."
#define MESSAGE_ERROR_ORTHO "Matrix of eigen vectors is not orthogonal."
#define MESSAGE_ERROR_ORDER "Eigen values are not sorted in ascending order."
const int COUNT_NORM_TYPES = 3;
const int NORM_TYPE[COUNT_NORM_TYPES] = {cv::NORM_L1, cv::NORM_L2, cv::NORM_INF};
enum TASK_TYPE_EIGEN {VALUES, VECTORS};
class Core_EigenTest: public cvtest::BaseTest
{
public:
Core_EigenTest();
~Core_EigenTest();
protected:
bool test_values(const cv::Mat& src); // complex test for eigen without vectors
bool check_full(int type); // compex test for symmetric matrix
virtual void run (int) = 0; // main testing method
protected:
float eps_val_32, eps_vec_32;
float eps_val_64, eps_vec_64;
int ntests;
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);
bool check_pairs_order(const cv::Mat& eigen_values); // checking order of eigen values & vectors (it should be none up)
bool check_orthogonality(const cv::Mat& U); // checking is matrix of eigen vectors orthogonal
bool test_pairs(const cv::Mat& src); // complex test for eigen with vectors
void print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff);
};
class Core_EigenTest_Scalar : public Core_EigenTest
{
public:
Core_EigenTest_Scalar() : Core_EigenTest() {}
~Core_EigenTest_Scalar();
virtual void run(int) = 0;
};
class Core_EigenTest_Scalar_32 : public Core_EigenTest_Scalar
{
public:
Core_EigenTest_Scalar_32() : Core_EigenTest_Scalar() {}
~Core_EigenTest_Scalar_32();
void run(int);
};
class Core_EigenTest_Scalar_64 : public Core_EigenTest_Scalar
{
public:
Core_EigenTest_Scalar_64() : Core_EigenTest_Scalar() {}
~Core_EigenTest_Scalar_64();
void run(int);
};
class Core_EigenTest_32 : public Core_EigenTest
{
public:
Core_EigenTest_32(): Core_EigenTest() {}
~Core_EigenTest_32() {}
void run(int);
};
class Core_EigenTest_64 : public Core_EigenTest
{
public:
Core_EigenTest_64(): Core_EigenTest() {}
~Core_EigenTest_64() {}
void run(int);
};
Core_EigenTest_Scalar::~Core_EigenTest_Scalar() {}
Core_EigenTest_Scalar_32::~Core_EigenTest_Scalar_32() {}
Core_EigenTest_Scalar_64::~Core_EigenTest_Scalar_64() {}
void Core_EigenTest_Scalar_32::run(int)
{
for (int i = 0; i < ntests; ++i)
{
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));
test_values(src);
}
}
void Core_EigenTest_Scalar_64::run(int)
{
for (int i = 0; i < ntests; ++i)
{
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));
test_values(src);
}
}
void Core_EigenTest_32::run(int) { check_full(CV_32FC1); }
void Core_EigenTest_64::run(int) { check_full(CV_64FC1); }
Core_EigenTest::Core_EigenTest()
: eps_val_32(1e-3f), eps_vec_32(1e-2f),
eps_val_64(1e-4f), eps_vec_64(1e-3f), ntests(100) {}
Core_EigenTest::~Core_EigenTest() {}
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index, int high_index)
{
int n = src.rows, s = sign(high_index);
if (!( (evalues.rows == n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)))) && (evalues.cols == 1)))
{
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return false;
}
return true;
}
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index, int high_index)
{
int n = src.rows, s = sign(high_index);
int right_eigen_pair_count = n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)));
if (!((evectors.rows == right_eigen_pair_count) && (evectors.cols == right_eigen_pair_count)))
{
std::cout << endl; std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl;
std::cout << "Number of rows: " << evectors.rows << " Number of cols: " << evectors.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_SIZE, MESSAGE_ERROR_SIZE);
return false;
}
if (!((evalues.rows == right_eigen_pair_count) && (evalues.cols == 1)))
{
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return false;
}
return true;
}
void Core_EigenTest::print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff)
{
switch (NORM_TYPE[norm_idx])
{
case cv::NORM_L1: {std::cout << "L1"; break;}
case cv::NORM_L2: {std::cout << "L2"; break;}
case cv::NORM_INF: {std::cout << "INF"; break;}
default: break;
}
cout << "-criteria... " << endl;
cout << "Source size: " << src.rows << " * " << src.cols << endl;
cout << "Difference between original eigen vectors matrix and result: " << diff << endl;
cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;
}
bool Core_EigenTest::check_orthogonality(const cv::Mat& U)
{
int type = U.type();
double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;
cv::Mat UUt; cv::mulTransposed(U, UUt, false);
cv::Mat E = Mat::eye(U.rows, U.cols, type);
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(UUt, E, NORM_TYPE[i]);
if (diff > eps_vec)
{
std::cout << endl; std::cout << "Checking orthogonality of matrix " << U << ": ";
print_information(i, U, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_ORTHO, MESSAGE_ERROR_ORTHO);
return false;
}
}
return true;
}
bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values)
{
switch (eigen_values.type())
{
case CV_32FC1:
{
for (int i = 0; i < (int)(eigen_values.total() - 1); ++i)
if (!(eigen_values.at<float>(i, 0) > eigen_values.at<float>(i+1, 0)))
{
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, MESSAGE_ERROR_ORDER);
return false;
}
break;
}
case CV_64FC1:
{
for (int i = 0; i < (int)(eigen_values.total() - 1); ++i)
if (!(eigen_values.at<double>(i, 0) > eigen_values.at<double>(i+1, 0)))
{
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order.");
return false;
}
break;
}
default:;
}
return true;
}
bool Core_EigenTest::test_pairs(const cv::Mat& src)
{
int type = src.type();
double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;
cv::Mat eigen_values, eigen_vectors;
cv::eigen(src, true, eigen_values, eigen_vectors);
if (!check_pair_count(src, eigen_values, eigen_vectors)) return false;
if (!check_orthogonality (eigen_vectors)) return false;
if (!check_pairs_order(eigen_values)) return false;
cv::Mat eigen_vectors_t; cv::transpose(eigen_vectors, eigen_vectors_t);
cv::Mat src_evec(src.rows, src.cols, type);
src_evec = src*eigen_vectors_t;
cv::Mat eval_evec(src.rows, src.cols, type);
switch (type)
{
case CV_32FC1:
{
for (int i = 0; i < src.cols; ++i)
{
cv::Mat tmp = eigen_values.at<float>(i, 0) * eigen_vectors_t.col(i);
for (int j = 0; j < src.rows; ++j) eval_evec.at<float>(j, i) = tmp.at<float>(j, 0);
}
break;
}
case CV_64FC1:
{
for (int i = 0; i < src.cols; ++i)
{
cv::Mat tmp = eigen_values.at<double>(i, 0) * eigen_vectors_t.col(i);
for (int j = 0; j < src.rows; ++j) eval_evec.at<double>(j, i) = tmp.at<double>(j, 0);
}
break;
}
default:;
}
cv::Mat disparity = src_evec - eval_evec;
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(disparity, NORM_TYPE[i]);
if (diff > eps_vec)
{
std::cout << endl; std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": ";
print_information(i, src, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_2);
return false;
}
}
return true;
}
bool Core_EigenTest::test_values(const cv::Mat& src)
{
int type = src.type();
double eps_val = type == CV_32FC1 ? eps_val_32 : eps_val_64;
cv::Mat eigen_values_1, eigen_values_2, eigen_vectors;
if (!test_pairs(src)) return false;
cv::eigen(src, true, eigen_values_1, eigen_vectors);
cv::eigen(src, false, eigen_values_2, eigen_vectors);
if (!check_pair_count(src, eigen_values_2)) return false;
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(eigen_values_1, eigen_values_2, NORM_TYPE[i]);
if (diff > eps_val)
{
std::cout << endl; std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": ";
print_information(i, src, diff, eps_val);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_1);
return false;
}
}
return true;
}
bool Core_EigenTest::check_full(int type)
{
const int MAX_DEGREE = 7;
srand((unsigned int)time(0));
for (int i = 0; i < ntests; ++i)
{
int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE)+1.));
cv::Mat src(src_size, src_size, type);
for (int j = 0; j < src.rows; ++j)
for (int k = j; k < src.cols; ++k)
if (type == CV_32FC1) src.at<float>(k, j) = src.at<float>(j, k) = cv::randu<float>();
else src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();
if (!test_values(src)) return false;
}
return true;
}
TEST(Core_Eigen, scalar_32) {Core_EigenTest_Scalar_32 test; test.safe_run(); }
TEST(Core_Eigen, scalar_64) {Core_EigenTest_Scalar_64 test; test.safe_run(); }
TEST(Core_Eigen, vector_32) { Core_EigenTest_32 test; test.safe_run(); }
TEST(Core_Eigen, vector_64) { Core_EigenTest_64 test; test.safe_run(); }
/*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 "test_precomp.hpp"
#include <time.h>
using namespace cv;
using namespace std;
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
#define CORE_EIGEN_ERROR_COUNT 1
#define CORE_EIGEN_ERROR_SIZE 2
#define CORE_EIGEN_ERROR_DIFF 3
#define CORE_EIGEN_ERROR_ORTHO 4
#define CORE_EIGEN_ERROR_ORDER 5
#define MESSAGE_ERROR_COUNT "Matrix of eigen values must have the same rows as source matrix and 1 column."
#define MESSAGE_ERROR_SIZE "Source matrix and matrix of eigen vectors must have the same sizes."
#define MESSAGE_ERROR_DIFF_1 "Accurasy of eigen values computing less than required."
#define MESSAGE_ERROR_DIFF_2 "Accuracy of eigen vectors computing less than required."
#define MESSAGE_ERROR_ORTHO "Matrix of eigen vectors is not orthogonal."
#define MESSAGE_ERROR_ORDER "Eigen values are not sorted in ascending order."
const int COUNT_NORM_TYPES = 3;
const int NORM_TYPE[COUNT_NORM_TYPES] = {cv::NORM_L1, cv::NORM_L2, cv::NORM_INF};
enum TASK_TYPE_EIGEN {VALUES, VECTORS};
class Core_EigenTest: public cvtest::BaseTest
{
public:
Core_EigenTest();
~Core_EigenTest();
protected:
bool test_values(const cv::Mat& src); // complex test for eigen without vectors
bool check_full(int type); // compex test for symmetric matrix
virtual void run (int) = 0; // main testing method
protected:
float eps_val_32, eps_vec_32;
float eps_val_64, eps_vec_64;
int ntests;
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);
bool check_pairs_order(const cv::Mat& eigen_values); // checking order of eigen values & vectors (it should be none up)
bool check_orthogonality(const cv::Mat& U); // checking is matrix of eigen vectors orthogonal
bool test_pairs(const cv::Mat& src); // complex test for eigen with vectors
void print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff);
};
class Core_EigenTest_Scalar : public Core_EigenTest
{
public:
Core_EigenTest_Scalar() : Core_EigenTest() {}
~Core_EigenTest_Scalar();
virtual void run(int) = 0;
};
class Core_EigenTest_Scalar_32 : public Core_EigenTest_Scalar
{
public:
Core_EigenTest_Scalar_32() : Core_EigenTest_Scalar() {}
~Core_EigenTest_Scalar_32();
void run(int);
};
class Core_EigenTest_Scalar_64 : public Core_EigenTest_Scalar
{
public:
Core_EigenTest_Scalar_64() : Core_EigenTest_Scalar() {}
~Core_EigenTest_Scalar_64();
void run(int);
};
class Core_EigenTest_32 : public Core_EigenTest
{
public:
Core_EigenTest_32(): Core_EigenTest() {}
~Core_EigenTest_32() {}
void run(int);
};
class Core_EigenTest_64 : public Core_EigenTest
{
public:
Core_EigenTest_64(): Core_EigenTest() {}
~Core_EigenTest_64() {}
void run(int);
};
Core_EigenTest_Scalar::~Core_EigenTest_Scalar() {}
Core_EigenTest_Scalar_32::~Core_EigenTest_Scalar_32() {}
Core_EigenTest_Scalar_64::~Core_EigenTest_Scalar_64() {}
void Core_EigenTest_Scalar_32::run(int)
{
for (int i = 0; i < ntests; ++i)
{
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));
test_values(src);
}
}
void Core_EigenTest_Scalar_64::run(int)
{
for (int i = 0; i < ntests; ++i)
{
float value = cv::randu<float>();
cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));
test_values(src);
}
}
void Core_EigenTest_32::run(int) { check_full(CV_32FC1); }
void Core_EigenTest_64::run(int) { check_full(CV_64FC1); }
Core_EigenTest::Core_EigenTest()
: eps_val_32(1e-3f), eps_vec_32(1e-2f),
eps_val_64(1e-4f), eps_vec_64(1e-3f), ntests(100) {}
Core_EigenTest::~Core_EigenTest() {}
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index, int high_index)
{
int n = src.rows, s = sign(high_index);
if (!( (evalues.rows == n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)))) && (evalues.cols == 1)))
{
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return false;
}
return true;
}
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index, int high_index)
{
int n = src.rows, s = sign(high_index);
int right_eigen_pair_count = n - max<int>(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1)));
if (!((evectors.rows == right_eigen_pair_count) && (evectors.cols == right_eigen_pair_count)))
{
std::cout << endl; std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl;
std::cout << "Number of rows: " << evectors.rows << " Number of cols: " << evectors.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_SIZE, MESSAGE_ERROR_SIZE);
return false;
}
if (!((evalues.rows == right_eigen_pair_count) && (evalues.cols == 1)))
{
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
return false;
}
return true;
}
void Core_EigenTest::print_information(const size_t norm_idx, const cv::Mat& src, double diff, double max_diff)
{
switch (NORM_TYPE[norm_idx])
{
case cv::NORM_L1: {std::cout << "L1"; break;}
case cv::NORM_L2: {std::cout << "L2"; break;}
case cv::NORM_INF: {std::cout << "INF"; break;}
default: break;
}
cout << "-criteria... " << endl;
cout << "Source size: " << src.rows << " * " << src.cols << endl;
cout << "Difference between original eigen vectors matrix and result: " << diff << endl;
cout << "Maximum allowed difference: " << max_diff << endl; cout << endl;
}
bool Core_EigenTest::check_orthogonality(const cv::Mat& U)
{
int type = U.type();
double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;
cv::Mat UUt; cv::mulTransposed(U, UUt, false);
cv::Mat E = Mat::eye(U.rows, U.cols, type);
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(UUt, E, NORM_TYPE[i]);
if (diff > eps_vec)
{
std::cout << endl; std::cout << "Checking orthogonality of matrix " << U << ": ";
print_information(i, U, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_ORTHO, MESSAGE_ERROR_ORTHO);
return false;
}
}
return true;
}
bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values)
{
switch (eigen_values.type())
{
case CV_32FC1:
{
for (int i = 0; i < (int)(eigen_values.total() - 1); ++i)
if (!(eigen_values.at<float>(i, 0) > eigen_values.at<float>(i+1, 0)))
{
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, MESSAGE_ERROR_ORDER);
return false;
}
break;
}
case CV_64FC1:
{
for (int i = 0; i < (int)(eigen_values.total() - 1); ++i)
if (!(eigen_values.at<double>(i, 0) > eigen_values.at<double>(i+1, 0)))
{
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order.");
return false;
}
break;
}
default:;
}
return true;
}
bool Core_EigenTest::test_pairs(const cv::Mat& src)
{
int type = src.type();
double eps_vec = type == CV_32FC1 ? eps_vec_32 : eps_vec_64;
cv::Mat eigen_values, eigen_vectors;
cv::eigen(src, true, eigen_values, eigen_vectors);
if (!check_pair_count(src, eigen_values, eigen_vectors)) return false;
if (!check_orthogonality (eigen_vectors)) return false;
if (!check_pairs_order(eigen_values)) return false;
cv::Mat eigen_vectors_t; cv::transpose(eigen_vectors, eigen_vectors_t);
cv::Mat src_evec(src.rows, src.cols, type);
src_evec = src*eigen_vectors_t;
cv::Mat eval_evec(src.rows, src.cols, type);
switch (type)
{
case CV_32FC1:
{
for (int i = 0; i < src.cols; ++i)
{
cv::Mat tmp = eigen_values.at<float>(i, 0) * eigen_vectors_t.col(i);
for (int j = 0; j < src.rows; ++j) eval_evec.at<float>(j, i) = tmp.at<float>(j, 0);
}
break;
}
case CV_64FC1:
{
for (int i = 0; i < src.cols; ++i)
{
cv::Mat tmp = eigen_values.at<double>(i, 0) * eigen_vectors_t.col(i);
for (int j = 0; j < src.rows; ++j) eval_evec.at<double>(j, i) = tmp.at<double>(j, 0);
}
break;
}
default:;
}
cv::Mat disparity = src_evec - eval_evec;
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(disparity, NORM_TYPE[i]);
if (diff > eps_vec)
{
std::cout << endl; std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": ";
print_information(i, src, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_2);
return false;
}
}
return true;
}
bool Core_EigenTest::test_values(const cv::Mat& src)
{
int type = src.type();
double eps_val = type == CV_32FC1 ? eps_val_32 : eps_val_64;
cv::Mat eigen_values_1, eigen_values_2, eigen_vectors;
if (!test_pairs(src)) return false;
cv::eigen(src, true, eigen_values_1, eigen_vectors);
cv::eigen(src, false, eigen_values_2, eigen_vectors);
if (!check_pair_count(src, eigen_values_2)) return false;
for (int i = 0; i < COUNT_NORM_TYPES; ++i)
{
double diff = cv::norm(eigen_values_1, eigen_values_2, NORM_TYPE[i]);
if (diff > eps_val)
{
std::cout << endl; std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": ";
print_information(i, src, diff, eps_val);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_1);
return false;
}
}
return true;
}
bool Core_EigenTest::check_full(int type)
{
const int MAX_DEGREE = 7;
srand((unsigned int)time(0));
for (int i = 0; i < ntests; ++i)
{
int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE)+1.));
cv::Mat src(src_size, src_size, type);
for (int j = 0; j < src.rows; ++j)
for (int k = j; k < src.cols; ++k)
if (type == CV_32FC1) src.at<float>(k, j) = src.at<float>(j, k) = cv::randu<float>();
else src.at<double>(k, j) = src.at<double>(j, k) = cv::randu<double>();
if (!test_values(src)) return false;
}
return true;
}
TEST(Core_Eigen, scalar_32) {Core_EigenTest_Scalar_32 test; test.safe_run(); }
TEST(Core_Eigen, scalar_64) {Core_EigenTest_Scalar_64 test; test.safe_run(); }
TEST(Core_Eigen, vector_32) { Core_EigenTest_32 test; test.safe_run(); }
TEST(Core_Eigen, vector_64) { Core_EigenTest_64 test; test.safe_run(); }
+5 -5
View File
@@ -424,17 +424,17 @@ protected:
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
return;
}
// 3. check C++ PCA w/retainedVariance
cPCA( rPoints.t(), Mat(), CV_PCA_DATA_AS_COL, retainedVariance );
diffPrjEps = 1, diffBackPrjEps = 1;
Mat rvPrjTestPoints = cPCA.project(rTestPoints.t());
Mat rvPrjTestPoints = cPCA.project(rTestPoints.t());
if( cPCA.eigenvectors.rows > maxComponents)
err = norm(cv::abs(rvPrjTestPoints.rowRange(0,maxComponents)), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 );
else
err = norm(cv::abs(rvPrjTestPoints), cv::abs(rPrjTestPoints.colRange(0,cPCA.eigenvectors.rows).t()), CV_RELATIVE_L2 );
if( err > diffPrjEps )
{
ts->printf( cvtest::TS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_COL); retainedVariance=0.95; err = %f\n", err );
@@ -448,7 +448,7 @@ protected:
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
return;
}
#ifdef CHECK_C
// 4. check C PCA & ROW
_points = rPoints;
File diff suppressed because it is too large Load Diff
+41 -41
View File
@@ -1,42 +1,42 @@
#include "test_precomp.hpp"
using namespace cv;
using namespace std;
TEST(Core_Drawing, _914)
{
const int rows = 256;
const int cols = 256;
Mat img(rows, cols, CV_8UC1, Scalar(255));
line(img, Point(0, 10), Point(255, 10), Scalar(0), 2, 4);
line(img, Point(-5, 20), Point(260, 20), Scalar(0), 2, 4);
line(img, Point(10, 0), Point(10, 255), Scalar(0), 2, 4);
double x0 = 0.0/pow(2.0, -2.0);
double x1 = 255.0/pow(2.0, -2.0);
double y = 30.5/pow(2.0, -2.0);
line(img, Point(int(x0), int(y)), Point(int(x1), int(y)), Scalar(0), 2, 4, 2);
int pixelsDrawn = rows*cols - countNonZero(img);
ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn);
}
TEST(Core_OutputArraySreate, _1997)
{
struct local {
static void create(OutputArray arr, Size submatSize, int type)
{
int sizes[] = {submatSize.width, submatSize.height};
arr.create(sizeof(sizes)/sizeof(sizes[0]), sizes, type);
}
};
Mat mat(Size(512, 512), CV_8U);
Size submatSize = Size(256, 256);
ASSERT_NO_THROW(local::create( mat(Rect(Point(), submatSize)), submatSize, mat.type() ));
#include "test_precomp.hpp"
using namespace cv;
using namespace std;
TEST(Core_Drawing, _914)
{
const int rows = 256;
const int cols = 256;
Mat img(rows, cols, CV_8UC1, Scalar(255));
line(img, Point(0, 10), Point(255, 10), Scalar(0), 2, 4);
line(img, Point(-5, 20), Point(260, 20), Scalar(0), 2, 4);
line(img, Point(10, 0), Point(10, 255), Scalar(0), 2, 4);
double x0 = 0.0/pow(2.0, -2.0);
double x1 = 255.0/pow(2.0, -2.0);
double y = 30.5/pow(2.0, -2.0);
line(img, Point(int(x0), int(y)), Point(int(x1), int(y)), Scalar(0), 2, 4, 2);
int pixelsDrawn = rows*cols - countNonZero(img);
ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn);
}
TEST(Core_OutputArraySreate, _1997)
{
struct local {
static void create(OutputArray arr, Size submatSize, int type)
{
int sizes[] = {submatSize.width, submatSize.height};
arr.create(sizeof(sizes)/sizeof(sizes[0]), sizes, type);
}
};
Mat mat(Size(512, 512), CV_8U);
Size submatSize = Size(256, 256);
ASSERT_NO_THROW(local::create( mat(Rect(Point(), submatSize)), submatSize, mat.type() ));
}
+182 -182
View File
@@ -57,9 +57,9 @@ class CV_OperationsTest : public cvtest::BaseTest
{
public:
CV_OperationsTest();
~CV_OperationsTest();
~CV_OperationsTest();
protected:
void run(int);
void run(int);
struct test_excep
{
@@ -116,7 +116,7 @@ template<typename _Tp> void CV_OperationsTest::TestType(Size sz, _Tp value)
for( int y = 0; y < sz.height; y++ )
for( int x = 0; x < sz.width; x++ )
m(y, x) = value;
CV_Assert( sum(m.reshape(1,1))[0] == (double)sz.width*sz.height );
}
@@ -131,8 +131,8 @@ bool CV_OperationsTest::TestMat()
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;
Mat res = one_3x1 + shi_3x1 + shi_3x1 + shi_3x1;
res = Mat(Mat(2 * rot_2x3) * res - shi_2x1) + shift;
Mat tmp, res2;
@@ -141,22 +141,22 @@ bool CV_OperationsTest::TestMat()
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())));
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);
@@ -183,7 +183,7 @@ bool CV_OperationsTest::TestMat()
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);
@@ -198,14 +198,14 @@ bool CV_OperationsTest::TestMat()
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));
@@ -216,7 +216,7 @@ bool CV_OperationsTest::TestMat()
CHECK_DIFF(maskMat0, (maskMat4 + maskMat1) ^ Scalar(5));
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ maskMat1));
CHECK_DIFF(maskMat5, (maskMat4 ^ maskMat1) | maskMat5);
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));
@@ -234,9 +234,9 @@ bool CV_OperationsTest::TestMat()
CHECK_DIFF(maskMat5, max(maskMat1, maskMat5 | maskMat5));
CHECK_DIFF(~maskMat1, maskMat1 ^ -1);
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ -1);
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ -1);
CHECK_DIFF(maskMat1, maskMat4/4.0);
CHECK_DIFF(maskMat1, maskMat4/4.0);
/////////////////////////////
@@ -251,33 +251,33 @@ bool CV_OperationsTest::TestMat()
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) * (-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((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);
@@ -287,7 +287,7 @@ bool CV_OperationsTest::TestMat()
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);
@@ -298,9 +298,9 @@ bool CV_OperationsTest::TestMat()
#endif
CHECK_DIFF((maskMat4 / 2.0) / 2.0 , maskMat1);
CHECK_DIFF(-(maskMat4 - maskMat5) , maskMat1);
CHECK_DIFF(-((maskMat4 - maskMat5) * 1.0), maskMat1);
CHECK_DIFF(-((maskMat4 - maskMat5) * 1.0), maskMat1);
/////////////////////////////
CHECK_DIFF(maskMat4 / maskMat4, maskMat1);
@@ -312,7 +312,7 @@ bool CV_OperationsTest::TestMat()
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);
@@ -328,8 +328,8 @@ bool CV_OperationsTest::TestMat()
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 / maskMat4, maskMat1);
CHECK_DIFF(4.0 / (maskMat4 | maskMat4), maskMat1);
CHECK_DIFF(4.0 / (maskMat1 * 4.0), maskMat1);
CHECK_DIFF(4.0 / (maskMat4 / maskMat1), maskMat1);
@@ -337,9 +337,9 @@ bool CV_OperationsTest::TestMat()
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};
/////////////////////////////
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);
@@ -369,13 +369,13 @@ bool CV_OperationsTest::TestMat()
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( mi * (2 * mt), d2);
CHECK_DIFF_FLT( mt.t() * mi_tr, d1 );
CHECK_DIFF_FLT( mt_tr * mi.t(), 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_tr * 2) * mi.t(), d2 );
CHECK_DIFF_FLT(mt.t() * mi.t(), d1);
CHECK_DIFF_FLT( (mi * mt) * 2.0, d2);
@@ -386,9 +386,9 @@ bool CV_OperationsTest::TestMat()
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( 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
@@ -405,7 +405,7 @@ bool CV_OperationsTest::TestMat()
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( 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);
@@ -417,7 +417,7 @@ bool CV_OperationsTest::TestMat()
CHECK_DIFF_FLT(mt.inv() * mt, d1);
CHECK_DIFF_FLT(mt.inv() * (2*mt - mt), d1);
CHECK_DIFF_FLT(mt.inv() * (2*mt - mt), d1);
#endif
}
catch (const test_excep& e)
@@ -435,18 +435,18 @@ bool CV_OperationsTest::SomeMatFunctions()
{
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 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 );
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);
CHECK_DIFF(bgr_exp, bgr);
CHECK_DIFF(alpha_exp, alpha);
}
catch (const test_excep& e)
{
@@ -477,7 +477,7 @@ bool CV_OperationsTest::TestSubMatAccess()
// set up display coords, really just the S frame
std::vector<float>coords;
for (int i=0; i<16; i++)
{
coords.push_back(T_bs(i));
@@ -495,7 +495,7 @@ bool CV_OperationsTest::TestSubMatAccess()
}
bool CV_OperationsTest::TestTemplateMat()
{
{
try
{
Mat_<float> one_3x1(3, 1, 1.0f);
@@ -505,7 +505,7 @@ bool CV_OperationsTest::TestTemplateMat()
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;
@@ -515,25 +515,25 @@ bool CV_OperationsTest::TestTemplateMat()
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(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())));
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);
@@ -551,17 +551,17 @@ bool CV_OperationsTest::TestTemplateMat()
Mat_<uchar> maskMat5(3, 3, 5);
Mat_<uchar> maskMat0(3, 3, (uchar)0);
CHECK_DIFF(maskMat0, maskMat4 & maskMat1);
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));
@@ -573,7 +573,7 @@ bool CV_OperationsTest::TestTemplateMat()
CHECK_DIFF(maskMat5, maskMat5 | (maskMat4 ^ Scalar(1)));
CHECK_DIFF(~maskMat1, maskMat1 ^ 0xFF);
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ 0xFF);
CHECK_DIFF(~(maskMat1 | maskMat1), maskMat1 ^ 0xFF);
CHECK_DIFF(maskMat1 + maskMat4, maskMat5);
CHECK_DIFF(maskMat1 + Scalar(4), maskMat5);
@@ -597,7 +597,7 @@ bool CV_OperationsTest::TestTemplateMat()
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);
@@ -605,31 +605,31 @@ bool CV_OperationsTest::TestTemplateMat()
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);
CHECK_DIFF(maskMat1, maskMat4/4.0);
Mat_<float> negf(3, 3, -3.0);
Mat_<float> negf(3, 3, -3.0);
Mat_<float> posf = -negf;
Mat_<float> posf2 = posf * 2;
Mat_<int> negi(3, 3, -3);
Mat_<int> negi(3, 3, -3);
CHECK_DIFF(abs(negf), -negf);
CHECK_DIFF(abs(posf - posf2), -negf);
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;
@@ -638,7 +638,7 @@ bool CV_OperationsTest::TestTemplateMat()
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();
@@ -654,14 +654,14 @@ bool CV_OperationsTest::TestTemplateMat()
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_<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();
@@ -671,10 +671,10 @@ bool CV_OperationsTest::TestTemplateMat()
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)));
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);
@@ -692,22 +692,22 @@ bool CV_OperationsTest::TestTemplateMat()
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>::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>::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&)
@@ -716,7 +716,7 @@ bool CV_OperationsTest::TestTemplateMat()
///////////////////////////////
float matrix_data[] = { 3, 1, -4, -5, 1, 0, 0, 1.1f, 1.5f};
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);
@@ -764,7 +764,7 @@ bool CV_OperationsTest::TestTemplateMat()
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();
vector<Mat_<float> > mvf, mvf2;
Mat_<Vec2f> mf2;
mvf.push_back(Mat_<float>::ones(4, 3));
@@ -773,14 +773,14 @@ bool CV_OperationsTest::TestTemplateMat()
split(mf2, mvf2);
CV_Assert( norm(mvf2[0], mvf[0], CV_C) == 0 &&
norm(mvf2[1], mvf[1], CV_C) == 0 );
{
Mat a(2,2,CV_32F,1.f);
Mat b(1,2,CV_32F,1.f);
Mat c = (a*b.t()).t();
CV_Assert( norm(c, CV_L1) == 4. );
}
bool badarg_catched = false;
try
{
@@ -793,10 +793,10 @@ bool CV_OperationsTest::TestTemplateMat()
badarg_catched = true;
}
CV_Assert( badarg_catched );
#include <iostream>
#include <opencv2/core/core.hpp>
Size size(2, 5);
TestType<float>(size);
TestType<cv::Vec3f>(size);
@@ -814,7 +814,7 @@ bool CV_OperationsTest::TestTemplateMat()
}
bool CV_OperationsTest::TestMatND()
{
{
int sizes[] = { 3, 3, 3};
cv::MatND nd(3, sizes, CV_32F);
@@ -822,7 +822,7 @@ bool CV_OperationsTest::TestMatND()
}
bool CV_OperationsTest::TestSparseMat()
{
{
try
{
int sizes[] = { 10, 10, 10};
@@ -844,62 +844,62 @@ bool CV_OperationsTest::TestSparseMat()
}
bool CV_OperationsTest::TestMatxMultiplication()
{
try
{
Matx33f mat(1, 1, 1, 0, 1, 1, 0, 0, 1); // Identity matrix
Point2f pt(3, 4);
Point3f res = mat * pt; // Correctly assumes homogeneous coordinates
bool CV_OperationsTest::TestMatxMultiplication()
{
try
{
Matx33f mat(1, 1, 1, 0, 1, 1, 0, 0, 1); // Identity matrix
Point2f pt(3, 4);
Point3f res = mat * pt; // Correctly assumes homogeneous coordinates
Vec3f res2 = mat*Vec3f(res.x, res.y, res.z);
if(res.x != 8.0) throw test_excep();
if(res.y != 5.0) throw test_excep();
if(res.x != 8.0) throw test_excep();
if(res.y != 5.0) throw test_excep();
if(res.z != 1.0) throw test_excep();
if(res2[0] != 14.0) throw test_excep();
if(res2[1] != 6.0) throw test_excep();
if(res2[0] != 14.0) throw test_excep();
if(res2[1] != 6.0) throw test_excep();
if(res2[2] != 1.0) throw test_excep();
Matx44f mat44f(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1);
Matx44d mat44d(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1);
Scalar s(4, 3, 2, 1);
Scalar sf = mat44f*s;
Scalar sd = mat44d*s;
if(sf[0] != 10.0) throw test_excep();
if(sf[1] != 6.0) throw test_excep();
if(sf[0] != 10.0) throw test_excep();
if(sf[1] != 6.0) throw test_excep();
if(sf[2] != 3.0) throw test_excep();
if(sf[3] != 1.0) throw test_excep();
if(sd[0] != 10.0) throw test_excep();
if(sd[1] != 6.0) throw test_excep();
if(sd[0] != 10.0) throw test_excep();
if(sd[1] != 6.0) throw test_excep();
if(sd[2] != 3.0) throw test_excep();
if(sd[3] != 1.0) throw test_excep();
}
catch(const test_excep&)
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return false;
}
return true;
}
}
catch(const test_excep&)
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return false;
}
return true;
}
bool CV_OperationsTest::TestVec()
{
try
{
bool CV_OperationsTest::TestVec()
{
try
{
cv::Mat hsvImage_f(5, 5, CV_32FC3), hsvImage_b(5, 5, CV_8UC3);
int i = 0,j = 0;
cv::Vec3f a;
//these compile
cv::Vec3b b = a;
hsvImage_f.at<cv::Vec3f>(i,j) = cv::Vec3f((float)i,0,1);
hsvImage_b.at<cv::Vec3b>(i,j) = cv::Vec3b(cv::Vec3f((float)i,0,1));
//these don't
b = cv::Vec3f(1,0,0);
cv::Vec3b c;
@@ -907,37 +907,37 @@ bool CV_OperationsTest::TestVec()
hsvImage_b.at<cv::Vec3b>(i,j) = cv::Vec3f((float)i,0,1);
hsvImage_b.at<cv::Vec3b>(i,j) = a;
hsvImage_b.at<cv::Vec3b>(i,j) = cv::Vec3f(1,2,3);
}
catch(const test_excep&)
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return false;
}
return true;
}
}
catch(const test_excep&)
{
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return false;
}
return true;
}
bool CV_OperationsTest::operations1()
{
try
{
try
{
Point3d p1(1, 1, 1), p2(2, 2, 2), p4(4, 4, 4);
p1*=2;
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);
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();
@@ -945,12 +945,12 @@ bool CV_OperationsTest::operations1()
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);
@@ -963,26 +963,26 @@ bool CV_OperationsTest::operations1()
if (!v10dzero[ii] == 0.0)
throw test_excep();
}
Mat A(1, 32, CV_32F), B;
for( int i = 0; i < A.cols; i++ )
A.at<float>(i) = (float)(i <= 12 ? i : 24 - i);
transpose(A, B);
int minidx[2] = {0, 0}, maxidx[2] = {0, 0};
double minval = 0, maxval = 0;
minMaxIdx(A, &minval, &maxval, minidx, maxidx);
if( !(minidx[0] == 0 && minidx[1] == 31 && maxidx[0] == 0 && maxidx[1] == 12 &&
minval == -7 && maxval == 12))
throw test_excep();
minMaxIdx(B, &minval, &maxval, minidx, maxidx);
if( !(minidx[0] == 31 && minidx[1] == 0 && maxidx[0] == 12 && maxidx[1] == 0 &&
minval == -7 && maxval == 12))
throw test_excep();
Matx33f b(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f);
Mat c;
add(Mat::zeros(3, 3, CV_32F), b, c);
@@ -1004,8 +1004,8 @@ bool CV_OperationsTest::operations1()
bool CV_OperationsTest::TestSVD()
{
try
{
try
{
Mat A = (Mat_<double>(3,4) << 1, 2, -1, 4, 2, 4, 3, 5, -1, -2, 6, 7);
Mat x;
@@ -1013,23 +1013,23 @@ bool CV_OperationsTest::TestSVD()
if( norm(A*x, CV_C) > FLT_EPSILON )
throw test_excep();
SVD svd(A, SVD::FULL_UV);
SVD svd(A, SVD::FULL_UV);
if( norm(A*svd.vt.row(3).t(), CV_C) > FLT_EPSILON )
throw test_excep();
Mat Dp(3,3,CV_32FC1);
Mat Dc(3,3,CV_32FC1);
Mat Q(3,3,CV_32FC1);
Mat U,Vt,R,T,W;
Dp.at<float>(0,0)=0.86483884f; Dp.at<float>(0,1)= -0.3077251f; Dp.at<float>(0,2)=-0.55711365f;
Dp.at<float>(1,0)=0.49294353f; Dp.at<float>(1,1)=-0.24209651f; Dp.at<float>(1,2)=-0.25084701f;
Dp.at<float>(2,0)=0; Dp.at<float>(2,1)=0; Dp.at<float>(2,2)=0;
Dc.at<float>(0,0)=0.75632739f; Dc.at<float>(0,1)= -0.38859656f; Dc.at<float>(0,2)=-0.36773083f;
Dc.at<float>(1,0)=0.9699229f; Dc.at<float>(1,1)=-0.49858192f; Dc.at<float>(1,2)=-0.47134098f;
Dc.at<float>(2,0)=0.10566688f; Dc.at<float>(2,1)=-0.060333252f; Dc.at<float>(2,2)=-0.045333147f;
Q=Dp*Dc.t();
SVD decomp;
decomp=SVD(Q);
@@ -1037,7 +1037,7 @@ bool CV_OperationsTest::TestSVD()
Vt=decomp.vt;
W=decomp.w;
Mat I = Mat::eye(3, 3, CV_32F);
if( norm(U*U.t(), I, CV_C) > FLT_EPSILON ||
norm(Vt*Vt.t(), I, CV_C) > FLT_EPSILON ||
W.at<float>(2) < 0 || W.at<float>(1) < W.at<float>(2) ||
@@ -1069,16 +1069,16 @@ void CV_OperationsTest::run( int /* start_from */)
if (!TestSparseMat())
return;
if (!TestVec())
return;
if (!TestMatxMultiplication())
return;
if (!TestSubMatAccess())
return;
if (!TestSVD())
return;
@@ -1094,7 +1094,7 @@ class CV_SparseMatTest : public cvtest::BaseTest
{
public:
CV_SparseMatTest() {}
~CV_SparseMatTest() {}
~CV_SparseMatTest() {}
protected:
void run(int)
{
@@ -1115,16 +1115,16 @@ protected:
}
int j, nz = rng.uniform(0, (p+2)/2), nz0 = 0;
SparseMat_<int> v(dims,sizes);
CV_Assert( (int)v.nzcount() == 0 );
SparseMatIterator_<int> it = v.begin();
SparseMatIterator_<int> it_end = v.end();
for( k = 0; it != it_end; ++it, ++k )
;
CV_Assert( k == 0 );
int sum0 = 0, sum = 0;
for( j = 0; j < nz; j++ )
{
@@ -1149,22 +1149,22 @@ protected:
nz0++;
sum0 += val;
}
CV_Assert( (int)v.nzcount() == nz0 );
it = v.begin();
it_end = v.end();
for( k = 0; it != it_end; ++it, ++k )
sum += *it;
CV_Assert( k == nz0 && sum == sum0 );
v.clear();
CV_Assert( (int)v.nzcount() == 0 );
it = v.begin();
it_end = v.end();
for( k = 0; it != it_end; ++it, ++k )
;
CV_Assert( k == 0 );