mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Normalize line endings and whitespace
This commit is contained in:
committed by
Andrey Kamaev
parent
69020da607
commit
04384a71e4
@@ -49,7 +49,7 @@ using namespace std;
|
||||
// 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)
|
||||
@@ -177,7 +177,7 @@ int CV_ApproxPolyTest::check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
double sin_a = 0;
|
||||
double cos_a = 0;
|
||||
double d = 0;
|
||||
double dist;
|
||||
double dist;
|
||||
///////////
|
||||
int j, TotalErrors = 0;
|
||||
|
||||
@@ -193,7 +193,7 @@ int CV_ApproxPolyTest::check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
|
||||
dx = (double)StartPt.x - (double)EndPt.x;
|
||||
dy = (double)StartPt.y - (double)EndPt.y;
|
||||
|
||||
|
||||
if( ( dx == 0 ) && ( dy == 0 ) ) flag = false;
|
||||
else
|
||||
{
|
||||
@@ -270,7 +270,7 @@ int CV_ApproxPolyTest::check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps )
|
||||
{
|
||||
TotalErrors++;
|
||||
return TotalErrors;
|
||||
} //if( !flag )
|
||||
} //if( !flag )
|
||||
|
||||
} // for( int i = 0 ; i < DstSeq->total ; i++ )
|
||||
|
||||
@@ -283,7 +283,7 @@ int CV_ApproxPolyTest::check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps )
|
||||
void CV_ApproxPolyTest::run( int /*start_from*/ )
|
||||
{
|
||||
int code = cvtest::TS::OK;
|
||||
CvMemStorage* storage = 0;
|
||||
CvMemStorage* storage = 0;
|
||||
////////////// Variables ////////////////
|
||||
int IntervalsCount = 10;
|
||||
///////////
|
||||
@@ -296,42 +296,42 @@ void CV_ApproxPolyTest::run( int /*start_from*/ )
|
||||
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);
|
||||
|
||||
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 );
|
||||
|
||||
cvSaveMemStoragePos( storage, &pos );
|
||||
|
||||
////////// call function ////////////
|
||||
DstSeq = cvApproxPoly( SrcSeq, SrcSeq->header_size, storage,
|
||||
DstSeq = cvApproxPoly( SrcSeq, SrcSeq->header_size, storage,
|
||||
CV_POLY_APPROX_DP, Eps );
|
||||
|
||||
if( DstSeq == NULL )
|
||||
|
||||
if( DstSeq == NULL )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"cvApproxPoly returned NULL for contour #%d, espilon = %g\n", i, Eps );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
} // if( DstSeq == NULL )
|
||||
|
||||
|
||||
code = check( SrcSeq, DstSeq, Eps );
|
||||
if( code != 0 )
|
||||
{
|
||||
@@ -340,10 +340,10 @@ void CV_ApproxPolyTest::run( int /*start_from*/ )
|
||||
code = cvtest::TS::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++ )
|
||||
|
||||
@@ -44,16 +44,16 @@
|
||||
|
||||
using namespace cv;
|
||||
|
||||
namespace cvtest
|
||||
{
|
||||
class CV_BilateralFilterTest :
|
||||
namespace cvtest
|
||||
{
|
||||
class CV_BilateralFilterTest :
|
||||
public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
enum
|
||||
enum
|
||||
{
|
||||
MAX_WIDTH = 1920, MIN_WIDTH = 1,
|
||||
MAX_HEIGHT = 1080, MIN_HEIGHT = 1
|
||||
MAX_HEIGHT = 1080, MIN_HEIGHT = 1
|
||||
};
|
||||
|
||||
CV_BilateralFilterTest();
|
||||
@@ -63,22 +63,22 @@ namespace cvtest
|
||||
virtual void run_func();
|
||||
virtual int prepare_test_case(int test_case_index);
|
||||
virtual int validate_test_results(int test_case_index);
|
||||
|
||||
|
||||
private:
|
||||
void reference_bilateral_filter(const Mat& src, Mat& dst, int d, double sigma_color,
|
||||
double sigma_space, int borderType = BORDER_DEFAULT);
|
||||
|
||||
|
||||
int getRandInt(RNG& rng, int min_value, int max_value) const;
|
||||
|
||||
|
||||
double _sigma_color;
|
||||
double _sigma_space;
|
||||
|
||||
|
||||
Mat _src;
|
||||
Mat _parallel_dst;
|
||||
int _d;
|
||||
};
|
||||
|
||||
CV_BilateralFilterTest::CV_BilateralFilterTest() :
|
||||
CV_BilateralFilterTest::CV_BilateralFilterTest() :
|
||||
cvtest::BaseTest(), _src(), _parallel_dst(), _d()
|
||||
{
|
||||
test_case_count = 1000;
|
||||
@@ -94,7 +94,7 @@ namespace cvtest
|
||||
return cvRound(exp((double)rand_value));
|
||||
}
|
||||
|
||||
void CV_BilateralFilterTest::reference_bilateral_filter(const Mat &src, Mat &dst, int d,
|
||||
void CV_BilateralFilterTest::reference_bilateral_filter(const Mat &src, Mat &dst, int d,
|
||||
double sigma_color, double sigma_space, int borderType)
|
||||
{
|
||||
int cn = src.channels();
|
||||
@@ -237,22 +237,22 @@ namespace cvtest
|
||||
RNG& rng = ts->get_rng();
|
||||
Size size(getRandInt(rng, MIN_WIDTH, MAX_WIDTH), getRandInt(rng, MIN_HEIGHT, MAX_HEIGHT));
|
||||
int type = types[rng(sizeof(types) / sizeof(types[0]))];
|
||||
|
||||
_d = rng.uniform(0., 1.) > 0.5 ? 5 : 3;
|
||||
|
||||
|
||||
_d = rng.uniform(0., 1.) > 0.5 ? 5 : 3;
|
||||
|
||||
_src.create(size, type);
|
||||
|
||||
|
||||
rng.fill(_src, RNG::UNIFORM, 0, 256);
|
||||
|
||||
|
||||
_sigma_color = _sigma_space = 1.;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CV_BilateralFilterTest::validate_test_results(int test_case_index)
|
||||
{
|
||||
static const double eps = 1;
|
||||
|
||||
|
||||
Mat reference_dst, reference_src;
|
||||
if (_src.depth() == CV_32F)
|
||||
reference_bilateral_filter(_src, reference_dst, _d, _sigma_color, _sigma_space);
|
||||
@@ -263,7 +263,7 @@ namespace cvtest
|
||||
reference_bilateral_filter(reference_src, reference_dst, _d, _sigma_color, _sigma_space);
|
||||
reference_dst.convertTo(reference_dst, type);
|
||||
}
|
||||
|
||||
|
||||
double e = norm(reference_dst, _parallel_dst);
|
||||
if (e > eps)
|
||||
{
|
||||
@@ -272,7 +272,7 @@ namespace cvtest
|
||||
}
|
||||
else
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
|
||||
return BaseTest::validate_test_results(test_case_index);
|
||||
}
|
||||
|
||||
@@ -282,9 +282,9 @@ namespace cvtest
|
||||
}
|
||||
|
||||
TEST(Imgproc_BilateralFilter, accuracy)
|
||||
{
|
||||
CV_BilateralFilterTest test;
|
||||
test.safe_run();
|
||||
{
|
||||
CV_BilateralFilterTest test;
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
} // end of namespace cvtest
|
||||
|
||||
@@ -1,144 +1,144 @@
|
||||
/*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>
|
||||
|
||||
#define IMGPROC_BOUNDINGRECT_ERROR_DIFF 1
|
||||
|
||||
#define MESSAGE_ERROR_DIFF "Bounding rectangle found by boundingRect function is incorrect."
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_BoundingRectTest: public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_BoundingRectTest();
|
||||
~CV_BoundingRectTest();
|
||||
|
||||
protected:
|
||||
void run (int);
|
||||
|
||||
private:
|
||||
template <typename T> void generate_src_points(vector <Point_<T> >& src, int n);
|
||||
template <typename T> cv::Rect get_bounding_rect(const vector <Point_<T> > src);
|
||||
template <typename T> bool checking_function_work(vector <Point_<T> >& src, int type);
|
||||
};
|
||||
|
||||
CV_BoundingRectTest::CV_BoundingRectTest() {}
|
||||
CV_BoundingRectTest::~CV_BoundingRectTest() {}
|
||||
|
||||
template <typename T> void CV_BoundingRectTest::generate_src_points(vector <Point_<T> >& src, int n)
|
||||
{
|
||||
src.clear();
|
||||
for (int i = 0; i < n; ++i)
|
||||
src.push_back(Point_<T>(cv::randu<T>(), cv::randu<T>()));
|
||||
}
|
||||
|
||||
template <typename T> cv::Rect CV_BoundingRectTest::get_bounding_rect(const vector <Point_<T> > src)
|
||||
{
|
||||
int n = (int)src.size();
|
||||
T min_w = std::numeric_limits<T>::max(), max_w = std::numeric_limits<T>::min();
|
||||
T min_h = min_w, max_h = max_w;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
min_w = std::min<T>(src.at(i).x, min_w);
|
||||
max_w = std::max<T>(src.at(i).x, max_w);
|
||||
min_h = std::min<T>(src.at(i).y, min_h);
|
||||
max_h = std::max<T>(src.at(i).y, max_h);
|
||||
}
|
||||
|
||||
return Rect((int)min_w, (int)min_h, (int)max_w-(int)min_w + 1, (int)max_h-(int)min_h + 1);
|
||||
}
|
||||
|
||||
template <typename T> bool CV_BoundingRectTest::checking_function_work(vector <Point_<T> >& src, int type)
|
||||
{
|
||||
const int MAX_COUNT_OF_POINTS = 1000;
|
||||
const int N = 10000;
|
||||
|
||||
for (int k = 0; k < N; ++k)
|
||||
{
|
||||
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
int n = rng.next()%MAX_COUNT_OF_POINTS + 1;
|
||||
|
||||
generate_src_points <T> (src, n);
|
||||
|
||||
cv::Rect right = get_bounding_rect <T> (src);
|
||||
|
||||
cv::Rect rect[2] = { boundingRect(src), boundingRect(Mat(src)) };
|
||||
|
||||
for (int i = 0; i < 2; ++i) if (rect[i] != right)
|
||||
{
|
||||
cout << endl; cout << "Checking for the work of boundingRect function..." << endl;
|
||||
cout << "Type of src points: ";
|
||||
switch (type)
|
||||
{
|
||||
case 0: {cout << "INT"; break;}
|
||||
case 1: {cout << "FLOAT"; break;}
|
||||
default: break;
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Src points are stored as "; if (i == 0) cout << "VECTOR" << endl; else cout << "MAT" << endl;
|
||||
cout << "Number of points: " << n << endl;
|
||||
cout << "Right rect (x, y, w, h): [" << right.x << ", " << right.y << ", " << right.width << ", " << right.height << "]" << endl;
|
||||
cout << "Result rect (x, y, w, h): [" << rect[i].x << ", " << rect[i].y << ", " << rect[i].width << ", " << rect[i].height << "]" << endl;
|
||||
cout << endl;
|
||||
CV_Error(IMGPROC_BOUNDINGRECT_ERROR_DIFF, MESSAGE_ERROR_DIFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_BoundingRectTest::run(int)
|
||||
{
|
||||
vector <Point> src_veci; if (!checking_function_work(src_veci, 0)) return;
|
||||
vector <Point2f> src_vecf; checking_function_work(src_vecf, 1);
|
||||
}
|
||||
|
||||
TEST (Imgproc_BoundingRect, accuracy) { CV_BoundingRectTest 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>
|
||||
|
||||
#define IMGPROC_BOUNDINGRECT_ERROR_DIFF 1
|
||||
|
||||
#define MESSAGE_ERROR_DIFF "Bounding rectangle found by boundingRect function is incorrect."
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
class CV_BoundingRectTest: public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_BoundingRectTest();
|
||||
~CV_BoundingRectTest();
|
||||
|
||||
protected:
|
||||
void run (int);
|
||||
|
||||
private:
|
||||
template <typename T> void generate_src_points(vector <Point_<T> >& src, int n);
|
||||
template <typename T> cv::Rect get_bounding_rect(const vector <Point_<T> > src);
|
||||
template <typename T> bool checking_function_work(vector <Point_<T> >& src, int type);
|
||||
};
|
||||
|
||||
CV_BoundingRectTest::CV_BoundingRectTest() {}
|
||||
CV_BoundingRectTest::~CV_BoundingRectTest() {}
|
||||
|
||||
template <typename T> void CV_BoundingRectTest::generate_src_points(vector <Point_<T> >& src, int n)
|
||||
{
|
||||
src.clear();
|
||||
for (int i = 0; i < n; ++i)
|
||||
src.push_back(Point_<T>(cv::randu<T>(), cv::randu<T>()));
|
||||
}
|
||||
|
||||
template <typename T> cv::Rect CV_BoundingRectTest::get_bounding_rect(const vector <Point_<T> > src)
|
||||
{
|
||||
int n = (int)src.size();
|
||||
T min_w = std::numeric_limits<T>::max(), max_w = std::numeric_limits<T>::min();
|
||||
T min_h = min_w, max_h = max_w;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
min_w = std::min<T>(src.at(i).x, min_w);
|
||||
max_w = std::max<T>(src.at(i).x, max_w);
|
||||
min_h = std::min<T>(src.at(i).y, min_h);
|
||||
max_h = std::max<T>(src.at(i).y, max_h);
|
||||
}
|
||||
|
||||
return Rect((int)min_w, (int)min_h, (int)max_w-(int)min_w + 1, (int)max_h-(int)min_h + 1);
|
||||
}
|
||||
|
||||
template <typename T> bool CV_BoundingRectTest::checking_function_work(vector <Point_<T> >& src, int type)
|
||||
{
|
||||
const int MAX_COUNT_OF_POINTS = 1000;
|
||||
const int N = 10000;
|
||||
|
||||
for (int k = 0; k < N; ++k)
|
||||
{
|
||||
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
int n = rng.next()%MAX_COUNT_OF_POINTS + 1;
|
||||
|
||||
generate_src_points <T> (src, n);
|
||||
|
||||
cv::Rect right = get_bounding_rect <T> (src);
|
||||
|
||||
cv::Rect rect[2] = { boundingRect(src), boundingRect(Mat(src)) };
|
||||
|
||||
for (int i = 0; i < 2; ++i) if (rect[i] != right)
|
||||
{
|
||||
cout << endl; cout << "Checking for the work of boundingRect function..." << endl;
|
||||
cout << "Type of src points: ";
|
||||
switch (type)
|
||||
{
|
||||
case 0: {cout << "INT"; break;}
|
||||
case 1: {cout << "FLOAT"; break;}
|
||||
default: break;
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Src points are stored as "; if (i == 0) cout << "VECTOR" << endl; else cout << "MAT" << endl;
|
||||
cout << "Number of points: " << n << endl;
|
||||
cout << "Right rect (x, y, w, h): [" << right.x << ", " << right.y << ", " << right.width << ", " << right.height << "]" << endl;
|
||||
cout << "Result rect (x, y, w, h): [" << rect[i].x << ", " << rect[i].y << ", " << rect[i].width << ", " << rect[i].height << "]" << endl;
|
||||
cout << endl;
|
||||
CV_Error(IMGPROC_BOUNDINGRECT_ERROR_DIFF, MESSAGE_ERROR_DIFF);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_BoundingRectTest::run(int)
|
||||
{
|
||||
vector <Point> src_veci; if (!checking_function_work(src_veci, 0)) return;
|
||||
vector <Point2f> src_vecf; checking_function_work(src_vecf, 1);
|
||||
}
|
||||
|
||||
TEST (Imgproc_BoundingRect, accuracy) { CV_BoundingRectTest test; test.safe_run(); }
|
||||
|
||||
@@ -193,13 +193,13 @@ test_Canny( const Mat& src, Mat& dst,
|
||||
{
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
|
||||
|
||||
float a = mag.at<float>(y, x), b = 0, c = 0;
|
||||
int y1 = 0, y2 = 0, x1 = 0, x2 = 0;
|
||||
|
||||
if( a <= lowThreshold )
|
||||
continue;
|
||||
|
||||
|
||||
int dxval = dx.at<short>(y, x);
|
||||
int dyval = dy.at<short>(y, x);
|
||||
|
||||
@@ -259,18 +259,18 @@ int CV_CannyTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::TS::OK, nz0;
|
||||
prepare_to_validation(test_case_idx);
|
||||
|
||||
|
||||
double err = cvtest::norm(test_mat[OUTPUT][0], test_mat[REF_OUTPUT][0], CV_L1);
|
||||
if( err == 0 )
|
||||
return code;
|
||||
|
||||
|
||||
if( err != cvRound(err) || cvRound(err)%255 != 0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "Some of the pixels, produced by Canny, are not 0's or 255's; the difference is %g\n", err );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
nz0 = cvRound(cvtest::norm(test_mat[REF_OUTPUT][0], CV_L1)/255);
|
||||
err = (err/255/MAX(nz0,100))*100;
|
||||
if( err > 1 )
|
||||
@@ -278,7 +278,7 @@ int CV_CannyTest::validate_test_results( int test_case_idx )
|
||||
ts->printf( cvtest::TS::LOG, "Too high percentage of non-matching edge pixels = %g%%\n", err);
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,12 +159,12 @@ void CV_ColorCvtBaseTest::run_func()
|
||||
{
|
||||
CvArr* out0 = test_array[OUTPUT][0];
|
||||
cv::Mat _out0 = cv::cvarrToMat(out0), _out1 = cv::cvarrToMat(test_array[OUTPUT][1]);
|
||||
|
||||
|
||||
if(!test_cpp)
|
||||
cvCvtColor( inplace ? out0 : test_array[INPUT][0], out0, fwd_code );
|
||||
else
|
||||
cv::cvtColor( cv::cvarrToMat(inplace ? out0 : test_array[INPUT][0]), _out0, fwd_code, _out0.channels());
|
||||
|
||||
|
||||
if( inplace )
|
||||
{
|
||||
cvCopy( out0, test_array[OUTPUT][1] );
|
||||
@@ -189,7 +189,7 @@ void CV_ColorCvtBaseTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
uchar* h0 = test_mat[REF_OUTPUT][0].ptr(y);
|
||||
uchar* h = test_mat[OUTPUT][0].ptr(y);
|
||||
|
||||
|
||||
for( int x = 0; x < test_mat[REF_OUTPUT][0].cols; x++, h0 += 3, h += 3 )
|
||||
{
|
||||
if( abs(*h - *h0) >= hue_range-1 && (*h <= 1 || *h0 <= 1) )
|
||||
@@ -1018,16 +1018,16 @@ void CV_ColorLabTest::convert_row_bgr2abc_32f_c3(const float* src_row, float* ds
|
||||
float Lscale = depth == CV_8U ? 255.f/100.f : depth == CV_16U ? 65535.f/100.f : 1.f;
|
||||
float ab_bias = depth == CV_8U ? 128.f : depth == CV_16U ? 32768.f : 0.f;
|
||||
float M[9];
|
||||
|
||||
|
||||
for (int j = 0; j < 9; j++ )
|
||||
M[j] = (float)RGB2XYZ[j];
|
||||
|
||||
|
||||
for (int x = 0; x < n*3; x += 3)
|
||||
{
|
||||
float R = src_row[x + 2];
|
||||
float G = src_row[x + 1];
|
||||
float B = src_row[x];
|
||||
|
||||
|
||||
float X = (R * M[0] + G * M[1] + B * M[2]) / Xn;
|
||||
float Y = R * M[3] + G * M[4] + B * M[5];
|
||||
float Z = (R * M[6] + G * M[7] + B * M[8]) / Zn;
|
||||
@@ -1035,7 +1035,7 @@ void CV_ColorLabTest::convert_row_bgr2abc_32f_c3(const float* src_row, float* ds
|
||||
(7.787f * X + 16.f / 116.f);
|
||||
float fZ = Z > 0.008856f ? pow(Z, _1_3f):
|
||||
(7.787f * Z + 16.f / 116.f);
|
||||
|
||||
|
||||
float L = 0.0f, fY = 0.0f;
|
||||
if (Y > 0.008856f)
|
||||
{
|
||||
@@ -1047,10 +1047,10 @@ void CV_ColorLabTest::convert_row_bgr2abc_32f_c3(const float* src_row, float* ds
|
||||
fY = 7.787f * Y + 16.f / 116.f;
|
||||
L = 903.3f * Y;
|
||||
}
|
||||
|
||||
|
||||
float a = 500.f * (fX - fY);
|
||||
float b = 200.f * (fY - fZ);
|
||||
|
||||
|
||||
dst_row[x] = L * Lscale;
|
||||
dst_row[x + 1] = a + ab_bias;
|
||||
dst_row[x + 2] = b + ab_bias;
|
||||
@@ -1063,10 +1063,10 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
|
||||
float Lscale = depth == CV_8U ? 100.f/255.f : depth == CV_16U ? 100.f/65535.f : 1.f;
|
||||
float ab_bias = depth == CV_8U ? 128.f : depth == CV_16U ? 32768.f : 0.f;
|
||||
float M[9];
|
||||
|
||||
|
||||
for(int j = 0; j < 9; j++ )
|
||||
M[j] = (float)XYZ2RGB[j];
|
||||
|
||||
|
||||
static const float lthresh = 903.3f * 0.008856f;
|
||||
static const float thresh = 7.787f * 0.008856f + 16.0f / 116.0f;
|
||||
for (int x = 0, end = n * 3; x < end; x += 3)
|
||||
@@ -1074,7 +1074,7 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
|
||||
float L = src_row[x] * Lscale;
|
||||
float a = src_row[x + 1] - ab_bias;
|
||||
float b = src_row[x + 2] - ab_bias;
|
||||
|
||||
|
||||
float FY = 0.0f, Y = 0.0f;
|
||||
if (L <= lthresh)
|
||||
{
|
||||
@@ -1086,10 +1086,10 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
|
||||
FY = (L + 16.0f) / 116.0f;
|
||||
Y = FY * FY * FY;
|
||||
}
|
||||
|
||||
|
||||
float FX = a / 500.0f + FY;
|
||||
float FZ = FY - b / 200.0f;
|
||||
|
||||
|
||||
float FXZ[] = { FX, FZ };
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
@@ -1100,11 +1100,11 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
|
||||
}
|
||||
float X = FXZ[0] * Xn;
|
||||
float Z = FXZ[1] * Zn;
|
||||
|
||||
|
||||
float R = M[0] * X + M[1] * Y + M[2] * Z;
|
||||
float G = M[3] * X + M[4] * Y + M[5] * Z;
|
||||
float B = M[6] * X + M[7] * Y + M[8] * Z;
|
||||
|
||||
|
||||
dst_row[x] = B;
|
||||
dst_row[x + 1] = G;
|
||||
dst_row[x + 2] = R;
|
||||
@@ -1589,10 +1589,10 @@ static void bayer2BGR_(const Mat& src, Mat& dst, int code)
|
||||
int i, j, cols = src.cols - 2;
|
||||
int bi = 0;
|
||||
int step = (int)(src.step/sizeof(T));
|
||||
|
||||
|
||||
if( code == CV_BayerRG2BGR || code == CV_BayerGR2BGR )
|
||||
bi ^= 2;
|
||||
|
||||
|
||||
for( i = 1; i < src.rows - 1; i++ )
|
||||
{
|
||||
const T* ptr = src.ptr<T>(i) + 1;
|
||||
@@ -1604,7 +1604,7 @@ static void bayer2BGR_(const Mat& src, Mat& dst, int code)
|
||||
dst_row[cols*3] = dst_row[cols*3+1] = dst_row[cols*3+2] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for( j = 0; j < cols; j++ )
|
||||
{
|
||||
int b, g, r;
|
||||
@@ -1625,18 +1625,18 @@ static void bayer2BGR_(const Mat& src, Mat& dst, int code)
|
||||
dst_row[j*3 + 1] = (T)g;
|
||||
dst_row[j*3 + (bi^2)] = (T)r;
|
||||
}
|
||||
|
||||
|
||||
dst_row[-3] = dst_row[0];
|
||||
dst_row[-2] = dst_row[1];
|
||||
dst_row[-1] = dst_row[2];
|
||||
dst_row[cols*3] = dst_row[cols*3-3];
|
||||
dst_row[cols*3+1] = dst_row[cols*3-2];
|
||||
dst_row[cols*3+2] = dst_row[cols*3-1];
|
||||
|
||||
|
||||
code = save_code ^ 1;
|
||||
bi ^= 2;
|
||||
}
|
||||
|
||||
|
||||
if( src.rows <= 2 )
|
||||
{
|
||||
memset( dst.ptr(), 0, (cols+2)*3*sizeof(T) );
|
||||
@@ -1647,7 +1647,7 @@ static void bayer2BGR_(const Mat& src, Mat& dst, int code)
|
||||
T* top_row = dst.ptr<T>();
|
||||
T* bottom_row = dst.ptr<T>(dst.rows-1);
|
||||
int dstep = (int)(dst.step/sizeof(T));
|
||||
|
||||
|
||||
for( j = 0; j < (cols+2)*3; j++ )
|
||||
{
|
||||
top_row[j] = top_row[j + dstep];
|
||||
@@ -1708,14 +1708,14 @@ TEST(Imgproc_ColorBayerVNG, regression)
|
||||
cvtest::TS& ts = *cvtest::TS::ptr();
|
||||
|
||||
Mat given = imread(string(ts.get_data_path()) + "/cvtcolor/bayer_input.png", CV_LOAD_IMAGE_GRAYSCALE);
|
||||
string goldfname = string(ts.get_data_path()) + "/cvtcolor/bayerVNG_gold.png";
|
||||
string goldfname = string(ts.get_data_path()) + "/cvtcolor/bayerVNG_gold.png";
|
||||
Mat gold = imread(goldfname, CV_LOAD_IMAGE_UNCHANGED);
|
||||
Mat result;
|
||||
|
||||
CV_Assert(given.data != NULL);
|
||||
|
||||
|
||||
cvtColor(given, result, CV_BayerBG2BGR_VNG, 3);
|
||||
|
||||
|
||||
if (gold.empty())
|
||||
imwrite(goldfname, result);
|
||||
else
|
||||
@@ -1750,7 +1750,7 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression)
|
||||
ts.set_gtest_status();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int type = -1;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
@@ -1816,7 +1816,7 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression)
|
||||
|
||||
// calculating a dst image
|
||||
cvtColor(bayer, dst, type);
|
||||
|
||||
|
||||
// reading a reference image
|
||||
full_path = parent_path + pattern[i] + image_name;
|
||||
reference = imread(full_path, CV_LOAD_IMAGE_UNCHANGED);
|
||||
@@ -1825,7 +1825,7 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression)
|
||||
imwrite(full_path, dst);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (reference.depth() != dst.depth() || reference.channels() != dst.channels() ||
|
||||
reference.size() != dst.size())
|
||||
{
|
||||
@@ -1839,13 +1839,13 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression)
|
||||
ts.printf(cvtest::TS::SUMMARY, "\nReference cols: %d\n"
|
||||
"Actual cols: %d\n", reference.cols, dst.cols);
|
||||
ts.set_gtest_status();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Mat diff;
|
||||
absdiff(reference, dst, diff);
|
||||
|
||||
|
||||
int nonZero = countNonZero(diff.reshape(1) > 1);
|
||||
if (nonZero != 0)
|
||||
{
|
||||
@@ -1872,7 +1872,7 @@ void GetTestMatrix(Mat& src)
|
||||
float b = (1 + cos((szm - i) * (szm - j) * pi2 / (10 * float(szm)))) / 2;
|
||||
float g = (1 + cos((szm - i) * j * pi2 / (10 * float(szm)))) / 2;
|
||||
float r = (1 + sin(i * j * pi2 / (10 * float(szm)))) / 2;
|
||||
|
||||
|
||||
// The following lines aren't necessary, but just to prove that
|
||||
// the BGR values all lie in [0,1]...
|
||||
if (b < 0) b = 0; else if (b > 1) b = 1;
|
||||
@@ -1887,11 +1887,11 @@ void validate_result(const Mat& reference, const Mat& actual, const Mat& src = M
|
||||
{
|
||||
cvtest::TS* ts = cvtest::TS::ptr();
|
||||
Size ssize = reference.size();
|
||||
|
||||
|
||||
int cn = reference.channels();
|
||||
ssize.width *= cn;
|
||||
bool next = true;
|
||||
|
||||
|
||||
for (int y = 0; y < ssize.height && next; ++y)
|
||||
{
|
||||
const float* rD = reference.ptr<float>(y);
|
||||
@@ -1906,7 +1906,7 @@ void validate_result(const Mat& reference, const Mat& actual, const Mat& src = M
|
||||
if (!src.empty())
|
||||
ts->printf(cvtest::TS::SUMMARY, "Src value: %f\n", src.ptr<float>(y)[x]);
|
||||
ts->printf(cvtest::TS::SUMMARY, "Size: (%d, %d)\n", reference.rows, reference.cols);
|
||||
|
||||
|
||||
if (mode >= 0)
|
||||
{
|
||||
cv::Mat lab;
|
||||
@@ -1914,7 +1914,7 @@ void validate_result(const Mat& reference, const Mat& actual, const Mat& src = M
|
||||
std::cout << "lab: " << lab(cv::Rect(y, x / cn, 1, 1)) << std::endl;
|
||||
}
|
||||
std::cout << "src: " << src(cv::Rect(y, x / cn, 1, 1)) << std::endl;
|
||||
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->set_gtest_status();
|
||||
}
|
||||
@@ -1928,11 +1928,11 @@ TEST(Imgproc_ColorLab_Full, accuracy)
|
||||
Mat reference(src.size(), CV_32FC3);
|
||||
Size ssize = src.size();
|
||||
CV_Assert(ssize.width == ssize.height);
|
||||
|
||||
|
||||
RNG& rng = cvtest::TS::ptr()->get_rng();
|
||||
int blueInd = rng.uniform(0., 1.) > 0.5 ? 0 : 2;
|
||||
bool srgb = rng.uniform(0., 1.) > 0.5;
|
||||
|
||||
|
||||
// Convert test image to LAB
|
||||
cv::Mat lab;
|
||||
int forward_code = blueInd ? srgb ? CV_BGR2Lab : CV_LBGR2Lab : srgb ? CV_RGB2Lab : CV_LRGB2Lab;
|
||||
@@ -1941,12 +1941,12 @@ TEST(Imgproc_ColorLab_Full, accuracy)
|
||||
// Convert LAB image back to BGR(RGB)
|
||||
cv::Mat recons;
|
||||
cv::cvtColor(lab, recons, inverse_code);
|
||||
|
||||
|
||||
validate_result(src, recons, src, forward_code);
|
||||
|
||||
|
||||
// src *= 255.0f;
|
||||
// recons *= 255.0f;
|
||||
|
||||
|
||||
// imshow("Test", src);
|
||||
// imshow("OpenCV", recons);
|
||||
// waitKey();
|
||||
|
||||
@@ -1,484 +1,484 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
#undef RGB
|
||||
#undef YUV
|
||||
|
||||
typedef Vec3b YUV;
|
||||
typedef Vec3b RGB;
|
||||
|
||||
int countOfDifferencies(const Mat& gold, const Mat& result, int maxAllowedDifference = 1)
|
||||
{
|
||||
Mat diff;
|
||||
absdiff(gold, result, diff);
|
||||
return countNonZero(diff.reshape(1) > maxAllowedDifference);
|
||||
}
|
||||
|
||||
class YUVreader
|
||||
{
|
||||
public:
|
||||
virtual ~YUVreader() {}
|
||||
virtual YUV read(const Mat& yuv, int row, int col) = 0;
|
||||
virtual int channels() = 0;
|
||||
virtual Size size(Size imgSize) = 0;
|
||||
|
||||
virtual bool requiresEvenHeight() { return true; }
|
||||
virtual bool requiresEvenWidth() { return true; }
|
||||
|
||||
static YUVreader* getReader(int code);
|
||||
};
|
||||
|
||||
class RGBwriter
|
||||
{
|
||||
public:
|
||||
virtual ~RGBwriter() {}
|
||||
|
||||
virtual void write(Mat& rgb, int row, int col, const RGB& val) = 0;
|
||||
virtual int channels() = 0;
|
||||
|
||||
static RGBwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class GRAYwriter
|
||||
{
|
||||
public:
|
||||
virtual ~GRAYwriter() {}
|
||||
|
||||
virtual void write(Mat& gray, int row, int col, const uchar& val)
|
||||
{
|
||||
gray.at<uchar>(row, col) = val;
|
||||
}
|
||||
|
||||
virtual int channels() { return 1; }
|
||||
|
||||
static GRAYwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class RGB888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
rgb.at<Vec3b>(row, col) = val;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class BGR888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec3b tmp(val[2], val[1], val[0]);
|
||||
rgb.at<Vec3b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class RGBA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[0], val[1], val[2], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class BGRA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[2], val[1], val[0], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class YUV420Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 1; }
|
||||
Size size(Size imgSize) { return Size(imgSize.width, imgSize.height * 3 / 2); }
|
||||
};
|
||||
|
||||
class YUV422Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 2; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
};
|
||||
|
||||
class NV21Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct NV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class IYUVReader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class UYVYReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][1];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][0];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][0];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUY2Reader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YVYUReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV888Reader : public YUVreader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
return yuv.at<YUV>(row, col);
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
bool requiresEvenWidth() { return false; }
|
||||
};
|
||||
|
||||
class YUV2RGB_Converter
|
||||
{
|
||||
public:
|
||||
RGB convert(YUV yuv)
|
||||
{
|
||||
int y = std::max(0, yuv[0] - 16);
|
||||
int u = yuv[1] - 128;
|
||||
int v = yuv[2] - 128;
|
||||
uchar r = saturate_cast<uchar>(1.164f * y + 1.596f * v);
|
||||
uchar g = saturate_cast<uchar>(1.164f * y - 0.813f * v - 0.391f * u);
|
||||
uchar b = saturate_cast<uchar>(1.164f * y + 2.018f * u);
|
||||
|
||||
return RGB(r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV2GRAY_Converter
|
||||
{
|
||||
public:
|
||||
uchar convert(YUV yuv)
|
||||
{
|
||||
return yuv[0];
|
||||
}
|
||||
};
|
||||
|
||||
YUVreader* YUVreader::getReader(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2RGB_NV12:
|
||||
case CV_YUV2BGR_NV12:
|
||||
case CV_YUV2RGBA_NV12:
|
||||
case CV_YUV2BGRA_NV12:
|
||||
return new NV12Reader();
|
||||
case CV_YUV2RGB_NV21:
|
||||
case CV_YUV2BGR_NV21:
|
||||
case CV_YUV2RGBA_NV21:
|
||||
case CV_YUV2BGRA_NV21:
|
||||
return new NV21Reader();
|
||||
case CV_YUV2RGB_YV12:
|
||||
case CV_YUV2BGR_YV12:
|
||||
case CV_YUV2RGBA_YV12:
|
||||
case CV_YUV2BGRA_YV12:
|
||||
return new YV12Reader();
|
||||
case CV_YUV2RGB_IYUV:
|
||||
case CV_YUV2BGR_IYUV:
|
||||
case CV_YUV2RGBA_IYUV:
|
||||
case CV_YUV2BGRA_IYUV:
|
||||
return new IYUVReader();
|
||||
case CV_YUV2RGB_UYVY:
|
||||
case CV_YUV2BGR_UYVY:
|
||||
case CV_YUV2RGBA_UYVY:
|
||||
case CV_YUV2BGRA_UYVY:
|
||||
return new UYVYReader();
|
||||
//case CV_YUV2RGB_VYUY = 109,
|
||||
//case CV_YUV2BGR_VYUY = 110,
|
||||
//case CV_YUV2RGBA_VYUY = 113,
|
||||
//case CV_YUV2BGRA_VYUY = 114,
|
||||
// return ??
|
||||
case CV_YUV2RGB_YUY2:
|
||||
case CV_YUV2BGR_YUY2:
|
||||
case CV_YUV2RGBA_YUY2:
|
||||
case CV_YUV2BGRA_YUY2:
|
||||
return new YUY2Reader();
|
||||
case CV_YUV2RGB_YVYU:
|
||||
case CV_YUV2BGR_YVYU:
|
||||
case CV_YUV2RGBA_YVYU:
|
||||
case CV_YUV2BGRA_YVYU:
|
||||
return new YVYUReader();
|
||||
case CV_YUV2GRAY_420:
|
||||
return new NV21Reader();
|
||||
case CV_YUV2GRAY_UYVY:
|
||||
return new UYVYReader();
|
||||
case CV_YUV2GRAY_YUY2:
|
||||
return new YUY2Reader();
|
||||
case CV_YUV2BGR:
|
||||
case CV_YUV2RGB:
|
||||
return new YUV888Reader();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
RGBwriter* RGBwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2RGB_NV12:
|
||||
case CV_YUV2RGB_NV21:
|
||||
case CV_YUV2RGB_YV12:
|
||||
case CV_YUV2RGB_IYUV:
|
||||
case CV_YUV2RGB_UYVY:
|
||||
//case CV_YUV2RGB_VYUY:
|
||||
case CV_YUV2RGB_YUY2:
|
||||
case CV_YUV2RGB_YVYU:
|
||||
case CV_YUV2RGB:
|
||||
return new RGB888Writer();
|
||||
case CV_YUV2BGR_NV12:
|
||||
case CV_YUV2BGR_NV21:
|
||||
case CV_YUV2BGR_YV12:
|
||||
case CV_YUV2BGR_IYUV:
|
||||
case CV_YUV2BGR_UYVY:
|
||||
//case CV_YUV2BGR_VYUY:
|
||||
case CV_YUV2BGR_YUY2:
|
||||
case CV_YUV2BGR_YVYU:
|
||||
case CV_YUV2BGR:
|
||||
return new BGR888Writer();
|
||||
case CV_YUV2RGBA_NV12:
|
||||
case CV_YUV2RGBA_NV21:
|
||||
case CV_YUV2RGBA_YV12:
|
||||
case CV_YUV2RGBA_IYUV:
|
||||
case CV_YUV2RGBA_UYVY:
|
||||
//case CV_YUV2RGBA_VYUY:
|
||||
case CV_YUV2RGBA_YUY2:
|
||||
case CV_YUV2RGBA_YVYU:
|
||||
return new RGBA8888Writer();
|
||||
case CV_YUV2BGRA_NV12:
|
||||
case CV_YUV2BGRA_NV21:
|
||||
case CV_YUV2BGRA_YV12:
|
||||
case CV_YUV2BGRA_IYUV:
|
||||
case CV_YUV2BGRA_UYVY:
|
||||
//case CV_YUV2BGRA_VYUY:
|
||||
case CV_YUV2BGRA_YUY2:
|
||||
case CV_YUV2BGRA_YVYU:
|
||||
return new BGRA8888Writer();
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
GRAYwriter* GRAYwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2GRAY_420:
|
||||
case CV_YUV2GRAY_UYVY:
|
||||
case CV_YUV2GRAY_YUY2:
|
||||
return new GRAYwriter();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2RGB(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, RGBwriter* rgbWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
rgbWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2GRAY(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, GRAYwriter* grayWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
grayWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
CV_ENUM(YUVCVTS, CV_YUV2RGB_NV12, CV_YUV2BGR_NV12, CV_YUV2RGB_NV21, CV_YUV2BGR_NV21,
|
||||
CV_YUV2RGBA_NV12, CV_YUV2BGRA_NV12, CV_YUV2RGBA_NV21, CV_YUV2BGRA_NV21,
|
||||
CV_YUV2RGB_YV12, CV_YUV2BGR_YV12, CV_YUV2RGB_IYUV, CV_YUV2BGR_IYUV,
|
||||
CV_YUV2RGBA_YV12, CV_YUV2BGRA_YV12, CV_YUV2RGBA_IYUV, CV_YUV2BGRA_IYUV,
|
||||
CV_YUV2RGB_UYVY, CV_YUV2BGR_UYVY, CV_YUV2RGBA_UYVY, CV_YUV2BGRA_UYVY,
|
||||
CV_YUV2RGB_YUY2, CV_YUV2BGR_YUY2, CV_YUV2RGB_YVYU, CV_YUV2BGR_YVYU,
|
||||
CV_YUV2RGBA_YUY2, CV_YUV2BGRA_YUY2, CV_YUV2RGBA_YVYU, CV_YUV2BGRA_YVYU,
|
||||
CV_YUV2GRAY_420, CV_YUV2GRAY_UYVY, CV_YUV2GRAY_YUY2,
|
||||
CV_YUV2BGR, CV_YUV2RGB);
|
||||
|
||||
typedef ::testing::TestWithParam<YUVCVTS> Imgproc_ColorYUV;
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
YUVreader* yuvReader = YUVreader::getReader(code);
|
||||
RGBwriter* rgbWriter = RGBwriter::getWriter(code);
|
||||
GRAYwriter* grayWriter = GRAYwriter::getWriter(code);
|
||||
|
||||
int dcn = (rgbWriter == 0) ? grayWriter->channels() : rgbWriter->channels();
|
||||
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(yuvReader->requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(yuvReader->requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
Size ysz = yuvReader->size(sz);
|
||||
Mat src = Mat(ysz.height, ysz.width * yuvReader->channels(), CV_8UC1).reshape(yuvReader->channels());
|
||||
|
||||
Mat dst = Mat(sz.height, sz.width * dcn, CV_8UC1).reshape(dcn);
|
||||
Mat gold(sz, CV_8UC(dcn));
|
||||
|
||||
random.fill(src, RNG::UNIFORM, 0, 256);
|
||||
|
||||
if(rgbWriter)
|
||||
referenceYUV2RGB<YUV2RGB_Converter>(src, gold, yuvReader, rgbWriter);
|
||||
else
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, yuvReader, grayWriter);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold, dst));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, roi_accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
YUVreader* yuvReader = YUVreader::getReader(code);
|
||||
RGBwriter* rgbWriter = RGBwriter::getWriter(code);
|
||||
GRAYwriter* grayWriter = GRAYwriter::getWriter(code);
|
||||
|
||||
int dcn = (rgbWriter == 0) ? grayWriter->channels() : rgbWriter->channels();
|
||||
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(yuvReader->requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(yuvReader->requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
int roi_offset_top = random.uniform(0, 6);
|
||||
int roi_offset_bottom = random.uniform(0, 6);
|
||||
int roi_offset_left = random.uniform(0, 6);
|
||||
int roi_offset_right = random.uniform(0, 6);
|
||||
|
||||
Size ysz = yuvReader->size(sz);
|
||||
|
||||
Mat src_full(ysz.height + roi_offset_top + roi_offset_bottom, ysz.width + roi_offset_left + roi_offset_right, CV_8UC(yuvReader->channels()));
|
||||
Mat dst_full(sz.height + roi_offset_left + roi_offset_right, sz.width + roi_offset_top + roi_offset_bottom, CV_8UC(dcn), Scalar::all(0));
|
||||
Mat gold_full(dst_full.size(), CV_8UC(dcn), Scalar::all(0));
|
||||
|
||||
random.fill(src_full, RNG::UNIFORM, 0, 256);
|
||||
|
||||
Mat src = src_full(Range(roi_offset_top, roi_offset_top + ysz.height), Range(roi_offset_left, roi_offset_left + ysz.width));
|
||||
Mat dst = dst_full(Range(roi_offset_left, roi_offset_left + sz.height), Range(roi_offset_top, roi_offset_top + sz.width));
|
||||
Mat gold = gold_full(Range(roi_offset_left, roi_offset_left + sz.height), Range(roi_offset_top, roi_offset_top + sz.width));
|
||||
|
||||
if(rgbWriter)
|
||||
referenceYUV2RGB<YUV2RGB_Converter>(src, gold, yuvReader, rgbWriter);
|
||||
else
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, yuvReader, grayWriter);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold_full, dst_full));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt420, Imgproc_ColorYUV,
|
||||
::testing::Values((int)CV_YUV2RGB_NV12, (int)CV_YUV2BGR_NV12, (int)CV_YUV2RGB_NV21, (int)CV_YUV2BGR_NV21,
|
||||
(int)CV_YUV2RGBA_NV12, (int)CV_YUV2BGRA_NV12, (int)CV_YUV2RGBA_NV21, (int)CV_YUV2BGRA_NV21,
|
||||
(int)CV_YUV2RGB_YV12, (int)CV_YUV2BGR_YV12, (int)CV_YUV2RGB_IYUV, (int)CV_YUV2BGR_IYUV,
|
||||
(int)CV_YUV2RGBA_YV12, (int)CV_YUV2BGRA_YV12, (int)CV_YUV2RGBA_IYUV, (int)CV_YUV2BGRA_IYUV,
|
||||
(int)CV_YUV2GRAY_420));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt422, Imgproc_ColorYUV,
|
||||
::testing::Values((int)CV_YUV2RGB_UYVY, (int)CV_YUV2BGR_UYVY, (int)CV_YUV2RGBA_UYVY, (int)CV_YUV2BGRA_UYVY,
|
||||
(int)CV_YUV2RGB_YUY2, (int)CV_YUV2BGR_YUY2, (int)CV_YUV2RGB_YVYU, (int)CV_YUV2BGR_YVYU,
|
||||
(int)CV_YUV2RGBA_YUY2, (int)CV_YUV2BGRA_YUY2, (int)CV_YUV2RGBA_YVYU, (int)CV_YUV2BGRA_YVYU,
|
||||
(int)CV_YUV2GRAY_UYVY, (int)CV_YUV2GRAY_YUY2));
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
#undef RGB
|
||||
#undef YUV
|
||||
|
||||
typedef Vec3b YUV;
|
||||
typedef Vec3b RGB;
|
||||
|
||||
int countOfDifferencies(const Mat& gold, const Mat& result, int maxAllowedDifference = 1)
|
||||
{
|
||||
Mat diff;
|
||||
absdiff(gold, result, diff);
|
||||
return countNonZero(diff.reshape(1) > maxAllowedDifference);
|
||||
}
|
||||
|
||||
class YUVreader
|
||||
{
|
||||
public:
|
||||
virtual ~YUVreader() {}
|
||||
virtual YUV read(const Mat& yuv, int row, int col) = 0;
|
||||
virtual int channels() = 0;
|
||||
virtual Size size(Size imgSize) = 0;
|
||||
|
||||
virtual bool requiresEvenHeight() { return true; }
|
||||
virtual bool requiresEvenWidth() { return true; }
|
||||
|
||||
static YUVreader* getReader(int code);
|
||||
};
|
||||
|
||||
class RGBwriter
|
||||
{
|
||||
public:
|
||||
virtual ~RGBwriter() {}
|
||||
|
||||
virtual void write(Mat& rgb, int row, int col, const RGB& val) = 0;
|
||||
virtual int channels() = 0;
|
||||
|
||||
static RGBwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class GRAYwriter
|
||||
{
|
||||
public:
|
||||
virtual ~GRAYwriter() {}
|
||||
|
||||
virtual void write(Mat& gray, int row, int col, const uchar& val)
|
||||
{
|
||||
gray.at<uchar>(row, col) = val;
|
||||
}
|
||||
|
||||
virtual int channels() { return 1; }
|
||||
|
||||
static GRAYwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class RGB888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
rgb.at<Vec3b>(row, col) = val;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class BGR888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec3b tmp(val[2], val[1], val[0]);
|
||||
rgb.at<Vec3b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class RGBA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[0], val[1], val[2], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class BGRA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[2], val[1], val[0], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class YUV420Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 1; }
|
||||
Size size(Size imgSize) { return Size(imgSize.width, imgSize.height * 3 / 2); }
|
||||
};
|
||||
|
||||
class YUV422Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 2; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
};
|
||||
|
||||
class NV21Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct NV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class IYUVReader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class UYVYReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][1];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][0];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][0];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUY2Reader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YVYUReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV888Reader : public YUVreader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
return yuv.at<YUV>(row, col);
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
bool requiresEvenWidth() { return false; }
|
||||
};
|
||||
|
||||
class YUV2RGB_Converter
|
||||
{
|
||||
public:
|
||||
RGB convert(YUV yuv)
|
||||
{
|
||||
int y = std::max(0, yuv[0] - 16);
|
||||
int u = yuv[1] - 128;
|
||||
int v = yuv[2] - 128;
|
||||
uchar r = saturate_cast<uchar>(1.164f * y + 1.596f * v);
|
||||
uchar g = saturate_cast<uchar>(1.164f * y - 0.813f * v - 0.391f * u);
|
||||
uchar b = saturate_cast<uchar>(1.164f * y + 2.018f * u);
|
||||
|
||||
return RGB(r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV2GRAY_Converter
|
||||
{
|
||||
public:
|
||||
uchar convert(YUV yuv)
|
||||
{
|
||||
return yuv[0];
|
||||
}
|
||||
};
|
||||
|
||||
YUVreader* YUVreader::getReader(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2RGB_NV12:
|
||||
case CV_YUV2BGR_NV12:
|
||||
case CV_YUV2RGBA_NV12:
|
||||
case CV_YUV2BGRA_NV12:
|
||||
return new NV12Reader();
|
||||
case CV_YUV2RGB_NV21:
|
||||
case CV_YUV2BGR_NV21:
|
||||
case CV_YUV2RGBA_NV21:
|
||||
case CV_YUV2BGRA_NV21:
|
||||
return new NV21Reader();
|
||||
case CV_YUV2RGB_YV12:
|
||||
case CV_YUV2BGR_YV12:
|
||||
case CV_YUV2RGBA_YV12:
|
||||
case CV_YUV2BGRA_YV12:
|
||||
return new YV12Reader();
|
||||
case CV_YUV2RGB_IYUV:
|
||||
case CV_YUV2BGR_IYUV:
|
||||
case CV_YUV2RGBA_IYUV:
|
||||
case CV_YUV2BGRA_IYUV:
|
||||
return new IYUVReader();
|
||||
case CV_YUV2RGB_UYVY:
|
||||
case CV_YUV2BGR_UYVY:
|
||||
case CV_YUV2RGBA_UYVY:
|
||||
case CV_YUV2BGRA_UYVY:
|
||||
return new UYVYReader();
|
||||
//case CV_YUV2RGB_VYUY = 109,
|
||||
//case CV_YUV2BGR_VYUY = 110,
|
||||
//case CV_YUV2RGBA_VYUY = 113,
|
||||
//case CV_YUV2BGRA_VYUY = 114,
|
||||
// return ??
|
||||
case CV_YUV2RGB_YUY2:
|
||||
case CV_YUV2BGR_YUY2:
|
||||
case CV_YUV2RGBA_YUY2:
|
||||
case CV_YUV2BGRA_YUY2:
|
||||
return new YUY2Reader();
|
||||
case CV_YUV2RGB_YVYU:
|
||||
case CV_YUV2BGR_YVYU:
|
||||
case CV_YUV2RGBA_YVYU:
|
||||
case CV_YUV2BGRA_YVYU:
|
||||
return new YVYUReader();
|
||||
case CV_YUV2GRAY_420:
|
||||
return new NV21Reader();
|
||||
case CV_YUV2GRAY_UYVY:
|
||||
return new UYVYReader();
|
||||
case CV_YUV2GRAY_YUY2:
|
||||
return new YUY2Reader();
|
||||
case CV_YUV2BGR:
|
||||
case CV_YUV2RGB:
|
||||
return new YUV888Reader();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
RGBwriter* RGBwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2RGB_NV12:
|
||||
case CV_YUV2RGB_NV21:
|
||||
case CV_YUV2RGB_YV12:
|
||||
case CV_YUV2RGB_IYUV:
|
||||
case CV_YUV2RGB_UYVY:
|
||||
//case CV_YUV2RGB_VYUY:
|
||||
case CV_YUV2RGB_YUY2:
|
||||
case CV_YUV2RGB_YVYU:
|
||||
case CV_YUV2RGB:
|
||||
return new RGB888Writer();
|
||||
case CV_YUV2BGR_NV12:
|
||||
case CV_YUV2BGR_NV21:
|
||||
case CV_YUV2BGR_YV12:
|
||||
case CV_YUV2BGR_IYUV:
|
||||
case CV_YUV2BGR_UYVY:
|
||||
//case CV_YUV2BGR_VYUY:
|
||||
case CV_YUV2BGR_YUY2:
|
||||
case CV_YUV2BGR_YVYU:
|
||||
case CV_YUV2BGR:
|
||||
return new BGR888Writer();
|
||||
case CV_YUV2RGBA_NV12:
|
||||
case CV_YUV2RGBA_NV21:
|
||||
case CV_YUV2RGBA_YV12:
|
||||
case CV_YUV2RGBA_IYUV:
|
||||
case CV_YUV2RGBA_UYVY:
|
||||
//case CV_YUV2RGBA_VYUY:
|
||||
case CV_YUV2RGBA_YUY2:
|
||||
case CV_YUV2RGBA_YVYU:
|
||||
return new RGBA8888Writer();
|
||||
case CV_YUV2BGRA_NV12:
|
||||
case CV_YUV2BGRA_NV21:
|
||||
case CV_YUV2BGRA_YV12:
|
||||
case CV_YUV2BGRA_IYUV:
|
||||
case CV_YUV2BGRA_UYVY:
|
||||
//case CV_YUV2BGRA_VYUY:
|
||||
case CV_YUV2BGRA_YUY2:
|
||||
case CV_YUV2BGRA_YVYU:
|
||||
return new BGRA8888Writer();
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
GRAYwriter* GRAYwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case CV_YUV2GRAY_420:
|
||||
case CV_YUV2GRAY_UYVY:
|
||||
case CV_YUV2GRAY_YUY2:
|
||||
return new GRAYwriter();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2RGB(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, RGBwriter* rgbWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
rgbWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2GRAY(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, GRAYwriter* grayWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
grayWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
CV_ENUM(YUVCVTS, CV_YUV2RGB_NV12, CV_YUV2BGR_NV12, CV_YUV2RGB_NV21, CV_YUV2BGR_NV21,
|
||||
CV_YUV2RGBA_NV12, CV_YUV2BGRA_NV12, CV_YUV2RGBA_NV21, CV_YUV2BGRA_NV21,
|
||||
CV_YUV2RGB_YV12, CV_YUV2BGR_YV12, CV_YUV2RGB_IYUV, CV_YUV2BGR_IYUV,
|
||||
CV_YUV2RGBA_YV12, CV_YUV2BGRA_YV12, CV_YUV2RGBA_IYUV, CV_YUV2BGRA_IYUV,
|
||||
CV_YUV2RGB_UYVY, CV_YUV2BGR_UYVY, CV_YUV2RGBA_UYVY, CV_YUV2BGRA_UYVY,
|
||||
CV_YUV2RGB_YUY2, CV_YUV2BGR_YUY2, CV_YUV2RGB_YVYU, CV_YUV2BGR_YVYU,
|
||||
CV_YUV2RGBA_YUY2, CV_YUV2BGRA_YUY2, CV_YUV2RGBA_YVYU, CV_YUV2BGRA_YVYU,
|
||||
CV_YUV2GRAY_420, CV_YUV2GRAY_UYVY, CV_YUV2GRAY_YUY2,
|
||||
CV_YUV2BGR, CV_YUV2RGB);
|
||||
|
||||
typedef ::testing::TestWithParam<YUVCVTS> Imgproc_ColorYUV;
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
YUVreader* yuvReader = YUVreader::getReader(code);
|
||||
RGBwriter* rgbWriter = RGBwriter::getWriter(code);
|
||||
GRAYwriter* grayWriter = GRAYwriter::getWriter(code);
|
||||
|
||||
int dcn = (rgbWriter == 0) ? grayWriter->channels() : rgbWriter->channels();
|
||||
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(yuvReader->requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(yuvReader->requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
Size ysz = yuvReader->size(sz);
|
||||
Mat src = Mat(ysz.height, ysz.width * yuvReader->channels(), CV_8UC1).reshape(yuvReader->channels());
|
||||
|
||||
Mat dst = Mat(sz.height, sz.width * dcn, CV_8UC1).reshape(dcn);
|
||||
Mat gold(sz, CV_8UC(dcn));
|
||||
|
||||
random.fill(src, RNG::UNIFORM, 0, 256);
|
||||
|
||||
if(rgbWriter)
|
||||
referenceYUV2RGB<YUV2RGB_Converter>(src, gold, yuvReader, rgbWriter);
|
||||
else
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, yuvReader, grayWriter);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold, dst));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, roi_accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
YUVreader* yuvReader = YUVreader::getReader(code);
|
||||
RGBwriter* rgbWriter = RGBwriter::getWriter(code);
|
||||
GRAYwriter* grayWriter = GRAYwriter::getWriter(code);
|
||||
|
||||
int dcn = (rgbWriter == 0) ? grayWriter->channels() : rgbWriter->channels();
|
||||
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(yuvReader->requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(yuvReader->requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
int roi_offset_top = random.uniform(0, 6);
|
||||
int roi_offset_bottom = random.uniform(0, 6);
|
||||
int roi_offset_left = random.uniform(0, 6);
|
||||
int roi_offset_right = random.uniform(0, 6);
|
||||
|
||||
Size ysz = yuvReader->size(sz);
|
||||
|
||||
Mat src_full(ysz.height + roi_offset_top + roi_offset_bottom, ysz.width + roi_offset_left + roi_offset_right, CV_8UC(yuvReader->channels()));
|
||||
Mat dst_full(sz.height + roi_offset_left + roi_offset_right, sz.width + roi_offset_top + roi_offset_bottom, CV_8UC(dcn), Scalar::all(0));
|
||||
Mat gold_full(dst_full.size(), CV_8UC(dcn), Scalar::all(0));
|
||||
|
||||
random.fill(src_full, RNG::UNIFORM, 0, 256);
|
||||
|
||||
Mat src = src_full(Range(roi_offset_top, roi_offset_top + ysz.height), Range(roi_offset_left, roi_offset_left + ysz.width));
|
||||
Mat dst = dst_full(Range(roi_offset_left, roi_offset_left + sz.height), Range(roi_offset_top, roi_offset_top + sz.width));
|
||||
Mat gold = gold_full(Range(roi_offset_left, roi_offset_left + sz.height), Range(roi_offset_top, roi_offset_top + sz.width));
|
||||
|
||||
if(rgbWriter)
|
||||
referenceYUV2RGB<YUV2RGB_Converter>(src, gold, yuvReader, rgbWriter);
|
||||
else
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, yuvReader, grayWriter);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold_full, dst_full));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt420, Imgproc_ColorYUV,
|
||||
::testing::Values((int)CV_YUV2RGB_NV12, (int)CV_YUV2BGR_NV12, (int)CV_YUV2RGB_NV21, (int)CV_YUV2BGR_NV21,
|
||||
(int)CV_YUV2RGBA_NV12, (int)CV_YUV2BGRA_NV12, (int)CV_YUV2RGBA_NV21, (int)CV_YUV2BGRA_NV21,
|
||||
(int)CV_YUV2RGB_YV12, (int)CV_YUV2BGR_YV12, (int)CV_YUV2RGB_IYUV, (int)CV_YUV2BGR_IYUV,
|
||||
(int)CV_YUV2RGBA_YV12, (int)CV_YUV2BGRA_YV12, (int)CV_YUV2RGBA_IYUV, (int)CV_YUV2BGRA_IYUV,
|
||||
(int)CV_YUV2GRAY_420));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt422, Imgproc_ColorYUV,
|
||||
::testing::Values((int)CV_YUV2RGB_UYVY, (int)CV_YUV2BGR_UYVY, (int)CV_YUV2RGBA_UYVY, (int)CV_YUV2BGRA_UYVY,
|
||||
(int)CV_YUV2RGB_YUY2, (int)CV_YUV2BGR_YUY2, (int)CV_YUV2RGB_YVYU, (int)CV_YUV2BGR_YVYU,
|
||||
(int)CV_YUV2RGBA_YUY2, (int)CV_YUV2BGRA_YUY2, (int)CV_YUV2RGBA_YVYU, (int)CV_YUV2BGRA_YVYU,
|
||||
(int)CV_YUV2GRAY_UYVY, (int)CV_YUV2GRAY_YUY2));
|
||||
|
||||
@@ -57,7 +57,7 @@ protected:
|
||||
|
||||
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
|
||||
|
||||
int mask_size;
|
||||
int dist_type;
|
||||
int fill_labels;
|
||||
@@ -86,7 +86,7 @@ void CV_DisTransTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_32FC1;
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32SC1;
|
||||
|
||||
|
||||
if( cvtest::randInt(rng) & 1 )
|
||||
{
|
||||
mask_size = 3;
|
||||
@@ -239,7 +239,7 @@ cvTsDistTransform( const CvMat* _src, CvMat* _dst, int dist_type,
|
||||
|
||||
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 )
|
||||
@@ -287,7 +287,7 @@ cvTsDistTransform( const CvMat* _src, CvMat* _dst, int dist_type,
|
||||
void CV_DisTransTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMat _input = test_mat[INPUT][0], _output = test_mat[REF_OUTPUT][0];
|
||||
|
||||
|
||||
cvTsDistTransform( &_input, &_output, dist_type, mask_size, mask, 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ void CV_EMDTest::run( int )
|
||||
const double success_error_level = 1e-6;
|
||||
#define M 10000
|
||||
double emd0 = 2460./210;
|
||||
static float cost[] =
|
||||
static float cost[] =
|
||||
{
|
||||
16, 16, 13, 22, 17,
|
||||
14, 14, 13, 19, 15,
|
||||
@@ -77,7 +77,7 @@ void CV_EMDTest::run( int )
|
||||
Mat _w1(4, 1, CV_32F, w1);
|
||||
Mat _w2(5, 1, CV_32F, w2);
|
||||
Mat _cost(_w1.rows, _w2.rows, CV_32F, cost);
|
||||
|
||||
|
||||
float emd = EMD( _w1, _w2, -1, _cost );
|
||||
if( fabs( emd - emd0 ) > success_error_level*emd0 )
|
||||
{
|
||||
|
||||
@@ -1123,15 +1123,15 @@ void CV_PyramidDownTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
cvtest::filter2D(src, temp, src.depth(),
|
||||
kernel, Point(kernel.cols/2, kernel.rows/2),
|
||||
0, BORDER_REFLECT_101);
|
||||
|
||||
|
||||
size_t elem_size = temp.elemSize();
|
||||
size_t ncols = dst.cols*elem_size;
|
||||
|
||||
|
||||
for( int i = 0; i < dst.rows; i++ )
|
||||
{
|
||||
const uchar* src_row = temp.ptr(i*2);
|
||||
uchar* dst_row = dst.ptr(i);
|
||||
|
||||
|
||||
for( size_t j = 0; j < ncols; j += elem_size )
|
||||
{
|
||||
for( size_t k = 0; k < elem_size; k++ )
|
||||
@@ -1169,15 +1169,15 @@ void CV_PyramidUpTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
Mat& src = test_mat[INPUT][0], &dst = test_mat[REF_OUTPUT][0];
|
||||
Mat temp(dst.size(), dst.type());
|
||||
|
||||
|
||||
size_t elem_size = src.elemSize();
|
||||
size_t ncols = src.cols*elem_size;
|
||||
|
||||
|
||||
for( int i = 0; i < src.rows; i++ )
|
||||
{
|
||||
const uchar* src_row = src.ptr(i);
|
||||
uchar* dst_row = temp.ptr(i*2);
|
||||
|
||||
|
||||
if( i*2 + 1 < temp.rows )
|
||||
memset( temp.ptr(i*2+1), 0, temp.cols*elem_size );
|
||||
for( size_t j = 0; j < ncols; j += elem_size )
|
||||
@@ -1189,7 +1189,7 @@ void CV_PyramidUpTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cvtest::filter2D(temp, dst, dst.depth(),
|
||||
kernel, Point(kernel.cols/2, kernel.rows/2),
|
||||
0, BORDER_REFLECT_101);
|
||||
@@ -1521,7 +1521,7 @@ void CV_PreCornerDetectTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
double kernel_scale = type != ftype ? 1./255 : 1.;
|
||||
|
||||
Mat dx, dy, d2x, d2y, dxy, kernel;
|
||||
|
||||
|
||||
kernel = cvtest::calcSobelKernel2D(1, 0, aperture_size);
|
||||
cvtest::filter2D(src, dx, ftype, kernel*kernel_scale, anchor, 0, BORDER_REPLICATE);
|
||||
kernel = cvtest::calcSobelKernel2D(2, 0, aperture_size);
|
||||
@@ -1660,13 +1660,13 @@ void CV_IntegralTest::run_func()
|
||||
static void test_integral( const Mat& img, Mat* sum, Mat* sqsum, Mat* tilted )
|
||||
{
|
||||
CV_Assert( img.depth() == CV_32F );
|
||||
|
||||
|
||||
sum->create(img.rows+1, img.cols+1, CV_64F);
|
||||
if( sqsum )
|
||||
sqsum->create(img.rows+1, img.cols+1, CV_64F);
|
||||
if( tilted )
|
||||
tilted->create(img.rows+1, img.cols+1, CV_64F);
|
||||
|
||||
|
||||
const float* data = img.ptr<float>();
|
||||
double* sdata = sum->ptr<double>();
|
||||
double* sqdata = sqsum ? sqsum->ptr<double>() : 0;
|
||||
@@ -1740,20 +1740,20 @@ void CV_IntegralTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
psqsum2 = sqsum0 ? *sqsum0 : Mat();
|
||||
ptsum2 = tsum0 ? *tsum0 : Mat();
|
||||
}
|
||||
|
||||
|
||||
for( int i = 0; i < cn; i++ )
|
||||
{
|
||||
if( cn > 1 )
|
||||
cvtest::extract(src, plane, i);
|
||||
plane.convertTo(srcf, CV_32F);
|
||||
|
||||
|
||||
test_integral( srcf, &psum, sqsum0 ? &psqsum : 0, tsum0 ? &ptsum : 0 );
|
||||
psum.convertTo(psum2, sum0->depth());
|
||||
if( sqsum0 )
|
||||
psqsum.convertTo(psqsum2, sqsum0->depth());
|
||||
if( tsum0 )
|
||||
ptsum.convertTo(ptsum2, tsum0->depth());
|
||||
|
||||
|
||||
if( cn > 1 )
|
||||
{
|
||||
cvtest::insert(psum2, *sum0, i);
|
||||
@@ -1790,11 +1790,11 @@ class CV_FilterSupportedFormatsTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_FilterSupportedFormatsTest() {}
|
||||
~CV_FilterSupportedFormatsTest() {}
|
||||
~CV_FilterSupportedFormatsTest() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
const int depths[][2] =
|
||||
const int depths[][2] =
|
||||
{
|
||||
{CV_8U, CV_8U},
|
||||
{CV_8U, CV_16U},
|
||||
@@ -1811,7 +1811,7 @@ protected:
|
||||
{CV_64F, CV_64F},
|
||||
{-1, -1}
|
||||
};
|
||||
|
||||
|
||||
int i = 0;
|
||||
volatile int fidx = -1;
|
||||
try
|
||||
@@ -1830,10 +1830,10 @@ protected:
|
||||
symkernelX += kernelX;
|
||||
flip(kernelY, symkernelY, 0);
|
||||
symkernelY += kernelY;
|
||||
|
||||
|
||||
Mat elem_ellipse = getStructuringElement(MORPH_ELLIPSE, Size(7, 7));
|
||||
Mat elem_rect = getStructuringElement(MORPH_RECT, Size(7, 7));
|
||||
|
||||
|
||||
for( i = 0; depths[i][0] >= 0; i++ )
|
||||
{
|
||||
int sdepth = depths[i][0];
|
||||
@@ -1879,7 +1879,7 @@ protected:
|
||||
fidx == 7 ? "blur" :
|
||||
fidx == 8 || fidx == 9 ? "morphologyEx" :
|
||||
"unknown???");
|
||||
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1498,12 +1498,12 @@ TEST(Imgproc_resize_area, regression)
|
||||
|
||||
ASSERT_EQ(actual.type(), expected.type());
|
||||
ASSERT_EQ(actual.size(), expected.size());
|
||||
|
||||
|
||||
Mat diff;
|
||||
absdiff(actual, expected, diff);
|
||||
|
||||
|
||||
Mat one_channel_diff = diff; //.reshape(1);
|
||||
|
||||
|
||||
float elem_diff = 1.0f;
|
||||
Size dsize = actual.size();
|
||||
bool next = true;
|
||||
@@ -1511,25 +1511,25 @@ TEST(Imgproc_resize_area, regression)
|
||||
{
|
||||
ushort* eD = expected.ptr<ushort>(dy);
|
||||
ushort* aD = actual.ptr<ushort>(dy);
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width && next; ++dx)
|
||||
if (fabs(static_cast<float>(aD[dx] - eD[dx])) > elem_diff)
|
||||
{
|
||||
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Inf norm: %f\n", static_cast<float>(norm(actual, expected, NORM_INF)));
|
||||
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, "Error in : (%d, %d)\n", dx, dy);
|
||||
|
||||
|
||||
const int radius = 3;
|
||||
int rmin = MAX(dy - radius, 0), rmax = MIN(dy + radius, dsize.height);
|
||||
int cmin = MAX(dx - radius, 0), cmax = MIN(dx + radius, dsize.width);
|
||||
|
||||
|
||||
std::cout << "Abs diff:" << std::endl << diff << std::endl;
|
||||
std::cout << "actual result:\n" << actual(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
|
||||
std::cout << "expected result:\n" << expected(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
|
||||
|
||||
|
||||
next = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ASSERT_EQ(norm(one_channel_diff, cv::NORM_INF), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace internal
|
||||
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
#define PRINT_TO_LOG __wrap_printf_func
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
CV_ImageWarpBaseTest();
|
||||
virtual ~CV_ImageWarpBaseTest();
|
||||
|
||||
|
||||
virtual void run(int);
|
||||
protected:
|
||||
virtual void generate_test_data();
|
||||
@@ -89,7 +89,7 @@ protected:
|
||||
virtual void prepare_test_data_for_reference_func();
|
||||
|
||||
Size randSize(RNG& rng) const;
|
||||
|
||||
|
||||
const char* interpolation_to_string(int inter_type) const;
|
||||
|
||||
int interpolation;
|
||||
@@ -150,7 +150,7 @@ void CV_ImageWarpBaseTest::generate_test_data()
|
||||
int cn = rng.uniform(1, 4);
|
||||
while (cn == 2)
|
||||
cn = rng.uniform(1, 4);
|
||||
|
||||
|
||||
src.create(ssize, CV_MAKE_TYPE(depth, cn));
|
||||
|
||||
// generating the src matrix
|
||||
@@ -170,10 +170,10 @@ void CV_ImageWarpBaseTest::generate_test_data()
|
||||
for (x = cell_size; x < src.cols; x += cell_size)
|
||||
line(src, Point2i(x, 0), Point2i(x, src.rows), Scalar::all(0), 1);
|
||||
}
|
||||
|
||||
|
||||
// generating an interpolation type
|
||||
interpolation = rng.uniform(0, CV_INTER_LANCZOS4 + 1);
|
||||
|
||||
|
||||
// generating the dst matrix structure
|
||||
double scale_x, scale_y;
|
||||
if (interpolation == INTER_AREA)
|
||||
@@ -196,16 +196,16 @@ void CV_ImageWarpBaseTest::generate_test_data()
|
||||
scale_y = rng.uniform(0.4, 4.0);
|
||||
}
|
||||
CV_Assert(scale_x > 0.0f && scale_y > 0.0f);
|
||||
|
||||
|
||||
dsize.width = saturate_cast<int>((ssize.width + scale_x - 1) / scale_x);
|
||||
dsize.height = saturate_cast<int>((ssize.height + scale_y - 1) / scale_y);
|
||||
|
||||
|
||||
dst = Mat::zeros(dsize, src.type());
|
||||
reference_dst = Mat::zeros(dst.size(), CV_MAKE_TYPE(CV_32F, dst.channels()));
|
||||
|
||||
|
||||
scale_x = src.cols / static_cast<double>(dst.cols);
|
||||
scale_y = src.rows / static_cast<double>(dst.rows);
|
||||
|
||||
|
||||
if (interpolation == INTER_AREA && (scale_x < 1.0 || scale_y < 1.0))
|
||||
interpolation = INTER_LINEAR;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ void CV_ImageWarpBaseTest::validate_results() const
|
||||
{
|
||||
Mat _dst;
|
||||
dst.convertTo(_dst, reference_dst.depth());
|
||||
|
||||
|
||||
Size dsize = dst.size(), ssize = src.size();
|
||||
int cn = _dst.channels();
|
||||
dsize.width *= cn;
|
||||
@@ -244,12 +244,12 @@ void CV_ImageWarpBaseTest::validate_results() const
|
||||
t = 1.0f;
|
||||
else if (interpolation == INTER_AREA)
|
||||
t = 2.0f;
|
||||
|
||||
|
||||
for (int dy = 0; dy < dsize.height; ++dy)
|
||||
{
|
||||
const float* rD = reference_dst.ptr<float>(dy);
|
||||
const float* D = _dst.ptr<float>(dy);
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
if (fabs(rD[dx] - D[dx]) > t &&
|
||||
// fabs(rD[dx] - D[dx]) < 250.0f &&
|
||||
@@ -260,7 +260,7 @@ void CV_ImageWarpBaseTest::validate_results() const
|
||||
PRINT_TO_LOG("Tuple (rD, D): (%f, %f)\n", rD[dx], D[dx]);
|
||||
PRINT_TO_LOG("Dsize: (%d, %d)\n", dsize.width / cn, dsize.height);
|
||||
PRINT_TO_LOG("Ssize: (%d, %d)\n", src.cols, src.rows);
|
||||
|
||||
|
||||
double scale_x = static_cast<double>(ssize.width) / dsize.width;
|
||||
double scale_y = static_cast<double>(ssize.height) / dsize.height;
|
||||
bool area_fast = interpolation == INTER_AREA &&
|
||||
@@ -271,37 +271,37 @@ void CV_ImageWarpBaseTest::validate_results() const
|
||||
scale_y = cvRound(scale_y);
|
||||
scale_x = cvRound(scale_x);
|
||||
}
|
||||
|
||||
|
||||
PRINT_TO_LOG("Interpolation: %s\n", interpolation_to_string(area_fast ? INTER_LANCZOS4 + 1 : interpolation));
|
||||
PRINT_TO_LOG("Scale (x, y): (%lf, %lf)\n", scale_x, scale_y);
|
||||
PRINT_TO_LOG("Elemsize: %d\n", src.elemSize1());
|
||||
PRINT_TO_LOG("Channels: %d\n", cn);
|
||||
|
||||
|
||||
#ifdef SHOW_IMAGE
|
||||
const std::string w1("OpenCV impl (run func)"), w2("Reference func"), w3("Src image"), w4("Diff");
|
||||
namedWindow(w1, CV_WINDOW_KEEPRATIO);
|
||||
namedWindow(w2, CV_WINDOW_KEEPRATIO);
|
||||
namedWindow(w3, CV_WINDOW_KEEPRATIO);
|
||||
namedWindow(w4, CV_WINDOW_KEEPRATIO);
|
||||
|
||||
|
||||
Mat diff;
|
||||
absdiff(reference_dst, _dst, diff);
|
||||
|
||||
|
||||
imshow(w1, dst);
|
||||
imshow(w2, reference_dst);
|
||||
imshow(w3, src);
|
||||
imshow(w4, diff);
|
||||
|
||||
|
||||
waitKey();
|
||||
#endif
|
||||
|
||||
|
||||
const int radius = 3;
|
||||
int rmin = MAX(dy - radius, 0), rmax = MIN(dy + radius, dsize.height);
|
||||
int cmin = MAX(dx / cn - radius, 0), cmax = MIN(dx / cn + radius, dsize.width);
|
||||
|
||||
|
||||
std::cout << "opencv result:\n" << dst(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
|
||||
std::cout << "reference result:\n" << reference_dst(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
|
||||
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
return;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ protected:
|
||||
|
||||
virtual void run_func();
|
||||
virtual void run_reference_func();
|
||||
|
||||
|
||||
private:
|
||||
double scale_x;
|
||||
double scale_y;
|
||||
@@ -343,7 +343,7 @@ private:
|
||||
void resize_generic();
|
||||
void resize_area();
|
||||
double getWeight(double a, double b, int x);
|
||||
|
||||
|
||||
typedef std::vector<std::pair<int, double> > dim;
|
||||
void generate_buffer(double scale, dim& _dim);
|
||||
void resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _dim);
|
||||
@@ -366,23 +366,23 @@ namespace internal
|
||||
coeffs[0] = 1.f - x;
|
||||
coeffs[1] = x;
|
||||
}
|
||||
|
||||
|
||||
void interpolateCubic(float x, float* coeffs)
|
||||
{
|
||||
const float A = -0.75f;
|
||||
|
||||
|
||||
coeffs[0] = ((A*(x + 1) - 5*A)*(x + 1) + 8*A)*(x + 1) - 4*A;
|
||||
coeffs[1] = ((A + 2)*x - (A + 3))*x*x + 1;
|
||||
coeffs[2] = ((A + 2)*(1 - x) - (A + 3))*(1 - x)*(1 - x) + 1;
|
||||
coeffs[3] = 1.f - coeffs[0] - coeffs[1] - coeffs[2];
|
||||
}
|
||||
|
||||
|
||||
void interpolateLanczos4(float x, float* coeffs)
|
||||
{
|
||||
static const double s45 = 0.70710678118654752440084436210485;
|
||||
static const double cs[][2]=
|
||||
{{1, 0}, {-s45, -s45}, {0, 1}, {s45, -s45}, {-1, 0}, {s45, s45}, {0, -1}, {-s45, s45}};
|
||||
|
||||
|
||||
if( x < FLT_EPSILON )
|
||||
{
|
||||
for( int i = 0; i < 8; i++ )
|
||||
@@ -390,7 +390,7 @@ namespace internal
|
||||
coeffs[3] = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
float sum = 0;
|
||||
double y0=-(x+3)*CV_PI*0.25, s0 = sin(y0), c0=cos(y0);
|
||||
for(int i = 0; i < 8; i++ )
|
||||
@@ -399,12 +399,12 @@ namespace internal
|
||||
coeffs[i] = (float)((cs[i][0]*s0 + cs[i][1]*c0)/(y*y));
|
||||
sum += coeffs[i];
|
||||
}
|
||||
|
||||
|
||||
sum = 1.f/sum;
|
||||
for(int i = 0; i < 8; i++ )
|
||||
coeffs[i] *= sum;
|
||||
}
|
||||
|
||||
|
||||
typedef void (*interpolate_method)(float x, float* coeffs);
|
||||
interpolate_method inter_array[] = { &interpolateLinear, &interpolateCubic, &interpolateLanczos4 };
|
||||
}
|
||||
@@ -412,10 +412,10 @@ namespace internal
|
||||
void CV_Resize_Test::generate_test_data()
|
||||
{
|
||||
CV_ImageWarpBaseTest::generate_test_data();
|
||||
|
||||
|
||||
scale_x = src.cols / static_cast<double>(dst.cols);
|
||||
scale_y = src.rows / static_cast<double>(dst.rows);
|
||||
|
||||
|
||||
area_fast = interpolation == INTER_AREA &&
|
||||
fabs(scale_x - cvRound(scale_x)) < FLT_EPSILON &&
|
||||
fabs(scale_y - cvRound(scale_y)) < FLT_EPSILON;
|
||||
@@ -434,7 +434,7 @@ void CV_Resize_Test::run_func()
|
||||
void CV_Resize_Test::run_reference_func()
|
||||
{
|
||||
CV_ImageWarpBaseTest::prepare_test_data_for_reference_func();
|
||||
|
||||
|
||||
if (interpolation == INTER_AREA)
|
||||
resize_area();
|
||||
else
|
||||
@@ -451,28 +451,28 @@ double CV_Resize_Test::getWeight(double a, double b, int x)
|
||||
void CV_Resize_Test::resize_area()
|
||||
{
|
||||
Size ssize = src.size(), dsize = reference_dst.size();
|
||||
CV_Assert(ssize.area() > 0 && dsize.area() > 0);
|
||||
CV_Assert(ssize.area() > 0 && dsize.area() > 0);
|
||||
int cn = src.channels();
|
||||
|
||||
CV_Assert(scale_x >= 1.0 && scale_y >= 1.0);
|
||||
|
||||
CV_Assert(scale_x >= 1.0 && scale_y >= 1.0);
|
||||
|
||||
double fsy0 = 0, fsy1 = scale_y;
|
||||
for (int dy = 0; dy < dsize.height; ++dy)
|
||||
{
|
||||
float* yD = reference_dst.ptr<float>(dy);
|
||||
int isy0 = cvFloor(fsy0), isy1 = std::min(cvFloor(fsy1), ssize.height - 1);
|
||||
CV_Assert(isy1 <= ssize.height && isy0 < ssize.height);
|
||||
|
||||
|
||||
double fsx0 = 0, fsx1 = scale_x;
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
{
|
||||
float* xyD = yD + cn * dx;
|
||||
int isx0 = cvFloor(fsx0), isx1 = std::min(ssize.width - 1, cvFloor(fsx1));
|
||||
|
||||
|
||||
CV_Assert(isx1 <= ssize.width);
|
||||
CV_Assert(isx0 < ssize.width);
|
||||
|
||||
|
||||
// for each pixel of dst
|
||||
for (int r = 0; r < cn; ++r)
|
||||
{
|
||||
@@ -490,7 +490,7 @@ void CV_Resize_Test::resize_area()
|
||||
area += w;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_Assert(area != 0);
|
||||
// norming pixel
|
||||
xyD[r] = static_cast<float>(xyD[r] / area);
|
||||
@@ -504,19 +504,19 @@ void CV_Resize_Test::resize_area()
|
||||
// for interpolation type : INTER_LINEAR, INTER_LINEAR, INTER_CUBIC, INTER_LANCZOS4
|
||||
void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _dim)
|
||||
{
|
||||
Size dsize = _dst.size();
|
||||
Size dsize = _dst.size();
|
||||
int cn = _dst.channels();
|
||||
float* yD = _dst.ptr<float>(dy);
|
||||
|
||||
|
||||
if (interpolation == INTER_NEAREST)
|
||||
{
|
||||
const float* yS = _src.ptr<float>(dy);
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
{
|
||||
int isx = _dim[dx].first;
|
||||
const float* xyS = yS + isx * cn;
|
||||
float* xyD = yD + dx * cn;
|
||||
|
||||
const float* xyS = yS + isx * cn;
|
||||
float* xyD = yD + dx * cn;
|
||||
|
||||
for (int r = 0; r < cn; ++r)
|
||||
xyD[r] = xyS[r];
|
||||
}
|
||||
@@ -525,13 +525,13 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d
|
||||
{
|
||||
internal::interpolate_method inter_func = internal::inter_array[interpolation - (interpolation == INTER_LANCZOS4 ? 2 : 1)];
|
||||
size_t elemsize = _src.elemSize();
|
||||
|
||||
|
||||
int ofs = 0, ksize = 2;
|
||||
if (interpolation == INTER_CUBIC)
|
||||
ofs = 1, ksize = 4;
|
||||
else if (interpolation == INTER_LANCZOS4)
|
||||
ofs = 3, ksize = 8;
|
||||
|
||||
|
||||
Mat _extended_src_row(1, _src.cols + ksize * 2, _src.type());
|
||||
uchar* srow = _src.data + dy * _src.step;
|
||||
memcpy(_extended_src_row.data + elemsize * ksize, srow, _src.step);
|
||||
@@ -540,7 +540,7 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d
|
||||
memcpy(_extended_src_row.data + k * elemsize, srow, elemsize);
|
||||
memcpy(_extended_src_row.data + (ksize + k) * elemsize + _src.step, srow + _src.step - elemsize, elemsize);
|
||||
}
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
{
|
||||
int isx = _dim[dx].first;
|
||||
@@ -569,7 +569,7 @@ void CV_Resize_Test::generate_buffer(double scale, dim& _dim)
|
||||
{
|
||||
size_t length = _dim.size();
|
||||
for (size_t dx = 0; dx < length; ++dx)
|
||||
{
|
||||
{
|
||||
double fsx = scale * (dx + 0.5) - 0.5;
|
||||
int isx = cvFloor(fsx);
|
||||
_dim[dx] = std::make_pair(isx, fsx - isx);
|
||||
@@ -580,12 +580,12 @@ void CV_Resize_Test::resize_generic()
|
||||
{
|
||||
Size dsize = reference_dst.size(), ssize = src.size();
|
||||
CV_Assert(dsize.area() > 0 && ssize.area() > 0);
|
||||
|
||||
|
||||
dim dims[] = { dim(dsize.width), dim(dsize.height) };
|
||||
if (interpolation == INTER_NEAREST)
|
||||
{
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
dims[0][dx].first = std::min(cvFloor(dx * scale_x), ssize.width - 1);
|
||||
dims[0][dx].first = std::min(cvFloor(dx * scale_x), ssize.width - 1);
|
||||
for (int dy = 0; dy < dsize.height; ++dy)
|
||||
dims[1][dy].first = std::min(cvFloor(dy * scale_y), ssize.height - 1);
|
||||
}
|
||||
@@ -594,14 +594,14 @@ void CV_Resize_Test::resize_generic()
|
||||
generate_buffer(scale_x, dims[0]);
|
||||
generate_buffer(scale_y, dims[1]);
|
||||
}
|
||||
|
||||
|
||||
Mat tmp(ssize.height, dsize.width, reference_dst.type());
|
||||
for (int dy = 0; dy < tmp.rows; ++dy)
|
||||
resize_1d(src, tmp, dy, dims[0]);
|
||||
|
||||
transpose(tmp, tmp);
|
||||
transpose(reference_dst, reference_dst);
|
||||
|
||||
|
||||
for (int dy = 0; dy < tmp.rows; ++dy)
|
||||
resize_1d(tmp, reference_dst, dy, dims[1]);
|
||||
transpose(reference_dst, reference_dst);
|
||||
@@ -634,7 +634,7 @@ protected:
|
||||
Scalar borderValue;
|
||||
|
||||
remap_func funcs[2];
|
||||
|
||||
|
||||
private:
|
||||
void remap_nearest(const Mat&, Mat&);
|
||||
void remap_generic(const Mat&, Mat&);
|
||||
@@ -671,7 +671,7 @@ void CV_Remap_Test::generate_test_data()
|
||||
|
||||
const int n = std::min(std::min(src.cols, src.rows) / 10 + 1, 2);
|
||||
float _n = 0; //static_cast<float>(-n);
|
||||
|
||||
|
||||
switch (mapx.type())
|
||||
{
|
||||
case CV_16SC2:
|
||||
@@ -737,7 +737,7 @@ void CV_Remap_Test::generate_test_data()
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
@@ -756,7 +756,7 @@ void CV_Remap_Test::convert_maps()
|
||||
else if (interpolation != INTER_NEAREST)
|
||||
if (mapy.type() != CV_16UC1)
|
||||
mapy.clone().convertTo(mapy, CV_16UC1);
|
||||
|
||||
|
||||
if (interpolation == INTER_NEAREST)
|
||||
mapy = Mat();
|
||||
CV_Assert(((interpolation == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16UC1 ||
|
||||
@@ -803,7 +803,7 @@ void CV_Remap_Test::run_reference_func()
|
||||
|
||||
if (interpolation == INTER_AREA)
|
||||
interpolation = INTER_LINEAR;
|
||||
|
||||
|
||||
int index = interpolation == INTER_NEAREST ? 0 : 1;
|
||||
(this->*funcs[index])(src, reference_dst);
|
||||
}
|
||||
@@ -821,7 +821,7 @@ void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst)
|
||||
{
|
||||
const short* yM = mapx.ptr<short>(dy);
|
||||
float* yD = _dst.ptr<float>(dy);
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
{
|
||||
float* xyD = yD + cn * dx;
|
||||
@@ -858,7 +858,7 @@ void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst)
|
||||
void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
|
||||
{
|
||||
CV_Assert(mapx.type() == CV_16SC2 && mapy.type() == CV_16UC1);
|
||||
|
||||
|
||||
int ksize = 2;
|
||||
if (interpolation == INTER_CUBIC)
|
||||
ksize = 4;
|
||||
@@ -867,7 +867,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
|
||||
else if (interpolation != INTER_LINEAR)
|
||||
assert(0);
|
||||
int ofs = (ksize / 2) - 1;
|
||||
|
||||
|
||||
CV_Assert(_src.depth() == CV_32F && _dst.type() == _src.type());
|
||||
Size ssize = _src.size(), dsize = _dst.size();
|
||||
int cn = _src.channels(), width1 = std::max(ssize.width - ksize + 1, 0),
|
||||
@@ -882,7 +882,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
|
||||
const ushort* yMy = mapy.ptr<ushort>(dy);
|
||||
|
||||
float* yD = _dst.ptr<float>(dy);
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx)
|
||||
{
|
||||
float* xyD = yD + dx * cn;
|
||||
@@ -891,7 +891,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
|
||||
|
||||
inter_func((yMy[dx] & (INTER_TAB_SIZE - 1)) / static_cast<float>(INTER_TAB_SIZE), w);
|
||||
inter_func(((yMy[dx] >> INTER_BITS) & (INTER_TAB_SIZE - 1)) / static_cast<float>(INTER_TAB_SIZE), w + ksize);
|
||||
|
||||
|
||||
isx -= ofs;
|
||||
isy -= ofs;
|
||||
|
||||
@@ -915,7 +915,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
|
||||
else if (borderType != BORDER_TRANSPARENT)
|
||||
{
|
||||
int ar_x[8], ar_y[8];
|
||||
|
||||
|
||||
for (int k = 0; k < ksize; k++)
|
||||
{
|
||||
ar_x[k] = borderInterpolate(isx + k, ssize.width, borderType) * cn;
|
||||
@@ -1009,7 +1009,7 @@ void CV_WarpAffine_Test::generate_test_data()
|
||||
M.convertTo(tmp, depth);
|
||||
M = tmp;
|
||||
}
|
||||
|
||||
|
||||
// warp_matrix is inverse
|
||||
if (rng.uniform(0., 1.) > 0)
|
||||
interpolation |= CV_WARP_INVERSE_MAP;
|
||||
@@ -1042,7 +1042,7 @@ void CV_WarpAffine_Test::warpAffine(const Mat& _src, Mat& _dst)
|
||||
|
||||
Mat tM;
|
||||
M.convertTo(tM, CV_64F);
|
||||
|
||||
|
||||
int inter = interpolation & INTER_MAX;
|
||||
if (inter == INTER_AREA)
|
||||
inter = INTER_LINEAR;
|
||||
@@ -1052,35 +1052,35 @@ void CV_WarpAffine_Test::warpAffine(const Mat& _src, Mat& _dst)
|
||||
mapy.create(dsize, CV_16SC1);
|
||||
else
|
||||
mapy = Mat();
|
||||
|
||||
|
||||
if (!(interpolation & CV_WARP_INVERSE_MAP))
|
||||
invertAffineTransform(tM.clone(), tM);
|
||||
|
||||
|
||||
const int AB_BITS = MAX(10, (int)INTER_BITS);
|
||||
const int AB_SCALE = 1 << AB_BITS;
|
||||
const int AB_SCALE = 1 << AB_BITS;
|
||||
int round_delta = (inter == INTER_NEAREST) ? AB_SCALE / 2 : (AB_SCALE / INTER_TAB_SIZE / 2);
|
||||
|
||||
|
||||
const double* data_tM = tM.ptr<double>(0);
|
||||
for (int dy = 0; dy < dsize.height; ++dy)
|
||||
{
|
||||
short* yM = mapx.ptr<short>(dy);
|
||||
for (int dx = 0; dx < dsize.width; ++dx, yM += 2)
|
||||
{
|
||||
int v1 = saturate_cast<int>(saturate_cast<int>(data_tM[0] * dx * AB_SCALE) +
|
||||
saturate_cast<int>((data_tM[1] * dy + data_tM[2]) * AB_SCALE) + round_delta),
|
||||
v2 = saturate_cast<int>(saturate_cast<int>(data_tM[3] * dx * AB_SCALE) +
|
||||
{
|
||||
int v1 = saturate_cast<int>(saturate_cast<int>(data_tM[0] * dx * AB_SCALE) +
|
||||
saturate_cast<int>((data_tM[1] * dy + data_tM[2]) * AB_SCALE) + round_delta),
|
||||
v2 = saturate_cast<int>(saturate_cast<int>(data_tM[3] * dx * AB_SCALE) +
|
||||
saturate_cast<int>((data_tM[4] * dy + data_tM[5]) * AB_SCALE) + round_delta);
|
||||
v1 >>= AB_BITS - INTER_BITS;
|
||||
v2 >>= AB_BITS - INTER_BITS;
|
||||
|
||||
yM[0] = saturate_cast<short>(v1 >> INTER_BITS);
|
||||
yM[1] = saturate_cast<short>(v2 >> INTER_BITS);
|
||||
|
||||
|
||||
if (inter != INTER_NEAREST)
|
||||
mapy.ptr<short>(dy)[dx] = ((v2 & (INTER_TAB_SIZE - 1)) * INTER_TAB_SIZE + (v1 & (INTER_TAB_SIZE - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1));
|
||||
cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue);
|
||||
}
|
||||
@@ -1106,7 +1106,7 @@ protected:
|
||||
private:
|
||||
void warpPerspective(const Mat&, Mat&);
|
||||
};
|
||||
|
||||
|
||||
CV_WarpPerspective_Test::CV_WarpPerspective_Test() :
|
||||
CV_WarpAffine_Test()
|
||||
{
|
||||
@@ -1156,24 +1156,24 @@ void CV_WarpPerspective_Test::warpPerspective(const Mat& _src, Mat& _dst)
|
||||
CV_Assert(dsize.area() > 0);
|
||||
CV_Assert(_src.type() == _dst.type());
|
||||
|
||||
if (M.depth() != CV_64F)
|
||||
{
|
||||
Mat tmp;
|
||||
M.convertTo(tmp, CV_64F);
|
||||
M = tmp;
|
||||
}
|
||||
|
||||
if (M.depth() != CV_64F)
|
||||
{
|
||||
Mat tmp;
|
||||
M.convertTo(tmp, CV_64F);
|
||||
M = tmp;
|
||||
}
|
||||
|
||||
if (!(interpolation & CV_WARP_INVERSE_MAP))
|
||||
{
|
||||
Mat tmp;
|
||||
invert(M, tmp);
|
||||
M = tmp;
|
||||
}
|
||||
|
||||
|
||||
int inter = interpolation & INTER_MAX;
|
||||
if (inter == INTER_AREA)
|
||||
inter = INTER_LINEAR;
|
||||
|
||||
|
||||
mapx.create(dsize, CV_16SC2);
|
||||
if (inter != INTER_NEAREST)
|
||||
mapy.create(dsize, CV_16SC1);
|
||||
@@ -1184,30 +1184,30 @@ void CV_WarpPerspective_Test::warpPerspective(const Mat& _src, Mat& _dst)
|
||||
for (int dy = 0; dy < dsize.height; ++dy)
|
||||
{
|
||||
short* yMx = mapx.ptr<short>(dy);
|
||||
|
||||
|
||||
for (int dx = 0; dx < dsize.width; ++dx, yMx += 2)
|
||||
{
|
||||
double den = tM[6] * dx + tM[7] * dy + tM[8];
|
||||
den = den ? 1.0 / den : 0.0;
|
||||
|
||||
|
||||
if (inter == INTER_NEAREST)
|
||||
{
|
||||
yMx[0] = saturate_cast<short>((tM[0] * dx + tM[1] * dy + tM[2]) * den);
|
||||
yMx[1] = saturate_cast<short>((tM[3] * dx + tM[4] * dy + tM[5]) * den);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
den *= INTER_TAB_SIZE;
|
||||
int v0 = saturate_cast<int>((tM[0] * dx + tM[1] * dy + tM[2]) * den);
|
||||
int v1 = saturate_cast<int>((tM[3] * dx + tM[4] * dy + tM[5]) * den);
|
||||
|
||||
|
||||
yMx[0] = saturate_cast<short>(v0 >> INTER_BITS);
|
||||
yMx[1] = saturate_cast<short>(v1 >> INTER_BITS);
|
||||
mapy.ptr<short>(dy)[dx] = saturate_cast<short>((v1 & (INTER_TAB_SIZE - 1)) *
|
||||
mapy.ptr<short>(dy)[dx] = saturate_cast<short>((v1 & (INTER_TAB_SIZE - 1)) *
|
||||
INTER_TAB_SIZE + (v0 & (INTER_TAB_SIZE - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1));
|
||||
cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
CV_MomentsTest();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
enum { MOMENT_COUNT = 25 };
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void prepare_to_validation( int /*test_case_idx*/ );
|
||||
@@ -78,7 +78,7 @@ void CV_MomentsTest::get_minmax_bounds( int i, int j, int type, Scalar& low, Sca
|
||||
{
|
||||
cvtest::ArrayTest::get_minmax_bounds( i, j, type, low, high );
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
|
||||
|
||||
if( depth == CV_16U )
|
||||
{
|
||||
low = Scalar::all(0);
|
||||
@@ -167,7 +167,7 @@ void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
int cn = src.channels();
|
||||
int i, y, x, cols = src.cols;
|
||||
double xc = 0., yc = 0.;
|
||||
|
||||
|
||||
memset( &m, 0, sizeof(m));
|
||||
|
||||
for( y = 0; y < src.rows; y++ )
|
||||
@@ -199,7 +199,7 @@ void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
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;
|
||||
@@ -243,7 +243,7 @@ void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
|
||||
m.mu02 += s0*y1*y1;
|
||||
m.mu03 += ((s0*y1)*y1)*y1;
|
||||
|
||||
|
||||
m.mu11 += s1*y1;
|
||||
m.mu12 += (s1*y1)*y1;
|
||||
|
||||
@@ -291,9 +291,9 @@ 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, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
@@ -367,7 +367,7 @@ void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
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;
|
||||
@@ -396,7 +396,7 @@ class CV_SmallContourMomentTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_SmallContourMomentTest() {}
|
||||
~CV_SmallContourMomentTest() {}
|
||||
~CV_SmallContourMomentTest() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
@@ -407,10 +407,10 @@ protected:
|
||||
points.push_back(Point(53, 53));
|
||||
points.push_back(Point(46, 54));
|
||||
points.push_back(Point(49, 51));
|
||||
|
||||
|
||||
Moments m = moments(points, false);
|
||||
double area = contourArea(points);
|
||||
|
||||
|
||||
CV_Assert( m.m00 == 0 && m.m01 == 0 && m.m10 == 0 && area == 0 );
|
||||
}
|
||||
catch(...)
|
||||
|
||||
@@ -127,7 +127,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
|
||||
int width_n = _src.cols*cn, height = _src.rows;
|
||||
int ithresh = cvFloor(thresh);
|
||||
int imaxval, ithresh2;
|
||||
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
ithresh2 = saturate_cast<uchar>(ithresh);
|
||||
@@ -145,7 +145,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
|
||||
}
|
||||
|
||||
assert( depth == CV_8U || depth == CV_16S || depth == CV_32F );
|
||||
|
||||
|
||||
switch( thresh_type )
|
||||
{
|
||||
case CV_THRESH_BINARY:
|
||||
|
||||
Reference in New Issue
Block a user