mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Normalize line endings and whitespace
This commit is contained in:
committed by
Andrey Kamaev
parent
69020da607
commit
04384a71e4
@@ -67,7 +67,7 @@ CVAPI(void) cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc
|
||||
/* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
|
||||
CVAPI(void) cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
|
||||
const CvArr* mask CV_DEFAULT(NULL) );
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Image Processing *
|
||||
\****************************************************************************************/
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using namespace testing;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
CV_ENUM(Mat_Type, CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3)
|
||||
|
||||
typedef TestBaseWithParam< tr1::tuple<Size, int, Mat_Type> > TestBilateralFilter;
|
||||
|
||||
PERF_TEST_P( TestBilateralFilter, BilateralFilter,
|
||||
Combine(
|
||||
Values( szVGA, sz1080p ), // image size
|
||||
Values( 3, 5 ), // d
|
||||
ValuesIn( Mat_Type::all() ) // image type
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz;
|
||||
int d, type;
|
||||
const double sigmaColor = 1., sigmaSpace = 1.;
|
||||
|
||||
sz = get<0>(GetParam());
|
||||
d = get<1>(GetParam());
|
||||
type = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst).time(20);
|
||||
|
||||
TEST_CYCLE() bilateralFilter(src, dst, d, sigmaColor, sigmaSpace, BORDER_DEFAULT);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using namespace testing;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
CV_ENUM(Mat_Type, CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3)
|
||||
|
||||
typedef TestBaseWithParam< tr1::tuple<Size, int, Mat_Type> > TestBilateralFilter;
|
||||
|
||||
PERF_TEST_P( TestBilateralFilter, BilateralFilter,
|
||||
Combine(
|
||||
Values( szVGA, sz1080p ), // image size
|
||||
Values( 3, 5 ), // d
|
||||
ValuesIn( Mat_Type::all() ) // image type
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz;
|
||||
int d, type;
|
||||
const double sigmaColor = 1., sigmaSpace = 1.;
|
||||
|
||||
sz = get<0>(GetParam());
|
||||
d = get<1>(GetParam());
|
||||
type = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst).time(20);
|
||||
|
||||
TEST_CYCLE() bilateralFilter(src, dst, d, sigmaColor, sigmaSpace, BORDER_DEFAULT);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ PERF_TEST_P(Img_BlockSize_ApertureSize_BorderType, cornerEigenValsAndVecs,
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
if (src.empty())
|
||||
FAIL() << "Unable to load source image" << filename;
|
||||
|
||||
|
||||
Mat dst;
|
||||
|
||||
TEST_CYCLE() cornerEigenValsAndVecs(src, dst, blockSize, apertureSize, borderType);
|
||||
|
||||
@@ -30,7 +30,7 @@ PERF_TEST_P(Img_BlockSize_ApertureSize_k_BorderType, cornerHarris,
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
if (src.empty())
|
||||
FAIL() << "Unable to load source image" << filename;
|
||||
|
||||
|
||||
Mat dst;
|
||||
|
||||
TEST_CYCLE() cornerHarris(src, dst, blockSize, apertureSize, k, borderType);
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using namespace testing;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
|
||||
CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101);
|
||||
|
||||
typedef TestBaseWithParam< tr1::tuple<Size, int, BorderMode> > TestFilter2d;
|
||||
typedef TestBaseWithParam< tr1::tuple<String, int> > Image_KernelSize;
|
||||
|
||||
PERF_TEST_P( TestFilter2d, Filter2d,
|
||||
Combine(
|
||||
Values( Size(320, 240), szVGA, sz720p, sz1080p ),
|
||||
Values( 3, 5 ),
|
||||
ValuesIn( BorderMode::all() )
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz;
|
||||
int borderMode, kSize;
|
||||
sz = get<0>(GetParam());
|
||||
kSize = get<1>(GetParam());
|
||||
borderMode = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, CV_8UC4);
|
||||
Mat dst(sz, CV_8UC4);
|
||||
|
||||
Mat kernel(kSize, kSize, CV_32FC1);
|
||||
randu(kernel, -3, 10);
|
||||
double s = fabs( sum(kernel)[0] );
|
||||
if(s > 1e-3) kernel /= s;
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst).time(20);
|
||||
|
||||
TEST_CYCLE() filter2D(src, dst, CV_8UC4, kernel, Point(1, 1), 0., borderMode);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
PERF_TEST_P( Image_KernelSize, GaborFilter2d,
|
||||
Combine(
|
||||
Values("stitching/a1.png", "cv/shared/pic5.png"),
|
||||
Values(16, 32, 64) )
|
||||
)
|
||||
{
|
||||
String fileName = getDataPath(get<0>(GetParam()));
|
||||
Mat sourceImage = imread(fileName, IMREAD_GRAYSCALE);
|
||||
if( sourceImage.empty() )
|
||||
{
|
||||
FAIL() << "Unable to load source image" << fileName;
|
||||
}
|
||||
|
||||
int kernelSize = get<1>(GetParam());
|
||||
double sigma = 4;
|
||||
double lambda = 11;
|
||||
double theta = 47;
|
||||
double gamma = 0.5;
|
||||
Mat gaborKernel = getGaborKernel(Size(kernelSize, kernelSize), sigma, theta, lambda, gamma);
|
||||
Mat filteredImage;
|
||||
|
||||
declare.in(sourceImage);
|
||||
|
||||
TEST_CYCLE()
|
||||
{
|
||||
filter2D(sourceImage, filteredImage, CV_32F, gaborKernel);
|
||||
}
|
||||
|
||||
SANITY_CHECK(filteredImage);
|
||||
}
|
||||
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using namespace testing;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
|
||||
CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101);
|
||||
|
||||
typedef TestBaseWithParam< tr1::tuple<Size, int, BorderMode> > TestFilter2d;
|
||||
typedef TestBaseWithParam< tr1::tuple<String, int> > Image_KernelSize;
|
||||
|
||||
PERF_TEST_P( TestFilter2d, Filter2d,
|
||||
Combine(
|
||||
Values( Size(320, 240), szVGA, sz720p, sz1080p ),
|
||||
Values( 3, 5 ),
|
||||
ValuesIn( BorderMode::all() )
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz;
|
||||
int borderMode, kSize;
|
||||
sz = get<0>(GetParam());
|
||||
kSize = get<1>(GetParam());
|
||||
borderMode = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, CV_8UC4);
|
||||
Mat dst(sz, CV_8UC4);
|
||||
|
||||
Mat kernel(kSize, kSize, CV_32FC1);
|
||||
randu(kernel, -3, 10);
|
||||
double s = fabs( sum(kernel)[0] );
|
||||
if(s > 1e-3) kernel /= s;
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst).time(20);
|
||||
|
||||
TEST_CYCLE() filter2D(src, dst, CV_8UC4, kernel, Point(1, 1), 0., borderMode);
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
PERF_TEST_P( Image_KernelSize, GaborFilter2d,
|
||||
Combine(
|
||||
Values("stitching/a1.png", "cv/shared/pic5.png"),
|
||||
Values(16, 32, 64) )
|
||||
)
|
||||
{
|
||||
String fileName = getDataPath(get<0>(GetParam()));
|
||||
Mat sourceImage = imread(fileName, IMREAD_GRAYSCALE);
|
||||
if( sourceImage.empty() )
|
||||
{
|
||||
FAIL() << "Unable to load source image" << fileName;
|
||||
}
|
||||
|
||||
int kernelSize = get<1>(GetParam());
|
||||
double sigma = 4;
|
||||
double lambda = 11;
|
||||
double theta = 47;
|
||||
double gamma = 0.5;
|
||||
Mat gaborKernel = getGaborKernel(Size(kernelSize, kernelSize), sigma, theta, lambda, gamma);
|
||||
Mat filteredImage;
|
||||
|
||||
declare.in(sourceImage);
|
||||
|
||||
TEST_CYCLE()
|
||||
{
|
||||
filter2D(sourceImage, filteredImage, CV_32F, gaborKernel);
|
||||
}
|
||||
|
||||
SANITY_CHECK(filteredImage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,
|
||||
testing::Values( "cv/shared/pic5.png", "stitching/a1.png" ),
|
||||
testing::Values( 1, 10 ),
|
||||
testing::Values( 0.01, 0.1 ),
|
||||
testing::Values( 300, 500 )
|
||||
testing::Values( 300, 500 )
|
||||
)
|
||||
)
|
||||
{
|
||||
@@ -28,9 +28,9 @@ PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,
|
||||
Mat image = imread(filename, IMREAD_GRAYSCALE);
|
||||
if (image.empty())
|
||||
FAIL() << "Unable to load source image" << filename;
|
||||
|
||||
|
||||
Canny(image, image, 0, 0);
|
||||
|
||||
|
||||
Mat lines;
|
||||
declare.time(7);
|
||||
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
typedef std::tr1::tuple<Size, MatType, MatDepth> Size_MatType_OutMatDepth_t;
|
||||
typedef perf::TestBaseWithParam<Size_MatType_OutMatDepth_t> Size_MatType_OutMatDepth;
|
||||
|
||||
PERF_TEST_P(Size_MatType_OutMatDepth, integral,
|
||||
testing::Combine(
|
||||
testing::Values(TYPICAL_MAT_SIZES),
|
||||
testing::Values(CV_8UC1, CV_8UC4),
|
||||
testing::Values(CV_32S, CV_32F, CV_64F)
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
}
|
||||
|
||||
PERF_TEST_P(Size_MatType_OutMatDepth, integral_sqsum,
|
||||
testing::Combine(
|
||||
testing::Values(TYPICAL_MAT_SIZES),
|
||||
testing::Values(CV_8UC1, CV_8UC4),
|
||||
testing::Values(CV_32S, CV_32F, CV_64F)
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
Mat sqsum(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum, sqsum);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sqsum, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
SANITY_CHECK(sqsum, 1e-6);
|
||||
}
|
||||
|
||||
PERF_TEST_P( Size_MatType_OutMatDepth, integral_sqsum_tilted,
|
||||
testing::Combine(
|
||||
testing::Values( TYPICAL_MAT_SIZES ),
|
||||
testing::Values( CV_8UC1, CV_8UC4 ),
|
||||
testing::Values( CV_32S, CV_32F, CV_64F )
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
Mat sqsum(sz, sdepth);
|
||||
Mat tilted(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum, sqsum, tilted);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sqsum, tilted, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
SANITY_CHECK(sqsum, 1e-6);
|
||||
SANITY_CHECK(tilted, 1e-6, tilted.depth() > CV_32S ? ERROR_RELATIVE : ERROR_ABSOLUTE);
|
||||
}
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
typedef std::tr1::tuple<Size, MatType, MatDepth> Size_MatType_OutMatDepth_t;
|
||||
typedef perf::TestBaseWithParam<Size_MatType_OutMatDepth_t> Size_MatType_OutMatDepth;
|
||||
|
||||
PERF_TEST_P(Size_MatType_OutMatDepth, integral,
|
||||
testing::Combine(
|
||||
testing::Values(TYPICAL_MAT_SIZES),
|
||||
testing::Values(CV_8UC1, CV_8UC4),
|
||||
testing::Values(CV_32S, CV_32F, CV_64F)
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
}
|
||||
|
||||
PERF_TEST_P(Size_MatType_OutMatDepth, integral_sqsum,
|
||||
testing::Combine(
|
||||
testing::Values(TYPICAL_MAT_SIZES),
|
||||
testing::Values(CV_8UC1, CV_8UC4),
|
||||
testing::Values(CV_32S, CV_32F, CV_64F)
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
Mat sqsum(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum, sqsum);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sqsum, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
SANITY_CHECK(sqsum, 1e-6);
|
||||
}
|
||||
|
||||
PERF_TEST_P( Size_MatType_OutMatDepth, integral_sqsum_tilted,
|
||||
testing::Combine(
|
||||
testing::Values( TYPICAL_MAT_SIZES ),
|
||||
testing::Values( CV_8UC1, CV_8UC4 ),
|
||||
testing::Values( CV_32S, CV_32F, CV_64F )
|
||||
)
|
||||
)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int matType = get<1>(GetParam());
|
||||
int sdepth = get<2>(GetParam());
|
||||
|
||||
Mat src(sz, matType);
|
||||
Mat sum(sz, sdepth);
|
||||
Mat sqsum(sz, sdepth);
|
||||
Mat tilted(sz, sdepth);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(sum, sqsum, tilted);
|
||||
|
||||
TEST_CYCLE() integral(src, sum, sqsum, tilted, sdepth);
|
||||
|
||||
SANITY_CHECK(sum, 1e-6);
|
||||
SANITY_CHECK(sqsum, 1e-6);
|
||||
SANITY_CHECK(tilted, 1e-6, tilted.depth() > CV_32S ? ERROR_RELATIVE : ERROR_ABSOLUTE);
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
#define TYPICAL_MAT_TYPES_MORPH CV_8UC1, CV_8UC4
|
||||
#define TYPICAL_MATS_MORPH testing::Combine(SZ_ALL_GA, testing::Values(TYPICAL_MAT_TYPES_MORPH))
|
||||
|
||||
PERF_TEST_P(Size_MatType, erode, TYPICAL_MATS_MORPH)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int type = get<1>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
TEST_CYCLE() erode(src, dst, noArray());
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
PERF_TEST_P(Size_MatType, dilate, TYPICAL_MATS_MORPH)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int type = get<1>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
TEST_CYCLE() dilate(src, dst, noArray());
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
#define TYPICAL_MAT_TYPES_MORPH CV_8UC1, CV_8UC4
|
||||
#define TYPICAL_MATS_MORPH testing::Combine(SZ_ALL_GA, testing::Values(TYPICAL_MAT_TYPES_MORPH))
|
||||
|
||||
PERF_TEST_P(Size_MatType, erode, TYPICAL_MATS_MORPH)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int type = get<1>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
TEST_CYCLE() erode(src, dst, noArray());
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
PERF_TEST_P(Size_MatType, dilate, TYPICAL_MATS_MORPH)
|
||||
{
|
||||
Size sz = get<0>(GetParam());
|
||||
int type = get<1>(GetParam());
|
||||
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
TEST_CYCLE() dilate(src, dst, noArray());
|
||||
|
||||
SANITY_CHECK(dst);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ PERF_TEST_P(MatInfo_Size_Scale_Area, ResizeArea,
|
||||
double scale = get<2>(GetParam());
|
||||
|
||||
cv::Mat src(from, matType);
|
||||
|
||||
|
||||
Size to(cvRound(from.width * scale), cvRound(from.height * scale));
|
||||
cv::Mat dst(to, matType);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize, adaptiveThreshold,
|
||||
|
||||
double maxValue = theRNG().uniform(1, 254);
|
||||
double C = 10.0;
|
||||
|
||||
|
||||
int type = CV_8UC1;
|
||||
Mat src(sz, type);
|
||||
Mat dst(sz, type);
|
||||
|
||||
@@ -49,18 +49,18 @@ template<typename T, typename AT> void
|
||||
acc_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
len *= cn;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= len - 4; i += 4 )
|
||||
{
|
||||
AT t0, t1;
|
||||
t0 = src[i] + dst[i];
|
||||
t1 = src[i+1] + dst[i+1];
|
||||
dst[i] = t0; dst[i+1] = t1;
|
||||
|
||||
|
||||
t0 = src[i+2] + dst[i+2];
|
||||
t1 = src[i+3] + dst[i+3];
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
@@ -86,7 +86,7 @@ acc_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
AT t0 = src[0] + dst[0];
|
||||
AT t1 = src[1] + dst[1];
|
||||
AT t2 = src[2] + dst[2];
|
||||
|
||||
|
||||
dst[0] = t0; dst[1] = t1; dst[2] = t2;
|
||||
}
|
||||
}
|
||||
@@ -102,23 +102,23 @@ acc_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, typename AT> void
|
||||
accSqr_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
len *= cn;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= len - 4; i += 4 )
|
||||
{
|
||||
AT t0, t1;
|
||||
t0 = (AT)src[i]*src[i] + dst[i];
|
||||
t1 = (AT)src[i+1]*src[i+1] + dst[i+1];
|
||||
dst[i] = t0; dst[i+1] = t1;
|
||||
|
||||
|
||||
t0 = (AT)src[i+2]*src[i+2] + dst[i+2];
|
||||
t1 = (AT)src[i+3]*src[i+3] + dst[i+3];
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
@@ -144,7 +144,7 @@ accSqr_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
AT t0 = (AT)src[0]*src[0] + dst[0];
|
||||
AT t1 = (AT)src[1]*src[1] + dst[1];
|
||||
AT t2 = (AT)src[2]*src[2] + dst[2];
|
||||
|
||||
|
||||
dst[0] = t0; dst[1] = t1; dst[2] = t2;
|
||||
}
|
||||
}
|
||||
@@ -159,24 +159,24 @@ accSqr_( const T* src, AT* dst, const uchar* mask, int len, int cn )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T, typename AT> void
|
||||
accProd_( const T* src1, const T* src2, AT* dst, const uchar* mask, int len, int cn )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
len *= cn;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= len - 4; i += 4 )
|
||||
{
|
||||
AT t0, t1;
|
||||
t0 = (AT)src1[i]*src2[i] + dst[i];
|
||||
t1 = (AT)src1[i+1]*src2[i+1] + dst[i+1];
|
||||
dst[i] = t0; dst[i+1] = t1;
|
||||
|
||||
|
||||
t0 = (AT)src1[i+2]*src2[i+2] + dst[i+2];
|
||||
t1 = (AT)src1[i+3]*src2[i+3] + dst[i+3];
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
@@ -202,7 +202,7 @@ accProd_( const T* src1, const T* src2, AT* dst, const uchar* mask, int len, int
|
||||
AT t0 = (AT)src1[0]*src2[0] + dst[0];
|
||||
AT t1 = (AT)src1[1]*src2[1] + dst[1];
|
||||
AT t2 = (AT)src1[2]*src2[2] + dst[2];
|
||||
|
||||
|
||||
dst[0] = t0; dst[1] = t1; dst[2] = t2;
|
||||
}
|
||||
}
|
||||
@@ -218,24 +218,24 @@ accProd_( const T* src1, const T* src2, AT* dst, const uchar* mask, int len, int
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, typename AT> void
|
||||
accW_( const T* src, AT* dst, const uchar* mask, int len, int cn, double alpha )
|
||||
{
|
||||
AT a = (AT)alpha, b = 1 - a;
|
||||
int i = 0;
|
||||
|
||||
|
||||
if( !mask )
|
||||
{
|
||||
len *= cn;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= len - 4; i += 4 )
|
||||
{
|
||||
AT t0, t1;
|
||||
t0 = src[i]*a + dst[i]*b;
|
||||
t1 = src[i+1]*a + dst[i+1]*b;
|
||||
dst[i] = t0; dst[i+1] = t1;
|
||||
|
||||
|
||||
t0 = src[i+2]*a + dst[i+2]*b;
|
||||
t1 = src[i+3]*a + dst[i+3]*b;
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
@@ -261,7 +261,7 @@ accW_( const T* src, AT* dst, const uchar* mask, int len, int cn, double alpha )
|
||||
AT t0 = src[0]*a + dst[0]*b;
|
||||
AT t1 = src[1]*a + dst[1]*b;
|
||||
AT t2 = src[2]*a + dst[2]*b;
|
||||
|
||||
|
||||
dst[0] = t0; dst[1] = t1; dst[2] = t2;
|
||||
}
|
||||
}
|
||||
@@ -303,8 +303,8 @@ DEF_ACC_FUNCS(16u64f, ushort, double)
|
||||
DEF_ACC_FUNCS(32f, float, float)
|
||||
DEF_ACC_FUNCS(32f64f, float, double)
|
||||
DEF_ACC_FUNCS(64f, double, double)
|
||||
|
||||
|
||||
|
||||
|
||||
typedef void (*AccFunc)(const uchar*, uchar*, const uchar*, int, int);
|
||||
typedef void (*AccProdFunc)(const uchar*, const uchar*, uchar*, const uchar*, int, int);
|
||||
typedef void (*AccWFunc)(const uchar*, uchar*, const uchar*, int, int, double);
|
||||
@@ -350,27 +350,27 @@ inline int getAccTabIdx(int sdepth, int ddepth)
|
||||
sdepth == CV_32F && ddepth == CV_32F ? 4 :
|
||||
sdepth == CV_32F && ddepth == CV_64F ? 5 :
|
||||
sdepth == CV_64F && ddepth == CV_64F ? 6 : -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cv::accumulate( InputArray _src, InputOutputArray _dst, InputArray _mask )
|
||||
{
|
||||
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
|
||||
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
|
||||
|
||||
|
||||
CV_Assert( dst.size == src.size && dst.channels() == cn );
|
||||
CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) );
|
||||
|
||||
|
||||
int fidx = getAccTabIdx(sdepth, ddepth);
|
||||
AccFunc func = fidx >= 0 ? accTab[fidx] : 0;
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &dst, &mask, 0};
|
||||
uchar* ptrs[3];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int len = (int)it.size;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
func(ptrs[0], ptrs[1], ptrs[2], len, cn);
|
||||
}
|
||||
@@ -380,19 +380,19 @@ void cv::accumulateSquare( InputArray _src, InputOutputArray _dst, InputArray _m
|
||||
{
|
||||
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
|
||||
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
|
||||
|
||||
|
||||
CV_Assert( dst.size == src.size && dst.channels() == cn );
|
||||
CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) );
|
||||
|
||||
|
||||
int fidx = getAccTabIdx(sdepth, ddepth);
|
||||
AccFunc func = fidx >= 0 ? accSqrTab[fidx] : 0;
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &dst, &mask, 0};
|
||||
uchar* ptrs[3];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int len = (int)it.size;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
func(ptrs[0], ptrs[1], ptrs[2], len, cn);
|
||||
}
|
||||
@@ -402,20 +402,20 @@ void cv::accumulateProduct( InputArray _src1, InputArray _src2,
|
||||
{
|
||||
Mat src1 = _src1.getMat(), src2 = _src2.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
|
||||
int sdepth = src1.depth(), ddepth = dst.depth(), cn = src1.channels();
|
||||
|
||||
|
||||
CV_Assert( src2.size && src1.size && src2.type() == src1.type() );
|
||||
CV_Assert( dst.size == src1.size && dst.channels() == cn );
|
||||
CV_Assert( mask.empty() || (mask.size == src1.size && mask.type() == CV_8U) );
|
||||
|
||||
|
||||
int fidx = getAccTabIdx(sdepth, ddepth);
|
||||
AccProdFunc func = fidx >= 0 ? accProdTab[fidx] : 0;
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src1, &src2, &dst, &mask, 0};
|
||||
uchar* ptrs[4];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int len = (int)it.size;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
func(ptrs[0], ptrs[1], ptrs[2], ptrs[3], len, cn);
|
||||
}
|
||||
@@ -426,19 +426,19 @@ void cv::accumulateWeighted( InputArray _src, InputOutputArray _dst,
|
||||
{
|
||||
Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat();
|
||||
int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels();
|
||||
|
||||
|
||||
CV_Assert( dst.size == src.size && dst.channels() == cn );
|
||||
CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) );
|
||||
|
||||
|
||||
int fidx = getAccTabIdx(sdepth, ddepth);
|
||||
AccWFunc func = fidx >= 0 ? accWTab[fidx] : 0;
|
||||
CV_Assert( func != 0 );
|
||||
|
||||
|
||||
const Mat* arrays[] = {&src, &dst, &mask, 0};
|
||||
uchar* ptrs[3];
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int len = (int)it.size;
|
||||
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
func(ptrs[0], ptrs[1], ptrs[2], len, cn, alpha);
|
||||
}
|
||||
|
||||
@@ -648,7 +648,7 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size,
|
||||
dx = end_pt.x - start_pt.x;
|
||||
dy = end_pt.y - start_pt.y;
|
||||
dist = fabs((pt.x - start_pt.x)*dy - (pt.y - start_pt.y)*dx);
|
||||
successive_inner_product = (pt.x - start_pt.x) * (end_pt.x - pt.x) +
|
||||
successive_inner_product = (pt.x - start_pt.x) * (end_pt.x - pt.x) +
|
||||
(pt.y - start_pt.y) * (end_pt.y - pt.y);
|
||||
|
||||
if( dist * dist <= 0.5*eps*(dx*dx + dy*dy) && dx != 0 && dy != 0 &&
|
||||
|
||||
@@ -47,7 +47,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CV_Assert( src.depth() == CV_8U );
|
||||
|
||||
|
||||
_dst.create(src.size(), CV_8U);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
@@ -80,7 +80,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
|
||||
{
|
||||
low_thresh = std::min(32767.0, low_thresh);
|
||||
high_thresh = std::min(32767.0, high_thresh);
|
||||
|
||||
|
||||
if (low_thresh > 0) low_thresh *= low_thresh;
|
||||
if (high_thresh > 0) high_thresh *= high_thresh;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
|
||||
|
||||
ptrdiff_t mapstep = src.cols + 2;
|
||||
cv::AutoBuffer<uchar> buffer((src.cols+2)*(src.rows+2) + cn * mapstep * 3 * sizeof(int));
|
||||
|
||||
|
||||
int* mag_buf[3];
|
||||
mag_buf[0] = (int*)(uchar*)buffer;
|
||||
mag_buf[1] = mag_buf[0] + mapstep*cn;
|
||||
@@ -143,7 +143,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
|
||||
for (int j = 0; j < src.cols*cn; j++)
|
||||
_norm[j] = int(_dx[j])*_dx[j] + int(_dy[j])*_dy[j];
|
||||
}
|
||||
|
||||
|
||||
if (cn > 1)
|
||||
{
|
||||
for(int j = 0, jn = 0; j < src.cols; ++j, jn += cn)
|
||||
@@ -160,7 +160,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
|
||||
}
|
||||
else
|
||||
memset(_norm-1, 0, /* cn* */mapstep*sizeof(int));
|
||||
|
||||
|
||||
// at the very beginning we do not have a complete ring
|
||||
// buffer of 3 magnitude rows for non-maxima suppression
|
||||
if (i == 0)
|
||||
@@ -280,7 +280,7 @@ void cvCanny( const CvArr* image, CvArr* edges, double threshold1,
|
||||
{
|
||||
cv::Mat src = cv::cvarrToMat(image), dst = cv::cvarrToMat(edges);
|
||||
CV_Assert( src.size == dst.size && src.depth() == CV_8U && dst.type() == CV_8U );
|
||||
|
||||
|
||||
cv::Canny(src, dst, threshold1, threshold2, aperture_size & 255,
|
||||
(aperture_size & CV_CANNY_L2_GRADIENT) != 0);
|
||||
}
|
||||
|
||||
@@ -1362,7 +1362,7 @@ struct RGB2Lab_f
|
||||
_coeffs = sRGB2XYZ_D65;
|
||||
if (!_whitept)
|
||||
_whitept = D65;
|
||||
|
||||
|
||||
float scale[] = { 1.0f / _whitept[0], 1.0f, 1.0f / _whitept[2] };
|
||||
|
||||
for( int i = 0; i < _3; i++ )
|
||||
@@ -1371,7 +1371,7 @@ struct RGB2Lab_f
|
||||
coeffs[j + (blueIdx ^ 2)] = _coeffs[j] * scale[i];
|
||||
coeffs[j + 1] = _coeffs[j + 1] * scale[i];
|
||||
coeffs[j + blueIdx] = _coeffs[j + 2] * scale[i];
|
||||
|
||||
|
||||
CV_Assert( coeffs[j] >= 0 && coeffs[j + 1] >= 0 && coeffs[j + 2] >= 0 &&
|
||||
coeffs[j] + coeffs[j + 1] + coeffs[j + 2] < 1.5f*LabCbrtTabScale );
|
||||
}
|
||||
@@ -1394,11 +1394,11 @@ struct RGB2Lab_f
|
||||
float R = clip(src[0]);
|
||||
float G = clip(src[1]);
|
||||
float B = clip(src[2]);
|
||||
|
||||
|
||||
// CV_Assert(R >= 0.0f && R <= 1.0f);
|
||||
// CV_Assert(G >= 0.0f && G <= 1.0f);
|
||||
// CV_Assert(B >= 0.0f && B <= 1.0f);
|
||||
|
||||
|
||||
if (gammaTab)
|
||||
{
|
||||
R = splineInterpolate(R * gscale, gammaTab, GAMMA_TAB_SIZE);
|
||||
@@ -1408,15 +1408,15 @@ struct RGB2Lab_f
|
||||
float X = R*C0 + G*C1 + B*C2;
|
||||
float Y = R*C3 + G*C4 + B*C5;
|
||||
float Z = R*C6 + G*C7 + B*C8;
|
||||
|
||||
|
||||
float FX = X > 0.008856 ? pow(X, _1_3) : (7.787f * X + _a);
|
||||
float FY = Y > 0.008856 ? pow(Y, _1_3) : (7.787f * Y + _a);
|
||||
float FZ = Z > 0.008856 ? pow(Z, _1_3) : (7.787f * Z + _a);
|
||||
|
||||
|
||||
float L = Y > 0.008856 ? (116.f * FY - 16.f) : (903.3 * Y);
|
||||
float a = 500.f * (FX - FY);
|
||||
float b = 200.f * (FY - FZ);
|
||||
|
||||
|
||||
dst[i] = L;
|
||||
dst[i + 1] = a;
|
||||
dst[i + 2] = b;
|
||||
@@ -1427,22 +1427,22 @@ struct RGB2Lab_f
|
||||
float coeffs[9];
|
||||
bool srgb;
|
||||
};
|
||||
|
||||
|
||||
struct Lab2RGB_f
|
||||
{
|
||||
typedef float channel_type;
|
||||
|
||||
|
||||
Lab2RGB_f( int _dstcn, int blueIdx, const float* _coeffs,
|
||||
const float* _whitept, bool _srgb )
|
||||
: dstcn(_dstcn), srgb(_srgb), blueInd(blueIdx)
|
||||
{
|
||||
initLabTabs();
|
||||
|
||||
|
||||
if(!_coeffs)
|
||||
_coeffs = XYZ2sRGB_D65;
|
||||
if(!_whitept)
|
||||
_whitept = D65;
|
||||
|
||||
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
coeffs[i+(blueIdx^2)*3] = _coeffs[i]*_whitept[i];
|
||||
@@ -1450,7 +1450,7 @@ struct Lab2RGB_f
|
||||
coeffs[i+blueIdx*3] = _coeffs[i+6]*_whitept[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void operator()(const float* src, float* dst, int n) const
|
||||
{
|
||||
int i, dcn = dstcn;
|
||||
@@ -1461,7 +1461,7 @@ struct Lab2RGB_f
|
||||
C6 = coeffs[6], C7 = coeffs[7], C8 = coeffs[8];
|
||||
float alpha = ColorChannel<float>::max();
|
||||
n *= 3;
|
||||
|
||||
|
||||
static const float lThresh = 0.008856f * 903.3f;
|
||||
static const float fThresh = 7.787f * 0.008856f + 16.0f / 116.0f;
|
||||
for (i = 0; i < n; i += 3, dst += dcn)
|
||||
@@ -1469,7 +1469,7 @@ struct Lab2RGB_f
|
||||
float li = src[i];
|
||||
float ai = src[i + 1];
|
||||
float bi = src[i + 2];
|
||||
|
||||
|
||||
float y, fy;
|
||||
if (li <= lThresh)
|
||||
{
|
||||
@@ -1481,44 +1481,44 @@ struct Lab2RGB_f
|
||||
fy = (li + 16.0f) / 116.0f;
|
||||
y = fy * fy * fy;
|
||||
}
|
||||
|
||||
|
||||
float fxz[] = { ai / 500.0f + fy, fy - bi / 200.0f };
|
||||
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
if (fxz[j] <= fThresh)
|
||||
fxz[j] = (fxz[j] - 16.0f / 116.0f) / 7.787f;
|
||||
else
|
||||
fxz[j] = fxz[j] * fxz[j] * fxz[j];
|
||||
|
||||
|
||||
|
||||
|
||||
float x = fxz[0], z = fxz[1];
|
||||
float ro = clip(C0 * x + C1 * y + C2 * z);
|
||||
float go = clip(C3 * x + C4 * y + C5 * z);
|
||||
float bo = clip(C6 * x + C7 * y + C8 * z);
|
||||
|
||||
|
||||
// CV_Assert(ro >= 0.0f && ro <= 1.0f);
|
||||
// CV_Assert(go >= 0.0f && go <= 1.0f);
|
||||
// CV_Assert(bo >= 0.0f && bo <= 1.0f);
|
||||
|
||||
|
||||
if (gammaTab)
|
||||
{
|
||||
ro = splineInterpolate(ro * gscale, gammaTab, GAMMA_TAB_SIZE);
|
||||
go = splineInterpolate(go * gscale, gammaTab, GAMMA_TAB_SIZE);
|
||||
bo = splineInterpolate(bo * gscale, gammaTab, GAMMA_TAB_SIZE);
|
||||
}
|
||||
|
||||
|
||||
dst[0] = ro, dst[1] = go, dst[2] = bo;
|
||||
if( dcn == 4 )
|
||||
dst[3] = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int dstcn;
|
||||
float coeffs[9];
|
||||
bool srgb;
|
||||
int blueInd;
|
||||
};
|
||||
|
||||
|
||||
#undef clip
|
||||
|
||||
struct Lab2RGB_b
|
||||
|
||||
@@ -159,7 +159,7 @@ typedef struct _CvContourScanner
|
||||
external contours and holes),
|
||||
3 - full hierarchy;
|
||||
4 - connected components of a multi-level image
|
||||
*/
|
||||
*/
|
||||
int subst_flag;
|
||||
int seq_type1; /* type of fetched contours */
|
||||
int header_size1; /* hdr size of fetched contours */
|
||||
@@ -190,7 +190,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
|
||||
|
||||
if( CV_MAT_TYPE(mat->type) == CV_32SC1 && mode == CV_RETR_CCOMP )
|
||||
mode = CV_RETR_FLOODFILL;
|
||||
|
||||
|
||||
if( !((CV_IS_MASK_ARR( mat ) && mode < CV_RETR_FLOODFILL) ||
|
||||
(CV_MAT_TYPE(mat->type) == CV_32SC1 && mode == CV_RETR_FLOODFILL)) )
|
||||
CV_Error( CV_StsUnsupportedFormat, "[Start]FindContours support only 8uC1 and 32sC1 images" );
|
||||
@@ -207,7 +207,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
|
||||
|
||||
CvContourScanner scanner = (CvContourScanner)cvAlloc( sizeof( *scanner ));
|
||||
memset( scanner, 0, sizeof(*scanner) );
|
||||
|
||||
|
||||
scanner->storage1 = scanner->storage2 = storage;
|
||||
scanner->img0 = (schar *) img;
|
||||
scanner->img = (schar *) (img + step);
|
||||
@@ -805,13 +805,13 @@ icvTraceContour_32s( int *ptr, int step, int *stop_ptr, int is_hole )
|
||||
const int new_flag = (int)((unsigned)INT_MIN >> 1);
|
||||
const int value_mask = ~(right_flag | new_flag);
|
||||
const int ccomp_val = *i0 & value_mask;
|
||||
|
||||
|
||||
/* initialize local state */
|
||||
CV_INIT_3X3_DELTAS( deltas, step, 1 );
|
||||
memcpy( deltas + 8, deltas, 8 * sizeof( deltas[0] ));
|
||||
|
||||
|
||||
s_end = s = is_hole ? 0 : 4;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
s = (s - 1) & 7;
|
||||
@@ -820,9 +820,9 @@ icvTraceContour_32s( int *ptr, int step, int *stop_ptr, int is_hole )
|
||||
break;
|
||||
}
|
||||
while( s != s_end );
|
||||
|
||||
|
||||
i3 = i0;
|
||||
|
||||
|
||||
/* check single pixel domain */
|
||||
if( s != s_end )
|
||||
{
|
||||
@@ -830,17 +830,17 @@ icvTraceContour_32s( int *ptr, int step, int *stop_ptr, int is_hole )
|
||||
for( ;; )
|
||||
{
|
||||
s_end = s;
|
||||
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
i4 = i3 + deltas[++s];
|
||||
if( (*i4 & value_mask) == ccomp_val )
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if( i3 == stop_ptr || (i4 == i0 && i3 == i1) )
|
||||
break;
|
||||
|
||||
|
||||
i3 = i4;
|
||||
s = (s + 4) & 7;
|
||||
} /* end of border following loop */
|
||||
@@ -869,24 +869,24 @@ icvFetchContourEx_32s( int* ptr,
|
||||
const int ccomp_val = *i0 & value_mask;
|
||||
const int nbd0 = ccomp_val | new_flag;
|
||||
const int nbd1 = nbd0 | right_flag;
|
||||
|
||||
|
||||
assert( (unsigned) _method <= CV_CHAIN_APPROX_SIMPLE );
|
||||
|
||||
|
||||
/* initialize local state */
|
||||
CV_INIT_3X3_DELTAS( deltas, step, 1 );
|
||||
memcpy( deltas + 8, deltas, 8 * sizeof( deltas[0] ));
|
||||
|
||||
|
||||
/* initialize writer */
|
||||
cvStartAppendToSeq( contour, &writer );
|
||||
|
||||
|
||||
if( method < 0 )
|
||||
((CvChain *)contour)->origin = pt;
|
||||
|
||||
|
||||
rect.x = rect.width = pt.x;
|
||||
rect.y = rect.height = pt.y;
|
||||
|
||||
|
||||
s_end = s = CV_IS_SEQ_HOLE( contour ) ? 0 : 4;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
s = (s - 1) & 7;
|
||||
@@ -895,7 +895,7 @@ icvFetchContourEx_32s( int* ptr,
|
||||
break;
|
||||
}
|
||||
while( s != s_end );
|
||||
|
||||
|
||||
if( s == s_end ) /* single pixel domain */
|
||||
{
|
||||
*i0 = nbd1;
|
||||
@@ -908,12 +908,12 @@ icvFetchContourEx_32s( int* ptr,
|
||||
{
|
||||
i3 = i0;
|
||||
prev_s = s ^ 4;
|
||||
|
||||
|
||||
/* follow border */
|
||||
for( ;; )
|
||||
{
|
||||
s_end = s;
|
||||
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
i4 = i3 + deltas[++s];
|
||||
@@ -921,7 +921,7 @@ icvFetchContourEx_32s( int* ptr,
|
||||
break;
|
||||
}
|
||||
s &= 7;
|
||||
|
||||
|
||||
/* check "right" bound */
|
||||
if( (unsigned) (s - 1) < (unsigned) s_end )
|
||||
{
|
||||
@@ -931,7 +931,7 @@ icvFetchContourEx_32s( int* ptr,
|
||||
{
|
||||
*i3 = nbd0;
|
||||
}
|
||||
|
||||
|
||||
if( method < 0 )
|
||||
{
|
||||
schar _s = (schar) s;
|
||||
@@ -941,7 +941,7 @@ icvFetchContourEx_32s( int* ptr,
|
||||
{
|
||||
CV_WRITE_SEQ_ELEM( pt, writer );
|
||||
}
|
||||
|
||||
|
||||
if( s != prev_s )
|
||||
{
|
||||
/* update bounds */
|
||||
@@ -949,37 +949,37 @@ icvFetchContourEx_32s( int* ptr,
|
||||
rect.x = pt.x;
|
||||
else if( pt.x > rect.width )
|
||||
rect.width = pt.x;
|
||||
|
||||
|
||||
if( pt.y < rect.y )
|
||||
rect.y = pt.y;
|
||||
else if( pt.y > rect.height )
|
||||
rect.height = pt.y;
|
||||
}
|
||||
|
||||
|
||||
prev_s = s;
|
||||
pt.x += icvCodeDeltas[s].x;
|
||||
pt.y += icvCodeDeltas[s].y;
|
||||
|
||||
|
||||
if( i4 == i0 && i3 == i1 ) break;
|
||||
|
||||
|
||||
i3 = i4;
|
||||
s = (s + 4) & 7;
|
||||
} /* end of border following loop */
|
||||
}
|
||||
|
||||
|
||||
rect.width -= rect.x - 1;
|
||||
rect.height -= rect.y - 1;
|
||||
|
||||
|
||||
cvEndWriteSeq( &writer );
|
||||
|
||||
|
||||
if( _method != CV_CHAIN_CODE )
|
||||
((CvContour*)contour)->rect = rect;
|
||||
|
||||
|
||||
assert( (writer.seq->total == 0 && writer.seq->first == 0) ||
|
||||
writer.seq->total > writer.seq->first->count ||
|
||||
(writer.seq->first->prev == writer.seq->first &&
|
||||
writer.seq->first->next == writer.seq->first) );
|
||||
|
||||
|
||||
if( _rect ) *_rect = rect;
|
||||
}
|
||||
|
||||
@@ -1005,7 +1005,7 @@ cvFindNextContour( CvContourScanner scanner )
|
||||
int nbd = scanner->nbd;
|
||||
int prev = img[x - 1];
|
||||
int new_mask = -2;
|
||||
|
||||
|
||||
if( mode == CV_RETR_FLOODFILL )
|
||||
{
|
||||
prev = ((int*)img)[x - 1];
|
||||
@@ -1017,13 +1017,13 @@ cvFindNextContour( CvContourScanner scanner )
|
||||
int* img0_i = 0;
|
||||
int* img_i = 0;
|
||||
int p = 0;
|
||||
|
||||
|
||||
if( mode == CV_RETR_FLOODFILL )
|
||||
{
|
||||
img0_i = (int*)img0;
|
||||
img_i = (int*)img;
|
||||
}
|
||||
|
||||
|
||||
for( ; x < width; x++ )
|
||||
{
|
||||
if( img_i )
|
||||
@@ -1036,10 +1036,10 @@ cvFindNextContour( CvContourScanner scanner )
|
||||
for( ; x < width && (p = img[x]) == prev; x++ )
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
if( x >= width )
|
||||
break;
|
||||
|
||||
|
||||
{
|
||||
_CvContourInfo *par_info = 0;
|
||||
_CvContourInfo *l_cinfo = 0;
|
||||
@@ -1053,7 +1053,7 @@ cvFindNextContour( CvContourScanner scanner )
|
||||
{
|
||||
/* check hole */
|
||||
if( (!img_i && (p != 0 || prev < 1)) ||
|
||||
(img_i && ((prev & new_mask) != 0 || (p & new_mask) != 0)))
|
||||
(img_i && ((prev & new_mask) != 0 || (p & new_mask) != 0)))
|
||||
goto resume_scan;
|
||||
|
||||
if( prev & new_mask )
|
||||
@@ -1219,7 +1219,7 @@ cvFindNextContour( CvContourScanner scanner )
|
||||
return l_cinfo->contour;
|
||||
|
||||
resume_scan:
|
||||
|
||||
|
||||
prev = p;
|
||||
/* update lnbd */
|
||||
if( prev & -2 )
|
||||
@@ -1663,7 +1663,7 @@ cvFindContours( void* img, CvMemStorage* storage,
|
||||
|
||||
if( !firstContour )
|
||||
CV_Error( CV_StsNullPtr, "NULL double CvSeq pointer" );
|
||||
|
||||
|
||||
*firstContour = 0;
|
||||
|
||||
if( method == CV_LINK_RUNS )
|
||||
@@ -1733,7 +1733,7 @@ void cv::findContours( InputOutputArray _image, OutputArrayOfArrays _contours,
|
||||
{
|
||||
_hierarchy.create(1, total, CV_32SC4, -1, true);
|
||||
Vec4i* hierarchy = _hierarchy.getMat().ptr<Vec4i>();
|
||||
|
||||
|
||||
it = all_contours.begin();
|
||||
for( i = 0; i < total; i++, ++it )
|
||||
{
|
||||
@@ -1768,19 +1768,19 @@ static void addChildContour(InputArrayOfArrays contours,
|
||||
cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
|
||||
!ci.empty() ? (void*)ci.data : 0, (int)ci.total(),
|
||||
&seq[i], &block[i] );
|
||||
|
||||
|
||||
int h_next = hierarchy[i][0], h_prev = hierarchy[i][1],
|
||||
v_next = hierarchy[i][2], v_prev = hierarchy[i][3];
|
||||
seq[i].h_next = (size_t)h_next < ncontours ? &seq[h_next] : 0;
|
||||
seq[i].h_prev = (size_t)h_prev < ncontours ? &seq[h_prev] : 0;
|
||||
seq[i].v_next = (size_t)v_next < ncontours ? &seq[v_next] : 0;
|
||||
seq[i].v_prev = (size_t)v_prev < ncontours ? &seq[v_prev] : 0;
|
||||
|
||||
|
||||
if( v_next >= 0 )
|
||||
addChildContour(contours, ncontours, hierarchy, v_next, seq, block);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours,
|
||||
@@ -1798,20 +1798,20 @@ void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours,
|
||||
|
||||
if( !last )
|
||||
return;
|
||||
|
||||
|
||||
seq.resize(last);
|
||||
block.resize(last);
|
||||
|
||||
|
||||
for( i = first; i < last; i++ )
|
||||
seq[i].first = 0;
|
||||
|
||||
|
||||
if( contourIdx >= 0 )
|
||||
{
|
||||
CV_Assert( 0 <= contourIdx && contourIdx < (int)last );
|
||||
first = contourIdx;
|
||||
last = contourIdx + 1;
|
||||
}
|
||||
|
||||
|
||||
for( i = first; i < last; i++ )
|
||||
{
|
||||
Mat ci = _contours.getMat((int)i);
|
||||
@@ -1834,7 +1834,7 @@ void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours,
|
||||
size_t count = last - first;
|
||||
CV_Assert(hierarchy.total() == ncontours && hierarchy.type() == CV_32SC4 );
|
||||
const Vec4i* h = hierarchy.ptr<Vec4i>();
|
||||
|
||||
|
||||
if( count == ncontours )
|
||||
{
|
||||
for( i = first; i < last; i++ )
|
||||
@@ -1934,7 +1934,7 @@ double cv::matchShapes( InputArray _contour1,
|
||||
CV_Assert(contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 &&
|
||||
(contour1.depth() == CV_32F || contour1.depth() == CV_32S) &&
|
||||
contour1.depth() == contour2.depth());
|
||||
|
||||
|
||||
CvMat c1 = Mat(contour1), c2 = Mat(contour2);
|
||||
return cvMatchShapes(&c1, &c2, method, parameter);
|
||||
}
|
||||
@@ -1945,13 +1945,13 @@ void cv::convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool
|
||||
Mat points = _points.getMat();
|
||||
int nelems = points.checkVector(2), depth = points.depth();
|
||||
CV_Assert(nelems >= 0 && (depth == CV_32F || depth == CV_32S));
|
||||
|
||||
|
||||
if( nelems == 0 )
|
||||
{
|
||||
_hull.release();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
returnPoints = !_hull.fixedType() ? returnPoints : _hull.type() != CV_32S;
|
||||
Mat hull(nelems, 1, returnPoints ? CV_MAKETYPE(depth, 2) : CV_32S);
|
||||
CvMat _cpoints = points, _chull = hull;
|
||||
@@ -1970,23 +1970,23 @@ void cv::convexityDefects( InputArray _points, InputArray _hull, OutputArray _de
|
||||
Mat hull = _hull.getMat();
|
||||
CV_Assert( hull.checkVector(1, CV_32S) > 2 );
|
||||
Ptr<CvMemStorage> storage = cvCreateMemStorage();
|
||||
|
||||
|
||||
CvMat c_points = points, c_hull = hull;
|
||||
CvSeq* seq = cvConvexityDefects(&c_points, &c_hull, storage);
|
||||
int i, n = seq->total;
|
||||
|
||||
|
||||
if( n == 0 )
|
||||
{
|
||||
_defects.release();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_defects.create(n, 1, CV_32SC4);
|
||||
Mat defects = _defects.getMat();
|
||||
|
||||
|
||||
SeqIterator<CvConvexityDefect> it = Seq<CvConvexityDefect>(seq).begin();
|
||||
CvPoint* ptorg = (CvPoint*)points.data;
|
||||
|
||||
|
||||
for( i = 0; i < n; i++, ++it )
|
||||
{
|
||||
CvConvexityDefect& d = *it;
|
||||
@@ -2034,9 +2034,9 @@ void cv::fitLine( InputArray _points, OutputArray _line, int distType,
|
||||
CvMat _cpoints = points.reshape(2 + (int)is3d);
|
||||
float line[6];
|
||||
cvFitLine(&_cpoints, distType, param, reps, aeps, &line[0]);
|
||||
|
||||
|
||||
int out_size = (is2d)?( (is3d)? (points.channels() * points.rows * 2) : 4 ): 6;
|
||||
|
||||
|
||||
_line.create(out_size, 1, CV_32F, -1, true);
|
||||
Mat l = _line.getMat();
|
||||
CV_Assert( l.isContinuous() );
|
||||
|
||||
@@ -55,7 +55,7 @@ calcMinEigenVal( const Mat& _cov, Mat& _dst )
|
||||
#if CV_SSE
|
||||
volatile bool simd = checkHardwareSupport(CV_CPU_SSE);
|
||||
#endif
|
||||
|
||||
|
||||
if( _cov.isContinuous() && _dst.isContinuous() )
|
||||
{
|
||||
size.width *= size.height;
|
||||
@@ -112,7 +112,7 @@ calcHarris( const Mat& _cov, Mat& _dst, double k )
|
||||
#if CV_SSE
|
||||
volatile bool simd = checkHardwareSupport(CV_CPU_SSE);
|
||||
#endif
|
||||
|
||||
|
||||
if( _cov.isContinuous() && _dst.isContinuous() )
|
||||
{
|
||||
size.width *= size.height;
|
||||
@@ -161,7 +161,7 @@ calcHarris( const Mat& _cov, Mat& _dst, double k )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void eigen2x2( const float* cov, float* dst, int n )
|
||||
{
|
||||
for( int j = 0; j < n; j++ )
|
||||
@@ -169,16 +169,16 @@ void eigen2x2( const float* cov, float* dst, int n )
|
||||
double a = cov[j*3];
|
||||
double b = cov[j*3+1];
|
||||
double c = cov[j*3+2];
|
||||
|
||||
|
||||
double u = (a + c)*0.5;
|
||||
double v = std::sqrt((a - c)*(a - c)*0.25 + b*b);
|
||||
double l1 = u + v;
|
||||
double l2 = u - v;
|
||||
|
||||
|
||||
double x = b;
|
||||
double y = l1 - a;
|
||||
double e = fabs(x);
|
||||
|
||||
|
||||
if( e + fabs(y) < 1e-4 )
|
||||
{
|
||||
y = b;
|
||||
@@ -190,16 +190,16 @@ void eigen2x2( const float* cov, float* dst, int n )
|
||||
x *= e, y *= e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double d = 1./std::sqrt(x*x + y*y + DBL_EPSILON);
|
||||
dst[6*j] = (float)l1;
|
||||
dst[6*j + 2] = (float)(x*d);
|
||||
dst[6*j + 3] = (float)(y*d);
|
||||
|
||||
|
||||
x = b;
|
||||
y = l2 - a;
|
||||
e = fabs(x);
|
||||
|
||||
|
||||
if( e + fabs(y) < 1e-4 )
|
||||
{
|
||||
y = b;
|
||||
@@ -211,7 +211,7 @@ void eigen2x2( const float* cov, float* dst, int n )
|
||||
x *= e, y *= e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
d = 1./std::sqrt(x*x + y*y + DBL_EPSILON);
|
||||
dst[6*j + 1] = (float)l2;
|
||||
dst[6*j + 4] = (float)(x*d);
|
||||
@@ -250,7 +250,7 @@ cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size,
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
if (tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType))
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int depth = src.depth();
|
||||
double scale = (double)(1 << ((aperture_size > 0 ? aperture_size : 3) - 1)) * block_size;
|
||||
@@ -331,7 +331,7 @@ void cv::cornerEigenValsAndVecs( InputArray _src, OutputArray _dst, int blockSiz
|
||||
Mat src = _src.getMat();
|
||||
Size dsz = _dst.size();
|
||||
int dtype = _dst.type();
|
||||
|
||||
|
||||
if( dsz.height != src.rows || dsz.width*CV_MAT_CN(dtype) != src.cols*6 || CV_MAT_DEPTH(dtype) != CV_32F )
|
||||
_dst.create( src.size(), CV_32FC(6) );
|
||||
Mat dst = _dst.getMat();
|
||||
@@ -346,7 +346,7 @@ void cv::preCornerDetect( InputArray _src, OutputArray _dst, int ksize, int bord
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_32FC1 );
|
||||
_dst.create( src.size(), CV_32F );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
Sobel( src, Dx, CV_32F, 1, 0, ksize, 1, 0, borderType );
|
||||
Sobel( src, Dy, CV_32F, 0, 1, ksize, 1, 0, borderType );
|
||||
Sobel( src, D2x, CV_32F, 2, 0, ksize, 1, 0, borderType );
|
||||
@@ -368,7 +368,7 @@ void cv::preCornerDetect( InputArray _src, OutputArray _dst, int ksize, int bord
|
||||
const float* d2xdata = (const float*)(D2x.data + i*D2x.step);
|
||||
const float* d2ydata = (const float*)(D2y.data + i*D2y.step);
|
||||
const float* dxydata = (const float*)(Dxy.data + i*Dxy.step);
|
||||
|
||||
|
||||
for( j = 0; j < size.width; j++ )
|
||||
{
|
||||
float dx = dxdata[j];
|
||||
|
||||
@@ -46,7 +46,7 @@ cvFindCornerSubPix( const void* srcarr, CvPoint2D32f* corners,
|
||||
CvTermCriteria criteria )
|
||||
{
|
||||
cv::AutoBuffer<float> buffer;
|
||||
|
||||
|
||||
const int MAX_ITERS = 100;
|
||||
const float drv[] = { -1.f, 0.f, 1.f };
|
||||
float *maskX;
|
||||
@@ -257,7 +257,7 @@ void cv::cornerSubPix( InputArray _image, InputOutputArray _corners,
|
||||
CV_Assert( ncorners >= 0 && corners.depth() == CV_32F );
|
||||
Mat image = _image.getMat();
|
||||
CvMat c_image = image;
|
||||
|
||||
|
||||
cvFindCornerSubPix( &c_image, (CvPoint2D32f*)corners.data, ncorners,
|
||||
winSize, zeroZone, criteria );
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ static void getSobelKernels( OutputArray _kx, OutputArray _ky,
|
||||
_kx.create(ksizeX, 1, ktype, -1, true);
|
||||
_ky.create(ksizeY, 1, ktype, -1, true);
|
||||
Mat kx = _kx.getMat();
|
||||
Mat ky = _ky.getMat();
|
||||
Mat ky = _ky.getMat();
|
||||
|
||||
if( _ksize % 2 == 0 || _ksize > 31 )
|
||||
CV_Error( CV_StsOutOfRange, "The kernel size must be odd and not larger than 31" );
|
||||
@@ -484,7 +484,7 @@ static bool IPPDeriv(const Mat& src, Mat& dst, int ddepth, int dx, int dy, int k
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
|
||||
@@ -505,7 +505,7 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
|
||||
if(dx < 3 && dy < 3 && src.channels() == 1 && borderType == 1)
|
||||
{
|
||||
@@ -544,7 +544,7 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
|
||||
if (tegra::scharr(src, dst, dx, dy, borderType))
|
||||
return;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
|
||||
if(dx < 2 && dy < 2 && src.channels() == 1 && borderType == 1)
|
||||
{
|
||||
@@ -572,24 +572,24 @@ void cv::Scharr( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
|
||||
void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize,
|
||||
double scale, double delta, int borderType )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
Mat src = _src.getMat();
|
||||
if (ddepth < 0)
|
||||
ddepth = src.depth();
|
||||
_dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
if (scale == 1.0 && delta == 0)
|
||||
{
|
||||
if (ksize == 1 && tegra::laplace1(src, dst, borderType))
|
||||
if (ksize == 1 && tegra::laplace1(src, dst, borderType))
|
||||
return;
|
||||
if (ksize == 3 && tegra::laplace3(src, dst, borderType))
|
||||
if (ksize == 3 && tegra::laplace3(src, dst, borderType))
|
||||
return;
|
||||
if (ksize == 5 && tegra::laplace5(src, dst, borderType))
|
||||
if (ksize == 5 && tegra::laplace5(src, dst, borderType))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if( ksize == 1 || ksize == 3 )
|
||||
{
|
||||
float K[2][9] =
|
||||
@@ -616,7 +616,7 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize,
|
||||
|
||||
int dy0 = std::min(std::max((int)(STRIPE_SIZE/(getElemSize(src.type())*src.cols)), 1), src.rows);
|
||||
Ptr<FilterEngine> fx = createSeparableLinearFilter(src.type(),
|
||||
wtype, kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
|
||||
wtype, kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
|
||||
Ptr<FilterEngine> fy = createSeparableLinearFilter(src.type(),
|
||||
wtype, ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ icvInitTopBottom( int* temp, int tempstep, CvSize size, int border )
|
||||
{
|
||||
int* ttop = (int*)(temp + i*tempstep);
|
||||
int* tbottom = (int*)(temp + (size.height + border*2 - i - 1)*tempstep);
|
||||
|
||||
|
||||
for( j = 0; j < size.width + border*2; j++ )
|
||||
{
|
||||
ttop[j] = ICV_INIT_DIST0;
|
||||
@@ -87,7 +87,7 @@ icvDistanceTransform_3x3_C1R( const uchar* src, int srcstep, int* temp,
|
||||
|
||||
for( j = 0; j < BORDER; j++ )
|
||||
tmp[-j-1] = tmp[size.width + j] = ICV_INIT_DIST0;
|
||||
|
||||
|
||||
for( j = 0; j < size.width; j++ )
|
||||
{
|
||||
if( !s[j] )
|
||||
@@ -111,7 +111,7 @@ icvDistanceTransform_3x3_C1R( const uchar* src, int srcstep, int* temp,
|
||||
{
|
||||
float* d = (float*)(dist + i*dststep);
|
||||
int* tmp = (int*)(temp + (i+BORDER)*step) + BORDER;
|
||||
|
||||
|
||||
for( j = size.width - 1; j >= 0; j-- )
|
||||
{
|
||||
int t0 = tmp[j];
|
||||
@@ -160,7 +160,7 @@ icvDistanceTransform_5x5_C1R( const uchar* src, int srcstep, int* temp,
|
||||
|
||||
for( j = 0; j < BORDER; j++ )
|
||||
tmp[-j-1] = tmp[size.width + j] = ICV_INIT_DIST0;
|
||||
|
||||
|
||||
for( j = 0; j < size.width; j++ )
|
||||
{
|
||||
if( !s[j] )
|
||||
@@ -192,7 +192,7 @@ icvDistanceTransform_5x5_C1R( const uchar* src, int srcstep, int* temp,
|
||||
{
|
||||
float* d = (float*)(dist + i*dststep);
|
||||
int* tmp = (int*)(temp + (i+BORDER)*step) + BORDER;
|
||||
|
||||
|
||||
for( j = size.width - 1; j >= 0; j-- )
|
||||
{
|
||||
int t0 = tmp[j];
|
||||
@@ -230,7 +230,7 @@ icvDistanceTransformEx_5x5_C1R( const uchar* src, int srcstep, int* temp,
|
||||
CvSize size, const float* metrics )
|
||||
{
|
||||
const int BORDER = 2;
|
||||
|
||||
|
||||
int i, j;
|
||||
const int HV_DIST = CV_FLT_TO_FIX( metrics[0], ICV_DIST_SHIFT );
|
||||
const int DIAG_DIST = CV_FLT_TO_FIX( metrics[1], ICV_DIST_SHIFT );
|
||||
@@ -253,7 +253,7 @@ icvDistanceTransformEx_5x5_C1R( const uchar* src, int srcstep, int* temp,
|
||||
|
||||
for( j = 0; j < BORDER; j++ )
|
||||
tmp[-j-1] = tmp[size.width + j] = ICV_INIT_DIST0;
|
||||
|
||||
|
||||
for( j = 0; j < size.width; j++ )
|
||||
{
|
||||
if( !s[j] )
|
||||
@@ -327,7 +327,7 @@ icvDistanceTransformEx_5x5_C1R( const uchar* src, int srcstep, int* temp,
|
||||
float* d = (float*)(dist + i*dststep);
|
||||
int* tmp = (int*)(temp + (i+BORDER)*step) + BORDER;
|
||||
int* lls = (int*)(labels + i*lstep);
|
||||
|
||||
|
||||
for( j = size.width - 1; j >= 0; j-- )
|
||||
{
|
||||
int t0 = tmp[j];
|
||||
@@ -452,7 +452,7 @@ struct DTColumnInvoker
|
||||
sat_tab = _sat_tab + src->rows*2 + 1;
|
||||
sqr_tab = _sqr_tab;
|
||||
}
|
||||
|
||||
|
||||
void operator()( const BlockedRange& range ) const
|
||||
{
|
||||
int i, i1 = range.begin(), i2 = range.end();
|
||||
@@ -460,19 +460,19 @@ struct DTColumnInvoker
|
||||
size_t sstep = src->step, dstep = dst->step/sizeof(float);
|
||||
AutoBuffer<int> _d(m);
|
||||
int* d = _d;
|
||||
|
||||
|
||||
for( i = i1; i < i2; i++ )
|
||||
{
|
||||
const uchar* sptr = src->data.ptr + i + (m-1)*sstep;
|
||||
float* dptr = dst->data.fl + i;
|
||||
int j, dist = m-1;
|
||||
|
||||
|
||||
for( j = m-1; j >= 0; j--, sptr -= sstep )
|
||||
{
|
||||
dist = (dist + 1) & (sptr[0] == 0 ? 0 : -1);
|
||||
d[j] = dist;
|
||||
}
|
||||
|
||||
|
||||
dist = m-1;
|
||||
for( j = 0; j < m; j++, dptr += dstep )
|
||||
{
|
||||
@@ -482,14 +482,14 @@ struct DTColumnInvoker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const CvMat* src;
|
||||
CvMat* dst;
|
||||
const int* sat_tab;
|
||||
const float* sqr_tab;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct DTRowInvoker
|
||||
{
|
||||
DTRowInvoker( CvMat* _dst, const float* _sqr_tab, const float* _inv_tab )
|
||||
@@ -498,7 +498,7 @@ struct DTRowInvoker
|
||||
sqr_tab = _sqr_tab;
|
||||
inv_tab = _inv_tab;
|
||||
}
|
||||
|
||||
|
||||
void operator()( const BlockedRange& range ) const
|
||||
{
|
||||
const float inf = 1e15f;
|
||||
@@ -508,22 +508,22 @@ struct DTRowInvoker
|
||||
float* f = (float*)(uchar*)_buf;
|
||||
float* z = f + n;
|
||||
int* v = alignPtr((int*)(z + n + 1), sizeof(int));
|
||||
|
||||
|
||||
for( i = i1; i < i2; i++ )
|
||||
{
|
||||
float* d = (float*)(dst->data.ptr + i*dst->step);
|
||||
int p, q, k;
|
||||
|
||||
|
||||
v[0] = 0;
|
||||
z[0] = -inf;
|
||||
z[1] = inf;
|
||||
f[0] = d[0];
|
||||
|
||||
|
||||
for( q = 1, k = 0; q < n; q++ )
|
||||
{
|
||||
float fq = d[q];
|
||||
f[q] = fq;
|
||||
|
||||
|
||||
for(;;k--)
|
||||
{
|
||||
p = v[k];
|
||||
@@ -538,7 +538,7 @@ struct DTRowInvoker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for( q = 0, k = 0; q < n; q++ )
|
||||
{
|
||||
while( z[k+1] < q )
|
||||
@@ -548,7 +548,7 @@ struct DTRowInvoker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CvMat* dst;
|
||||
const float* sqr_tab;
|
||||
const float* inv_tab;
|
||||
@@ -560,7 +560,7 @@ static void
|
||||
icvTrueDistTrans( const CvMat* src, CvMat* dst )
|
||||
{
|
||||
const float inf = 1e15f;
|
||||
|
||||
|
||||
if( !CV_ARE_SIZES_EQ( src, dst ))
|
||||
CV_Error( CV_StsUnmatchedSizes, "" );
|
||||
|
||||
@@ -586,11 +586,11 @@ icvTrueDistTrans( const CvMat* src, CvMat* dst )
|
||||
for( ; i <= m*3; i++ )
|
||||
sat_tab[i] = i - shift;
|
||||
|
||||
cv::parallel_for(cv::BlockedRange(0, n), cv::DTColumnInvoker(src, dst, sat_tab, sqr_tab));
|
||||
cv::parallel_for(cv::BlockedRange(0, n), cv::DTColumnInvoker(src, dst, sat_tab, sqr_tab));
|
||||
|
||||
// stage 2: compute modified distance transform for each row
|
||||
float* inv_tab = sqr_tab + n;
|
||||
|
||||
|
||||
inv_tab[0] = sqr_tab[0] = 0.f;
|
||||
for( i = 1; i < n; i++ )
|
||||
{
|
||||
@@ -634,7 +634,7 @@ icvDistanceATS_L1_8u( const CvMat* src, CvMat* dst )
|
||||
int a;
|
||||
uchar lut[256];
|
||||
int x, y;
|
||||
|
||||
|
||||
const uchar *sbase = src->data.ptr;
|
||||
uchar *dbase = dst->data.ptr;
|
||||
int srcstep = src->step;
|
||||
@@ -738,7 +738,7 @@ cvDistTransform( const void* srcarr, void* dstarr,
|
||||
icvTrueDistTrans( src, dst );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( labels )
|
||||
{
|
||||
labels = cvGetMat( labels, &lstub );
|
||||
@@ -789,7 +789,7 @@ cvDistTransform( const void* srcarr, void* dstarr,
|
||||
else
|
||||
{
|
||||
cvZero( labels );
|
||||
|
||||
|
||||
if( labelType == CV_DIST_LABEL_CCOMP )
|
||||
{
|
||||
CvSeq *contours = 0;
|
||||
@@ -799,7 +799,7 @@ cvDistTransform( const void* srcarr, void* dstarr,
|
||||
cvCmpS( src_copy, 0, src_copy, CV_CMP_EQ );
|
||||
cvFindContours( src_copy, st, &contours, sizeof(CvContour),
|
||||
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(-border, -border));
|
||||
|
||||
|
||||
for( int label = 1; contours != 0; contours = contours->h_next, label++ )
|
||||
{
|
||||
CvScalar area_color = cvScalarAll(label);
|
||||
@@ -813,7 +813,7 @@ cvDistTransform( const void* srcarr, void* dstarr,
|
||||
{
|
||||
const uchar* srcptr = src->data.ptr + src->step*i;
|
||||
int* labelptr = (int*)(labels->data.ptr + labels->step*i);
|
||||
|
||||
|
||||
for( int j = 0; j < src->cols; j++ )
|
||||
if( srcptr[j] == 0 )
|
||||
labelptr[j] = k++;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
An implementation of the Earth Movers Distance.
|
||||
Based of the solution for the Transportation problem as described in
|
||||
"Introduction to Mathematical Programming" by F. S. Hillier and
|
||||
"Introduction to Mathematical Programming" by F. S. Hillier and
|
||||
G. J. Lieberman, McGraw-Hill, 1990.
|
||||
|
||||
Copyright (C) 1998 Yossi Rubner
|
||||
@@ -347,7 +347,7 @@ static int icvInitEMD( const float* signature1, int size1,
|
||||
sizeof( CvNode2D * ) + /* cols_x & rows_x */
|
||||
sizeof( CvNode1D ) + /* u & v */
|
||||
sizeof( float ) + /* s & d */
|
||||
sizeof( int ) + sizeof(CvNode2D*)) + /* idx1 & idx2 */
|
||||
sizeof( int ) + sizeof(CvNode2D*)) + /* idx1 & idx2 */
|
||||
(size1+1) * (sizeof( float * ) + sizeof( char * ) + /* rows pointers for */
|
||||
sizeof( float * )) + 256; /* cost, is_x and delta */
|
||||
|
||||
@@ -384,7 +384,7 @@ static int icvInitEMD( const float* signature1, int size1,
|
||||
s_sum += weight;
|
||||
state->s[ssize] = weight;
|
||||
state->idx1[ssize++] = i;
|
||||
|
||||
|
||||
}
|
||||
else if( weight < 0 )
|
||||
CV_Error(CV_StsOutOfRange, "");
|
||||
@@ -416,7 +416,7 @@ static int icvInitEMD( const float* signature1, int size1,
|
||||
{
|
||||
state->s[ssize] = -diff;
|
||||
state->idx1[ssize++] = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state->d[dsize] = diff;
|
||||
@@ -525,7 +525,7 @@ static int icvInitEMD( const float* signature1, int size1,
|
||||
}
|
||||
|
||||
state->max_cost = max_cost;
|
||||
|
||||
|
||||
memset( buffer, 0, buffer_end - buffer );
|
||||
|
||||
state->rows_x = (CvNode2D **) buffer;
|
||||
@@ -1144,7 +1144,7 @@ float cv::EMD( InputArray _signature1, InputArray _signature2,
|
||||
{
|
||||
Mat signature1 = _signature1.getMat(), signature2 = _signature2.getMat();
|
||||
Mat cost = _cost.getMat(), flow;
|
||||
|
||||
|
||||
CvMat _csignature1 = signature1;
|
||||
CvMat _csignature2 = signature2;
|
||||
CvMat _ccost = cost, _cflow;
|
||||
@@ -1154,7 +1154,7 @@ float cv::EMD( InputArray _signature1, InputArray _signature2,
|
||||
flow = _flow.getMat();
|
||||
_cflow = flow;
|
||||
}
|
||||
|
||||
|
||||
return cvCalcEMD2( &_csignature1, &_csignature2, distType, 0, cost.empty() ? 0 : &_ccost,
|
||||
_flow.needed() ? &_cflow : 0, lowerBound, 0 );
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ template<typename T> struct greaterThanPtr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray _mask, int blockSize,
|
||||
bool useHarrisDetector, double harrisK )
|
||||
{
|
||||
Mat image = _image.getMat(), mask = _mask.getMat();
|
||||
|
||||
|
||||
CV_Assert( qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0 );
|
||||
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == image.size()) );
|
||||
|
||||
@@ -116,7 +116,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
bool good = true;
|
||||
bool good = true;
|
||||
|
||||
int x_cell = x / cell_size;
|
||||
int y_cell = y / cell_size;
|
||||
@@ -135,7 +135,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
for( int yy = y1; yy <= y2; yy++ )
|
||||
{
|
||||
for( int xx = x1; xx <= x2; xx++ )
|
||||
{
|
||||
{
|
||||
vector <Point2f> &m = grid[yy*grid_width + xx];
|
||||
|
||||
if( m.size() )
|
||||
@@ -151,7 +151,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
goto break_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Mat(corners).convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
|
||||
|
||||
/*
|
||||
|
||||
@@ -56,34 +56,34 @@ cv::Mat cv::getGaborKernel( Size ksize, double sigma, double theta,
|
||||
int nstds = 3;
|
||||
int xmin, xmax, ymin, ymax;
|
||||
double c = cos(theta), s = sin(theta);
|
||||
|
||||
|
||||
if( ksize.width > 0 )
|
||||
xmax = ksize.width/2;
|
||||
else
|
||||
xmax = cvRound(std::max(fabs(nstds*sigma_x*c), fabs(nstds*sigma_y*s)));
|
||||
|
||||
|
||||
if( ksize.height > 0 )
|
||||
ymax = ksize.height/2;
|
||||
else
|
||||
ymax = cvRound(std::max(fabs(nstds*sigma_x*s), fabs(nstds*sigma_y*c)));
|
||||
|
||||
|
||||
xmin = -xmax;
|
||||
ymin = -ymax;
|
||||
|
||||
|
||||
CV_Assert( ktype == CV_32F || ktype == CV_64F );
|
||||
|
||||
|
||||
Mat kernel(ymax - ymin + 1, xmax - xmin + 1, ktype);
|
||||
double scale = 1;
|
||||
double ex = -0.5/(sigma_x*sigma_x);
|
||||
double ey = -0.5/(sigma_y*sigma_y);
|
||||
double cscale = CV_PI*2/lambd;
|
||||
|
||||
|
||||
for( int y = ymin; y <= ymax; y++ )
|
||||
for( int x = xmin; x <= xmax; x++ )
|
||||
{
|
||||
double xr = x*c + y*s;
|
||||
double yr = -x*s + y*c;
|
||||
|
||||
|
||||
double v = scale*exp(ex*xr*xr + ey*yr*yr)*cos(cscale*xr + psi);
|
||||
if( ktype == CV_32F )
|
||||
kernel.at<float>(ymax - y, xmax - x) = (float)v;
|
||||
|
||||
@@ -131,7 +131,7 @@ CV_IMPL double
|
||||
cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
|
||||
{
|
||||
double result = 0;
|
||||
|
||||
|
||||
CvSeqBlock block;
|
||||
CvContour header;
|
||||
CvSeq* contour = (CvSeq*)_contour;
|
||||
@@ -256,7 +256,7 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
double dx, dy, dx1, dy1, dx2, dy2, dist_num, dist_denom = 1;
|
||||
|
||||
|
||||
v0 = v;
|
||||
if( is_float )
|
||||
{
|
||||
@@ -267,11 +267,11 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
|
||||
CV_READ_SEQ_ELEM( iv, reader );
|
||||
v = cvPointTo32f( iv );
|
||||
}
|
||||
|
||||
|
||||
dx = v.x - v0.x; dy = v.y - v0.y;
|
||||
dx1 = pt.x - v0.x; dy1 = pt.y - v0.y;
|
||||
dx2 = pt.x - v.x; dy2 = pt.y - v.y;
|
||||
|
||||
|
||||
if( dx1*dx + dy1*dy <= 0 )
|
||||
dist_num = dx1*dx1 + dy1*dy1;
|
||||
else if( dx2*dx + dy2*dy >= 0 )
|
||||
@@ -316,7 +316,7 @@ cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
|
||||
This code is described in "Computational Geometry in C" (Second Edition),
|
||||
Chapter 7. It is not written to be comprehensible without the
|
||||
explanation in that book.
|
||||
|
||||
|
||||
Written by Joseph O'Rourke.
|
||||
Last modified: December 1997
|
||||
Questions to orourke@cs.smith.edu.
|
||||
@@ -345,7 +345,7 @@ static int areaSign( Point2f a, Point2f b, Point2f c )
|
||||
static bool between( Point2f a, Point2f b, Point2f c )
|
||||
{
|
||||
Point2f ba, ca;
|
||||
|
||||
|
||||
// If ab not vertical, check betweenness on x; else on y.
|
||||
if ( a.x != b.x )
|
||||
return ((a.x <= c.x) && (c.x <= b.x)) ||
|
||||
@@ -394,38 +394,38 @@ static char segSegInt( Point2f a, Point2f b, Point2f c, Point2f d, Point2f& p, P
|
||||
double s, t; // The two parameters of the parametric eqns.
|
||||
double num, denom; // Numerator and denoninator of equations.
|
||||
char code = '?'; // Return char characterizing intersection.
|
||||
|
||||
|
||||
denom = a.x * (double)( d.y - c.y ) +
|
||||
b.x * (double)( c.y - d.y ) +
|
||||
d.x * (double)( b.y - a.y ) +
|
||||
c.x * (double)( a.y - b.y );
|
||||
|
||||
|
||||
// If denom is zero, then segments are parallel: handle separately.
|
||||
if (denom == 0.0)
|
||||
return parallelInt(a, b, c, d, p, q);
|
||||
|
||||
|
||||
num = a.x * (double)( d.y - c.y ) +
|
||||
c.x * (double)( a.y - d.y ) +
|
||||
d.x * (double)( c.y - a.y );
|
||||
if ( (num == 0.0) || (num == denom) ) code = 'v';
|
||||
s = num / denom;
|
||||
|
||||
|
||||
num = -( a.x * (double)( c.y - b.y ) +
|
||||
b.x * (double)( a.y - c.y ) +
|
||||
c.x * (double)( b.y - a.y ) );
|
||||
if ( (num == 0.0) || (num == denom) ) code = 'v';
|
||||
t = num / denom;
|
||||
|
||||
|
||||
if ( (0.0 < s) && (s < 1.0) &&
|
||||
(0.0 < t) && (t < 1.0) )
|
||||
code = '1';
|
||||
else if ( (0.0 > s) || (s > 1.0) ||
|
||||
(0.0 > t) || (t > 1.0) )
|
||||
code = '0';
|
||||
|
||||
|
||||
p.x = (float)(a.x + s*(b.x - a.x));
|
||||
p.y = (float)(a.y + s*(b.y - a.y));
|
||||
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ static int advance( int a, int *aa, int n, bool inside, Point2f v, Point2f*& res
|
||||
*result++ = v;
|
||||
(*aa)++;
|
||||
return (a+1) % n;
|
||||
}
|
||||
}
|
||||
|
||||
static void addSharedSeg( Point2f p, Point2f q, Point2f*& result )
|
||||
{
|
||||
@@ -469,19 +469,19 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
|
||||
bool FirstPoint=true;// Is this the first point? (used to initialize).
|
||||
Point2f p0; // The first point.
|
||||
*result++ = Point2f(FLT_MAX, FLT_MAX);
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
// Computations of key variables.
|
||||
int a1 = (a + n - 1) % n; // a-1, b-1 (resp.)
|
||||
int b1 = (b + m - 1) % m;
|
||||
|
||||
|
||||
Point2f A = P[a] - P[a1], B = Q[b] - Q[b1]; // directed edges on P and Q (resp.)
|
||||
|
||||
|
||||
int cross = areaSign( Origin, A, B ); // sign of z-component of A x B
|
||||
int aHB = areaSign( Q[b1], Q[b], P[a] ); // a in H(b).
|
||||
int bHA = areaSign( P[a1], P[a], Q[b] ); // b in H(A);
|
||||
|
||||
|
||||
// If A & B intersect, update inflag.
|
||||
Point2f p, q;
|
||||
int code = segSegInt( P[a1], P[a], Q[b1], Q[b], p, q );
|
||||
@@ -496,20 +496,20 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
|
||||
}
|
||||
inflag = inOut( p, inflag, aHB, bHA, result );
|
||||
}
|
||||
|
||||
|
||||
//-----Advance rules-----
|
||||
|
||||
|
||||
// Special case: A & B overlap and oppositely oriented.
|
||||
if( code == 'e' && A.ddot(B) < 0 )
|
||||
{
|
||||
addSharedSeg( p, q, result );
|
||||
return (int)(result - result0);
|
||||
}
|
||||
|
||||
|
||||
// Special case: A & B parallel and separated.
|
||||
if( cross == 0 && aHB < 0 && bHA < 0 )
|
||||
return (int)(result - result0);
|
||||
|
||||
|
||||
// Special case: A & B collinear.
|
||||
else if ( cross == 0 && aHB == 0 && bHA == 0 ) {
|
||||
// Advance but do not output point.
|
||||
@@ -518,7 +518,7 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
|
||||
else
|
||||
a = advance( a, &aa, n, inflag == Pin, P[a], result );
|
||||
}
|
||||
|
||||
|
||||
// Generic cases.
|
||||
else if( cross >= 0 )
|
||||
{
|
||||
@@ -537,14 +537,14 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
|
||||
// Quit when both adv. indices have cycled, or one has cycled twice.
|
||||
}
|
||||
while ( ((aa < n) || (ba < m)) && (aa < 2*n) && (ba < 2*m) );
|
||||
|
||||
|
||||
// Deal with special cases: not implemented.
|
||||
if( inflag == Unknown )
|
||||
{
|
||||
// The boundaries of P and Q do not cross.
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
int i, nr = (int)(result - result0);
|
||||
double area = 0;
|
||||
Point2f prev = result0[nr-1];
|
||||
@@ -554,44 +554,44 @@ static int intersectConvexConvex_( const Point2f* P, int n, const Point2f* Q, in
|
||||
area += (double)prev.x*result0[i].y - (double)prev.y*result0[i].x;
|
||||
prev = result0[i];
|
||||
}
|
||||
|
||||
|
||||
*_area = (float)(area*0.5);
|
||||
|
||||
|
||||
if( result0[nr-2] == result0[0] && nr > 1 )
|
||||
nr--;
|
||||
return nr-1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p12, bool handleNested )
|
||||
{
|
||||
Mat p1 = _p1.getMat(), p2 = _p2.getMat();
|
||||
CV_Assert( p1.depth() == CV_32S || p1.depth() == CV_32F );
|
||||
CV_Assert( p2.depth() == CV_32S || p2.depth() == CV_32F );
|
||||
|
||||
|
||||
int n = p1.checkVector(2, p1.depth(), true);
|
||||
int m = p2.checkVector(2, p2.depth(), true);
|
||||
|
||||
|
||||
CV_Assert( n >= 0 && m >= 0 );
|
||||
|
||||
|
||||
if( n < 2 || m < 2 )
|
||||
{
|
||||
_p12.release();
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
|
||||
AutoBuffer<Point2f> _result(n*2 + m*2 + 1);
|
||||
Point2f *fp1 = _result, *fp2 = fp1 + n;
|
||||
Point2f* result = fp2 + m;
|
||||
int orientation = 0;
|
||||
|
||||
|
||||
for( int k = 1; k <= 2; k++ )
|
||||
{
|
||||
Mat& p = k == 1 ? p1 : p2;
|
||||
int len = k == 1 ? n : m;
|
||||
Point2f* dst = k == 1 ? fp1 : fp2;
|
||||
|
||||
|
||||
Mat temp(p.size(), CV_MAKETYPE(CV_32F, p.channels()), dst);
|
||||
p.convertTo(temp, CV_32F);
|
||||
CV_Assert( temp.ptr<Point2f>() == dst );
|
||||
@@ -610,7 +610,7 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float area = 0.f;
|
||||
int nr = intersectConvexConvex_(fp1, n, fp2, m, result, &area);
|
||||
if( nr == 0 )
|
||||
@@ -620,7 +620,7 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
|
||||
_p12.release();
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
|
||||
if( pointPolygonTest(_InputArray(fp1, n), fp2[0], false) >= 0 )
|
||||
{
|
||||
result = fp2;
|
||||
@@ -638,7 +638,7 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
|
||||
}
|
||||
area = (float)contourArea(_InputArray(result, nr), false);
|
||||
}
|
||||
|
||||
|
||||
if( _p12.needed() )
|
||||
{
|
||||
Mat temp(nr, 1, CV_32FC2, result);
|
||||
@@ -662,7 +662,7 @@ static void testConvConv()
|
||||
100, 100,
|
||||
0, 100,
|
||||
};
|
||||
|
||||
|
||||
static const int Q1[] =
|
||||
{
|
||||
100, 80,
|
||||
@@ -670,7 +670,7 @@ static void testConvConv()
|
||||
50, 50,
|
||||
100, 50
|
||||
};
|
||||
|
||||
|
||||
static const int P2[] =
|
||||
{
|
||||
0, 0,
|
||||
@@ -679,7 +679,7 @@ static void testConvConv()
|
||||
100, 200,
|
||||
0, 100
|
||||
};
|
||||
|
||||
|
||||
static const int Q2[] =
|
||||
{
|
||||
100, 100,
|
||||
@@ -687,7 +687,7 @@ static void testConvConv()
|
||||
300, 200,
|
||||
100, 200
|
||||
};
|
||||
|
||||
|
||||
static const int P3[] =
|
||||
{
|
||||
0, 0,
|
||||
@@ -695,7 +695,7 @@ static void testConvConv()
|
||||
100, 100,
|
||||
0, 100
|
||||
};
|
||||
|
||||
|
||||
static const int Q3[] =
|
||||
{
|
||||
50, 50,
|
||||
@@ -703,7 +703,7 @@ static void testConvConv()
|
||||
150, 150,
|
||||
50, 150
|
||||
};
|
||||
|
||||
|
||||
static const int P4[] =
|
||||
{
|
||||
0, 160,
|
||||
@@ -717,7 +717,7 @@ static void testConvConv()
|
||||
70, 320,
|
||||
30, 290
|
||||
};
|
||||
|
||||
|
||||
static const int Q4[] =
|
||||
{
|
||||
160, -30,
|
||||
@@ -726,12 +726,12 @@ static void testConvConv()
|
||||
0, 220,
|
||||
30, 100
|
||||
};
|
||||
|
||||
|
||||
static const void* PQs[] =
|
||||
{
|
||||
P1, Q1, P2, Q2, P3, Q3, P4, Q4
|
||||
};
|
||||
|
||||
|
||||
static const int lens[] =
|
||||
{
|
||||
CV_DIM(P1), CV_DIM(Q1),
|
||||
@@ -739,36 +739,36 @@ static void testConvConv()
|
||||
CV_DIM(P3), CV_DIM(Q3),
|
||||
CV_DIM(P4), CV_DIM(Q4)
|
||||
};
|
||||
|
||||
|
||||
Mat img(800, 800, CV_8UC3);
|
||||
|
||||
|
||||
for( int i = 0; i < CV_DIM(PQs)/2; i++ )
|
||||
{
|
||||
Mat Pm = Mat(lens[i*2]/2, 1, CV_32SC2, (void*)PQs[i*2]) + Scalar(100, 100);
|
||||
Mat Qm = Mat(lens[i*2+1]/2, 1, CV_32SC2, (void*)PQs[i*2+1]) + Scalar(100, 100);
|
||||
Point* P = Pm.ptr<Point>();
|
||||
Point* Q = Qm.ptr<Point>();
|
||||
|
||||
|
||||
flip(Pm, Pm, 0);
|
||||
flip(Qm, Qm, 0);
|
||||
|
||||
|
||||
Mat Rm;
|
||||
intersectConvexConvex(Pm, Qm, Rm);
|
||||
std::cout << Rm << std::endl << std::endl;
|
||||
|
||||
|
||||
img = Scalar::all(0);
|
||||
|
||||
|
||||
polylines(img, Pm, true, Scalar(0,255,0), 1, CV_AA, 0);
|
||||
polylines(img, Qm, true, Scalar(0,0,255), 1, CV_AA, 0);
|
||||
Mat temp;
|
||||
Rm.convertTo(temp, CV_32S, 256);
|
||||
polylines(img, temp, true, Scalar(128, 255, 255), 3, CV_AA, 8);
|
||||
|
||||
|
||||
namedWindow("test", 1);
|
||||
imshow("test", img);
|
||||
waitKey();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -119,7 +119,7 @@ double GMM::operator()( int ci, const Vec3d color ) const
|
||||
double res = 0;
|
||||
if( coefs[ci] > 0 )
|
||||
{
|
||||
CV_Assert( covDeterms[ci] > std::numeric_limits<double>::epsilon() );
|
||||
CV_Assert( covDeterms[ci] > std::numeric_limits<double>::epsilon() );
|
||||
Vec3d diff = color;
|
||||
double* m = mean + 3*ci;
|
||||
diff[0] -= m[0]; diff[1] -= m[1]; diff[2] -= m[2];
|
||||
@@ -138,7 +138,7 @@ int GMM::whichComponent( const Vec3d color ) const
|
||||
|
||||
for( int ci = 0; ci < componentsCount; ci++ )
|
||||
{
|
||||
double p = (*this)( ci, color );
|
||||
double p = (*this)( ci, color );
|
||||
if( p > max )
|
||||
{
|
||||
k = ci;
|
||||
@@ -406,7 +406,7 @@ static void assignGMMsComponents( const Mat& img, const Mat& mask, const GMM& bg
|
||||
for( p.x = 0; p.x < img.cols; p.x++ )
|
||||
{
|
||||
Vec3d color = img.at<Vec3b>(p);
|
||||
compIdxs.at<int>(p) = mask.at<uchar>(p) == GC_BGD || mask.at<uchar>(p) == GC_PR_BGD ?
|
||||
compIdxs.at<int>(p) = mask.at<uchar>(p) == GC_BGD || mask.at<uchar>(p) == GC_PR_BGD ?
|
||||
bgdGMM.whichComponent(color) : fgdGMM.whichComponent(color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,12 +251,12 @@ public:
|
||||
ify(_ify)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
Size ssize = src.size(), dsize = dst.size();
|
||||
int y, x, pix_size = (int)src.elemSize();
|
||||
|
||||
|
||||
for( y = range.start; y < range.end; y++ )
|
||||
{
|
||||
uchar* D = dst.data + dst.step*y;
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
const Mat src;
|
||||
Mat dst;
|
||||
@@ -354,7 +354,7 @@ resizeNN( const Mat& src, Mat& dst, double fx, double fy )
|
||||
int sx = cvFloor(x*ifx);
|
||||
x_ofs[x] = std::min(sx, ssize.width-1)*pix_size;
|
||||
}
|
||||
|
||||
|
||||
Range range(0, dsize.height);
|
||||
resizeNNInvoker invoker(src, dst, x_ofs, pix_size4, ify);
|
||||
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
|
||||
@@ -1132,7 +1132,7 @@ public:
|
||||
typedef typename HResize::value_type T;
|
||||
typedef typename HResize::buf_type WT;
|
||||
typedef typename HResize::alpha_type AT;
|
||||
|
||||
|
||||
resizeGeneric_Invoker(const Mat& _src, Mat &_dst, const int *_xofs, const int *_yofs,
|
||||
const AT* _alpha, const AT* __beta, const Size& _ssize, const Size &_dsize,
|
||||
int _ksize, int _xmin, int _xmax) :
|
||||
@@ -1141,13 +1141,13 @@ public:
|
||||
ksize(_ksize), xmin(_xmin), xmax(_xmax)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
int dy, cn = src.channels();
|
||||
HResize hresize;
|
||||
VResize vresize;
|
||||
|
||||
|
||||
int bufstep = (int)alignSize(dsize.width, 16);
|
||||
AutoBuffer<WT> _buffer(bufstep*ksize);
|
||||
const T* srows[MAX_ESIZE]={0};
|
||||
@@ -1159,9 +1159,9 @@ public:
|
||||
prev_sy[k] = -1;
|
||||
rows[k] = (WT*)_buffer + bufstep*k;
|
||||
}
|
||||
|
||||
|
||||
const AT* beta = _beta + ksize * range.start;
|
||||
|
||||
|
||||
for( dy = range.start; dy < range.end; dy++, beta += ksize )
|
||||
{
|
||||
int sy0 = yofs[dy], k0=ksize, k1=0, ksize2 = ksize/2;
|
||||
@@ -1190,7 +1190,7 @@ public:
|
||||
vresize( (const WT**)rows, (T*)(dst.data + dst.step*dy), beta, dsize.width );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Mat src;
|
||||
Mat dst;
|
||||
@@ -1218,7 +1218,7 @@ static void resizeGeneric_( const Mat& src, Mat& dst,
|
||||
xmin *= cn;
|
||||
xmax *= cn;
|
||||
// image resize is a separable operation. In case of not too strong
|
||||
|
||||
|
||||
Range range(0, dsize.height);
|
||||
resizeGeneric_Invoker<HResize, VResize> invoker(src, dst, xofs, yofs, (const AT*)_alpha, beta,
|
||||
ssize, dsize, ksize, xmin, xmax);
|
||||
@@ -1238,18 +1238,18 @@ struct ResizeAreaFastVec
|
||||
{
|
||||
ResizeAreaFastVec(int _scale_x, int _scale_y, int _cn, int _step/*, const int* _ofs*/) :
|
||||
scale_x(_scale_x), scale_y(_scale_y), cn(_cn), step(_step)/*, ofs(_ofs)*/
|
||||
{
|
||||
fast_mode = scale_x == 2 && scale_y == 2 && (cn == 1 || cn == 3 || cn == 4);
|
||||
{
|
||||
fast_mode = scale_x == 2 && scale_y == 2 && (cn == 1 || cn == 3 || cn == 4);
|
||||
}
|
||||
|
||||
|
||||
int operator() (const T* S, T* D, int w) const
|
||||
{
|
||||
if( !fast_mode )
|
||||
return 0;
|
||||
|
||||
|
||||
const T* nextS = (const T*)((const uchar*)S + step);
|
||||
int dx = 0;
|
||||
|
||||
|
||||
if (cn == 1)
|
||||
for( ; dx < w; ++dx )
|
||||
{
|
||||
@@ -1276,10 +1276,10 @@ struct ResizeAreaFastVec
|
||||
D[dx+3] = (T)((S[index+3] + S[index+7] + nextS[index+3] + nextS[index+7] + 2) >> 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return dx;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
int scale_x, scale_y;
|
||||
int cn;
|
||||
@@ -1298,7 +1298,7 @@ public:
|
||||
scale_y(_scale_y), ofs(_ofs), xofs(_xofs)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
Size ssize = src.size(), dsize = dst.size();
|
||||
@@ -1309,15 +1309,15 @@ public:
|
||||
dsize.width *= cn;
|
||||
ssize.width *= cn;
|
||||
int dy, dx, k = 0;
|
||||
|
||||
|
||||
VecOp vop(scale_x, scale_y, src.channels(), (int)src.step/*, area_ofs*/);
|
||||
|
||||
|
||||
for( dy = range.start; dy < range.end; dy++ )
|
||||
{
|
||||
T* D = (T*)(dst.data + dst.step*dy);
|
||||
int sy0 = dy*scale_y;
|
||||
int w = sy0 + scale_y <= ssize.height ? dwidth1 : 0;
|
||||
|
||||
|
||||
if( sy0 >= ssize.height )
|
||||
{
|
||||
for( dx = 0; dx < dsize.width; dx++ )
|
||||
@@ -1366,7 +1366,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Mat src;
|
||||
Mat dst;
|
||||
@@ -1379,7 +1379,7 @@ static void resizeAreaFast_( const Mat& src, Mat& dst, const int* ofs, const int
|
||||
int scale_x, int scale_y )
|
||||
{
|
||||
Range range(0, dst.rows);
|
||||
resizeAreaFast_Invoker<T, WT, VecOp> invoker(src, dst, scale_x,
|
||||
resizeAreaFast_Invoker<T, WT, VecOp> invoker(src, dst, scale_x,
|
||||
scale_y, ofs, xofs);
|
||||
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
|
||||
}
|
||||
@@ -1395,16 +1395,16 @@ class resizeArea_Invoker :
|
||||
public ParallelLoopBody
|
||||
{
|
||||
public:
|
||||
resizeArea_Invoker(const Mat& _src, Mat& _dst, const DecimateAlpha* _xofs,
|
||||
int _xofs_count, double _scale_y_, const int* _cur_dy_ofs,
|
||||
resizeArea_Invoker(const Mat& _src, Mat& _dst, const DecimateAlpha* _xofs,
|
||||
int _xofs_count, double _scale_y_, const int* _cur_dy_ofs,
|
||||
const std::vector<std::pair<int, int> >& _bands) :
|
||||
ParallelLoopBody(), src(_src), dst(_dst), xofs(_xofs),
|
||||
ParallelLoopBody(), src(_src), dst(_dst), xofs(_xofs),
|
||||
xofs_count(_xofs_count), scale_y_(_scale_y_),
|
||||
cur_dy_ofs(_cur_dy_ofs), bands(_bands)
|
||||
{
|
||||
}
|
||||
|
||||
void resize_single_band(const Range& range) const
|
||||
|
||||
void resize_single_band(const Range& range) const
|
||||
{
|
||||
Size ssize = src.size(), dsize = dst.size();
|
||||
int cn = src.channels();
|
||||
@@ -1413,11 +1413,11 @@ public:
|
||||
WT *buf = _buffer, *sum = buf + dsize.width;
|
||||
int k = 0, sy = 0, dx = 0, cur_dy = 0;
|
||||
WT scale_y = (WT)scale_y_;
|
||||
|
||||
|
||||
CV_Assert( cn <= 4 );
|
||||
for( dx = 0; dx < dsize.width; dx++ )
|
||||
buf[dx] = sum[dx] = 0;
|
||||
|
||||
|
||||
cur_dy = cur_dy_ofs[range.start];
|
||||
for (sy = range.start; sy < range.end; sy++)
|
||||
{
|
||||
@@ -1463,7 +1463,7 @@ public:
|
||||
t1 = buf[dxn+3] + S[sxn+3]*alpha;
|
||||
buf[dxn+2] = t0; buf[dxn+3] = t1;
|
||||
}
|
||||
|
||||
|
||||
if( (cur_dy + 1)*scale_y <= sy + 1 || sy == ssize.height - 1 )
|
||||
{
|
||||
WT beta = std::max(sy + 1 - (cur_dy+1)*scale_y, (WT)0);
|
||||
@@ -1481,7 +1481,7 @@ public:
|
||||
}
|
||||
else
|
||||
for( dx = 0; dx < dsize.width; dx++ )
|
||||
{
|
||||
{
|
||||
D[dx] = saturate_cast<T>((sum[dx] + buf[dx]* beta1)/ min(scale_y, src.rows - cur_dy*scale_y)); //
|
||||
sum[dx] = buf[dx]*beta;
|
||||
buf[dx] = 0;
|
||||
@@ -1505,7 +1505,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
for (int i = range.start; i < range.end; ++i)
|
||||
@@ -1514,7 +1514,7 @@ public:
|
||||
resize_single_band(band_range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Mat src;
|
||||
Mat dst;
|
||||
@@ -1533,11 +1533,11 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in
|
||||
int *cur_dy_ofs = _yofs;
|
||||
int cur_dy = 0, index = 0;
|
||||
std::vector<std::pair<int, int> > bands;
|
||||
|
||||
|
||||
for (int sy = 0; sy < ssize.height; sy++)
|
||||
{
|
||||
cur_dy_ofs[sy] = cur_dy;
|
||||
|
||||
|
||||
if ((cur_dy + 1) * scale_y_ <= sy + 1 || sy == ssize.height - 1 )
|
||||
{
|
||||
WT beta = (WT)std::max(sy + 1 - (cur_dy + 1) * scale_y_, 0.);
|
||||
@@ -1569,7 +1569,7 @@ typedef void (*ResizeAreaFastFunc)( const Mat& src, Mat& dst,
|
||||
int scale_x, int scale_y );
|
||||
|
||||
typedef void (*ResizeAreaFunc)( const Mat& src, Mat& dst,
|
||||
const DecimateAlpha* xofs, int xofs_count,
|
||||
const DecimateAlpha* xofs, int xofs_count,
|
||||
double scale_y_);
|
||||
|
||||
}
|
||||
@@ -1667,7 +1667,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
|
||||
static ResizeAreaFastFunc areafast_tab[] =
|
||||
{
|
||||
resizeAreaFast_<uchar, int, ResizeAreaFastVec<uchar> >,
|
||||
resizeAreaFast_<uchar, int, ResizeAreaFastVec<uchar> >,
|
||||
0,
|
||||
resizeAreaFast_<ushort, float, ResizeAreaFastVec<ushort> >,
|
||||
resizeAreaFast_<short, float, ResizeAreaFastVec<short> >,
|
||||
@@ -1679,7 +1679,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
|
||||
static ResizeAreaFunc area_tab[] =
|
||||
{
|
||||
resizeArea_<uchar, float>, 0, resizeArea_<ushort, float>,
|
||||
resizeArea_<uchar, float>, 0, resizeArea_<ushort, float>,
|
||||
resizeArea_<short, float>, 0, resizeArea_<float, float>,
|
||||
resizeArea_<double, double>, 0
|
||||
};
|
||||
@@ -1718,15 +1718,15 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
resizeNN( src, dst, inv_scale_x, inv_scale_y );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int iscale_x = saturate_cast<int>(scale_x);
|
||||
int iscale_y = saturate_cast<int>(scale_y);
|
||||
|
||||
|
||||
bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON &&
|
||||
std::abs(scale_y - iscale_y) < DBL_EPSILON;
|
||||
|
||||
// in case of scale_x && scale_y is equal to 2
|
||||
|
||||
// in case of scale_x && scale_y is equal to 2
|
||||
// INTER_AREA (fast) also is equal to INTER_LINEAR
|
||||
if( interpolation == INTER_LINEAR && is_area_fast && iscale_x == 2 && iscale_y == 2 )
|
||||
{
|
||||
@@ -1801,7 +1801,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
xofs[k++].alpha = (float)(min(fsx2 - sx2, 1.) / min(scale_x, src.cols - fsx1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func( src, dst, xofs, k, scale_y);
|
||||
return;
|
||||
}
|
||||
@@ -2684,15 +2684,15 @@ class RemapInvoker :
|
||||
public ParallelLoopBody
|
||||
{
|
||||
public:
|
||||
RemapInvoker(const Mat& _src, Mat& _dst, const Mat *_m1,
|
||||
RemapInvoker(const Mat& _src, Mat& _dst, const Mat *_m1,
|
||||
const Mat *_m2, int _interpolation, int _borderType, const Scalar &_borderValue,
|
||||
int _planar_input, RemapNNFunc _nnfunc, RemapFunc _ifunc, const void *_ctab) :
|
||||
ParallelLoopBody(), src(&_src), dst(&_dst), m1(_m1), m2(_m2),
|
||||
interpolation(_interpolation), borderType(_borderType), borderValue(_borderValue),
|
||||
interpolation(_interpolation), borderType(_borderType), borderValue(_borderValue),
|
||||
planar_input(_planar_input), nnfunc(_nnfunc), ifunc(_ifunc), ctab(_ctab)
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
int x, y, x1, y1;
|
||||
@@ -2866,7 +2866,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
const Mat* src;
|
||||
Mat* dst;
|
||||
@@ -2972,7 +2972,7 @@ void cv::remap( InputArray _src, OutputArray _dst,
|
||||
planar_input = map1.channels() == 1;
|
||||
}
|
||||
|
||||
RemapInvoker invoker(src, dst, m1, m2, interpolation,
|
||||
RemapInvoker invoker(src, dst, m1, m2, interpolation,
|
||||
borderType, borderValue, planar_input, nnfunc, ifunc,
|
||||
ctab);
|
||||
parallel_for_(Range(0, dst.rows), invoker, dst.total()/(double)(1<<16));
|
||||
@@ -3117,33 +3117,33 @@ void cv::convertMaps( InputArray _map1, InputArray _map2,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class warpAffineInvoker :
|
||||
class warpAffineInvoker :
|
||||
public ParallelLoopBody
|
||||
{
|
||||
public:
|
||||
warpAffineInvoker(const Mat &_src, Mat &_dst, int _interpolation, int _borderType,
|
||||
warpAffineInvoker(const Mat &_src, Mat &_dst, int _interpolation, int _borderType,
|
||||
const Scalar &_borderValue, int *_adelta, int *_bdelta, double *_M) :
|
||||
ParallelLoopBody(), src(_src), dst(_dst), interpolation(_interpolation),
|
||||
borderType(_borderType), borderValue(_borderValue), adelta(_adelta), bdelta(_bdelta),
|
||||
M(_M)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
const int BLOCK_SZ = 64;
|
||||
short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ];
|
||||
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 = interpolation == INTER_NEAREST ? AB_SCALE/2 : AB_SCALE/INTER_TAB_SIZE/2, x, y, x1, y1;
|
||||
#if CV_SSE2
|
||||
bool useSIMD = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
|
||||
int bh0 = std::min(BLOCK_SZ/2, dst.rows);
|
||||
int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, dst.cols);
|
||||
bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, dst.rows);
|
||||
@@ -3232,7 +3232,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Mat src;
|
||||
Mat dst;
|
||||
@@ -3243,8 +3243,8 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void cv::warpAffine( InputArray _src, OutputArray _dst,
|
||||
InputArray _M0, Size dsize,
|
||||
int flags, int borderType, const Scalar& borderValue )
|
||||
@@ -3308,41 +3308,41 @@ class warpPerspectiveInvoker :
|
||||
public ParallelLoopBody
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
warpPerspectiveInvoker(const Mat &_src, Mat &_dst, double *_M, int _interpolation,
|
||||
int _borderType, const Scalar &_borderValue) :
|
||||
ParallelLoopBody(), src(_src), dst(_dst), M(_M), interpolation(_interpolation),
|
||||
borderType(_borderType), borderValue(_borderValue)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
const int BLOCK_SZ = 32;
|
||||
short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ];
|
||||
int x, y, x1, y1, width = dst.cols, height = dst.rows;
|
||||
|
||||
|
||||
int bh0 = std::min(BLOCK_SZ/2, height);
|
||||
int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, width);
|
||||
bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, height);
|
||||
|
||||
|
||||
for( y = range.start; y < range.end; y += bh0 )
|
||||
{
|
||||
for( x = 0; x < width; x += bw0 )
|
||||
{
|
||||
int bw = std::min( bw0, width - x);
|
||||
int bh = std::min( bh0, range.end - y); // height
|
||||
|
||||
|
||||
Mat _XY(bh, bw, CV_16SC2, XY), matA;
|
||||
Mat dpart(dst, Rect(x, y, bw, bh));
|
||||
|
||||
|
||||
for( y1 = 0; y1 < bh; y1++ )
|
||||
{
|
||||
short* xy = XY + y1*bw*2;
|
||||
double X0 = M[0]*x + M[1]*(y + y1) + M[2];
|
||||
double Y0 = M[3]*x + M[4]*(y + y1) + M[5];
|
||||
double W0 = M[6]*x + M[7]*(y + y1) + M[8];
|
||||
|
||||
|
||||
if( interpolation == INTER_NEAREST )
|
||||
for( x1 = 0; x1 < bw; x1++ )
|
||||
{
|
||||
@@ -3352,7 +3352,7 @@ public:
|
||||
double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W));
|
||||
int X = saturate_cast<int>(fX);
|
||||
int Y = saturate_cast<int>(fY);
|
||||
|
||||
|
||||
xy[x1*2] = saturate_cast<short>(X);
|
||||
xy[x1*2+1] = saturate_cast<short>(Y);
|
||||
}
|
||||
@@ -3367,7 +3367,7 @@ public:
|
||||
double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W));
|
||||
int X = saturate_cast<int>(fX);
|
||||
int Y = saturate_cast<int>(fY);
|
||||
|
||||
|
||||
xy[x1*2] = saturate_cast<short>(X >> INTER_BITS);
|
||||
xy[x1*2+1] = saturate_cast<short>(Y >> INTER_BITS);
|
||||
alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE +
|
||||
@@ -3375,7 +3375,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( interpolation == INTER_NEAREST )
|
||||
remap( src, dpart, _XY, Mat(), interpolation, borderType, borderValue );
|
||||
else
|
||||
@@ -3386,7 +3386,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Mat src;
|
||||
Mat dst;
|
||||
@@ -3394,7 +3394,7 @@ private:
|
||||
int interpolation, borderType;
|
||||
Scalar borderValue;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
|
||||
|
||||
@@ -394,7 +394,7 @@ static CvStatus icvFitLine2D( CvPoint2D32f * points, int count, int dist,
|
||||
int first = 1;
|
||||
for( i = 0; i < count; i++ )
|
||||
w[i] = 0.f;
|
||||
|
||||
|
||||
for( i = 0; i < MIN(count,10); )
|
||||
{
|
||||
j = cvRandInt(&rng) % count;
|
||||
@@ -542,7 +542,7 @@ icvFitLine3D( CvPoint3D32f * points, int count, int dist,
|
||||
int first = 1;
|
||||
for( i = 0; i < count; i++ )
|
||||
w[i] = 0.f;
|
||||
|
||||
|
||||
for( i = 0; i < MIN(count,10); )
|
||||
{
|
||||
j = cvRandInt(&rng) % count;
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
// method - method for the matching calculation
|
||||
// (now CV_IPPI_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2 or
|
||||
// CV_CONTOURS_MATCH_I3 only )
|
||||
// rezult - output calculated measure
|
||||
// rezult - output calculated measure
|
||||
//
|
||||
//F*/
|
||||
CV_IMPL double
|
||||
|
||||
@@ -91,7 +91,7 @@ struct MorphNoVec
|
||||
{
|
||||
int operator()(uchar**, int, uchar*, int) const { return 0; }
|
||||
};
|
||||
|
||||
|
||||
#if CV_SSE2
|
||||
|
||||
template<class VecUpdate> struct MorphRowIVec
|
||||
@@ -103,7 +103,7 @@ template<class VecUpdate> struct MorphRowIVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE2) )
|
||||
return 0;
|
||||
|
||||
|
||||
cn *= ESZ;
|
||||
int i, k, _ksize = ksize*cn;
|
||||
width = (width & -4)*cn;
|
||||
@@ -145,7 +145,7 @@ template<class VecUpdate> struct MorphRowFVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE) )
|
||||
return 0;
|
||||
|
||||
|
||||
int i, k, _ksize = ksize*cn;
|
||||
width = (width & -4)*cn;
|
||||
VecUpdate updateOp;
|
||||
@@ -177,7 +177,7 @@ template<class VecUpdate> struct MorphColumnIVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE2) )
|
||||
return 0;
|
||||
|
||||
|
||||
int i = 0, k, _ksize = ksize;
|
||||
width *= ESZ;
|
||||
VecUpdate updateOp;
|
||||
@@ -281,7 +281,7 @@ template<class VecUpdate> struct MorphColumnFVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE) )
|
||||
return 0;
|
||||
|
||||
|
||||
int i = 0, k, _ksize = ksize;
|
||||
VecUpdate updateOp;
|
||||
|
||||
@@ -410,7 +410,7 @@ template<class VecUpdate> struct MorphIVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE2) )
|
||||
return 0;
|
||||
|
||||
|
||||
int i, k;
|
||||
width *= ESZ;
|
||||
VecUpdate updateOp;
|
||||
@@ -457,7 +457,7 @@ template<class VecUpdate> struct MorphFVec
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE) )
|
||||
return 0;
|
||||
|
||||
|
||||
const float** src = (const float**)_src;
|
||||
float* dst = (float*)_dst;
|
||||
int i, k;
|
||||
@@ -707,8 +707,8 @@ template<class Op, class VecOp> struct MorphColumnFilter : public BaseColumnFilt
|
||||
|
||||
for( ; _ksize > 1 && count > 1; count -= 2, D += dststep*2, src += 2 )
|
||||
{
|
||||
i = i0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
i = i0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= width - 4; i += 4 )
|
||||
{
|
||||
const T* sptr = src[1] + i;
|
||||
@@ -748,8 +748,8 @@ template<class Op, class VecOp> struct MorphColumnFilter : public BaseColumnFilt
|
||||
|
||||
for( ; count > 0; count--, D += dststep, src++ )
|
||||
{
|
||||
i = i0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
i = i0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= width - 4; i += 4 )
|
||||
{
|
||||
const T* sptr = src[0] + i;
|
||||
@@ -889,7 +889,7 @@ cv::Ptr<cv::BaseRowFilter> cv::getMorphologyRowFilter(int op, int type, int ksiz
|
||||
if( depth == CV_64F )
|
||||
return Ptr<BaseRowFilter>(new MorphRowFilter<MaxOp<double>,
|
||||
DilateRowVec64f>(ksize, anchor));
|
||||
}
|
||||
}
|
||||
|
||||
CV_Error_( CV_StsNotImplemented, ("Unsupported data type (=%d)", type));
|
||||
return Ptr<BaseRowFilter>(0);
|
||||
@@ -1149,7 +1149,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst,
|
||||
|
||||
_dst.create( src.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
if( iterations == 0 || kernel.rows*kernel.cols == 1 )
|
||||
{
|
||||
src.copyTo(dst);
|
||||
@@ -1219,15 +1219,15 @@ void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
|
||||
Mat src = _src.getMat(), temp;
|
||||
_dst.create(src.size(), src.type());
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
|
||||
switch( op )
|
||||
{
|
||||
case MORPH_ERODE:
|
||||
erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
|
||||
break;
|
||||
break;
|
||||
case MORPH_DILATE:
|
||||
dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
|
||||
break;
|
||||
break;
|
||||
case MORPH_OPEN:
|
||||
erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
|
||||
dilate( dst, dst, kernel, anchor, iterations, borderType, borderValue );
|
||||
@@ -1355,14 +1355,14 @@ cvMorphologyEx( const void* srcarr, void* dstarr, void*,
|
||||
IplConvKernel* temp_element = NULL;
|
||||
if (!element)
|
||||
{
|
||||
temp_element = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_RECT);
|
||||
temp_element = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_RECT);
|
||||
} else {
|
||||
temp_element = element;
|
||||
temp_element = element;
|
||||
}
|
||||
convertConvKernel( temp_element, kernel, anchor );
|
||||
if (!element)
|
||||
{
|
||||
cvReleaseStructuringElement(&temp_element);
|
||||
cvReleaseStructuringElement(&temp_element);
|
||||
}
|
||||
cv::morphologyEx( src, dst, op, kernel, anchor, iterations, cv::BORDER_REPLICATE );
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ struct PyrDownVec_32s8u
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE2) )
|
||||
return 0;
|
||||
|
||||
|
||||
int x = 0;
|
||||
const int *row0 = src[0], *row1 = src[1], *row2 = src[2], *row3 = src[3], *row4 = src[4];
|
||||
__m128i delta = _mm_set1_epi16(128);
|
||||
@@ -139,7 +139,7 @@ struct PyrDownVec_32f
|
||||
{
|
||||
if( !checkHardwareSupport(CV_CPU_SSE) )
|
||||
return 0;
|
||||
|
||||
|
||||
int x = 0;
|
||||
const float *row0 = src[0], *row1 = src[1], *row2 = src[2], *row3 = src[3], *row4 = src[4];
|
||||
__m128 _4 = _mm_set1_ps(4.f), _scale = _mm_set1_ps(1.f/256);
|
||||
@@ -217,7 +217,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType )
|
||||
tabR[x*cn + k] = sx1 + k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ssize.width *= cn;
|
||||
dsize.width *= cn;
|
||||
width0 *= cn;
|
||||
@@ -400,7 +400,7 @@ pyrUp_( const Mat& _src, Mat& _dst, int)
|
||||
typedef void (*PyrFunc)(const Mat&, Mat&, int);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
@@ -492,11 +492,11 @@ cvReleasePyramid( CvMat*** _pyramid, int extra_layers )
|
||||
{
|
||||
if( !_pyramid )
|
||||
CV_Error( CV_StsNullPtr, "" );
|
||||
|
||||
|
||||
if( *_pyramid )
|
||||
for( int i = 0; i <= extra_layers; i++ )
|
||||
cvReleaseMat( &(*_pyramid)[i] );
|
||||
|
||||
|
||||
cvFree( _pyramid );
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ cvSampleLine( const void* img, CvPoint pt1, CvPoint pt2,
|
||||
void* _buffer, int connectivity )
|
||||
{
|
||||
int count = -1;
|
||||
|
||||
|
||||
int i, coi = 0, pix_size;
|
||||
CvMat stub, *mat = cvGetMat( img, &stub, &coi );
|
||||
CvLineIterator iterator;
|
||||
|
||||
@@ -64,7 +64,7 @@ static CvWSNode*
|
||||
icvAllocWSNodes( CvMemStorage* storage )
|
||||
{
|
||||
CvWSNode* n = 0;
|
||||
|
||||
|
||||
int i, count = (storage->block_size - sizeof(CvMemBlock))/sizeof(*n) - 1;
|
||||
|
||||
n = (CvWSNode*)cvMemStorageAlloc( storage, count*sizeof(*n) );
|
||||
@@ -83,7 +83,7 @@ cvWatershed( const CvArr* srcarr, CvArr* dstarr )
|
||||
const int WSHED = -1;
|
||||
const int NQ = 256;
|
||||
cv::Ptr<CvMemStorage> storage;
|
||||
|
||||
|
||||
CvMat sstub, *src;
|
||||
CvMat dstub, *dst;
|
||||
CvSize size;
|
||||
@@ -149,7 +149,7 @@ cvWatershed( const CvArr* srcarr, CvArr* dstarr )
|
||||
if( CV_MAT_TYPE(dst->type) != CV_32SC1 )
|
||||
CV_Error( CV_StsUnsupportedFormat,
|
||||
"Only 32-bit, 1-channel output images are supported" );
|
||||
|
||||
|
||||
if( !CV_ARE_SIZES_EQ( src, dst ))
|
||||
CV_Error( CV_StsUnmatchedSizes, "The input and output images must have the same size" );
|
||||
|
||||
@@ -231,7 +231,7 @@ cvWatershed( const CvArr* srcarr, CvArr* dstarr )
|
||||
int lab = 0, t;
|
||||
int* m;
|
||||
uchar* ptr;
|
||||
|
||||
|
||||
if( q[active_queue].first == 0 )
|
||||
{
|
||||
for( i = active_queue+1; i < NQ; i++ )
|
||||
@@ -316,13 +316,13 @@ void cv::watershed( InputArray _src, InputOutputArray markers )
|
||||
\****************************************************************************************/
|
||||
|
||||
CV_IMPL void
|
||||
cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
double sp0, double sr, int max_level,
|
||||
CvTermCriteria termcrit )
|
||||
{
|
||||
const int cn = 3;
|
||||
const int MAX_LEVELS = 8;
|
||||
|
||||
|
||||
if( (unsigned)max_level > (unsigned)MAX_LEVELS )
|
||||
CV_Error( CV_StsOutOfRange, "The number of pyramid levels is too large or negative" );
|
||||
|
||||
@@ -343,7 +343,7 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
|
||||
if( src0.type() != CV_8UC3 )
|
||||
CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 3-channel images are supported" );
|
||||
|
||||
|
||||
if( src0.type() != dst0.type() )
|
||||
CV_Error( CV_StsUnmatchedFormats, "The input and output images must have the same type" );
|
||||
|
||||
@@ -423,9 +423,9 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
for( i = 0; i < size.height; i++, sptr += sstep - size.width*3,
|
||||
dptr += dstep - size.width*3,
|
||||
mask += mstep )
|
||||
{
|
||||
{
|
||||
for( j = 0; j < size.width; j++, sptr += 3, dptr += 3 )
|
||||
{
|
||||
{
|
||||
int x0 = j, y0 = i, x1, y1, iter;
|
||||
int c0, c1, c2;
|
||||
|
||||
@@ -449,46 +449,46 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
miny = cvRound(y0 - sp); miny = MAX(miny, 0);
|
||||
maxx = cvRound(x0 + sp); maxx = MIN(maxx, size.width-1);
|
||||
maxy = cvRound(y0 + sp); maxy = MIN(maxy, size.height-1);
|
||||
ptr = sptr + (miny - i)*sstep + (minx - j)*3;
|
||||
ptr = sptr + (miny - i)*sstep + (minx - j)*3;
|
||||
|
||||
for( y = miny; y <= maxy; y++, ptr += sstep - (maxx-minx+1)*3 )
|
||||
{
|
||||
int row_count = 0;
|
||||
x = minx;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; x + 3 <= maxx; x += 4, ptr += 12 )
|
||||
{
|
||||
int t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
|
||||
if( tab[t0-c0+255] + tab[t1-c1+255] + tab[t2-c2+255] <= isr2 )
|
||||
{
|
||||
{
|
||||
s0 += t0; s1 += t1; s2 += t2;
|
||||
sx += x; row_count++;
|
||||
}
|
||||
t0 = ptr[3], t1 = ptr[4], t2 = ptr[5];
|
||||
if( tab[t0-c0+255] + tab[t1-c1+255] + tab[t2-c2+255] <= isr2 )
|
||||
{
|
||||
{
|
||||
s0 += t0; s1 += t1; s2 += t2;
|
||||
sx += x+1; row_count++;
|
||||
}
|
||||
t0 = ptr[6], t1 = ptr[7], t2 = ptr[8];
|
||||
if( tab[t0-c0+255] + tab[t1-c1+255] + tab[t2-c2+255] <= isr2 )
|
||||
{
|
||||
{
|
||||
s0 += t0; s1 += t1; s2 += t2;
|
||||
sx += x+2; row_count++;
|
||||
}
|
||||
t0 = ptr[9], t1 = ptr[10], t2 = ptr[11];
|
||||
if( tab[t0-c0+255] + tab[t1-c1+255] + tab[t2-c2+255] <= isr2 )
|
||||
{
|
||||
{
|
||||
s0 += t0; s1 += t1; s2 += t2;
|
||||
sx += x+3; row_count++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; x <= maxx; x++, ptr += 3 )
|
||||
{
|
||||
{
|
||||
int t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
|
||||
if( tab[t0-c0+255] + tab[t1-c1+255] + tab[t2-c2+255] <= isr2 )
|
||||
{
|
||||
{
|
||||
s0 += t0; s1 += t1; s2 += t2;
|
||||
sx += x; row_count++;
|
||||
}
|
||||
@@ -510,7 +510,7 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
|
||||
stop_flag = (x0 == x1 && y0 == y1) || abs(x1-x0) + abs(y1-y0) +
|
||||
tab[s0 - c0 + 255] + tab[s1 - c1 + 255] +
|
||||
tab[s2 - c2 + 255] <= termcrit.epsilon;
|
||||
|
||||
|
||||
x0 = x1; y0 = y1;
|
||||
c0 = s0; c1 = s1; c2 = s2;
|
||||
|
||||
@@ -531,7 +531,7 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst,
|
||||
TermCriteria termcrit )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
|
||||
|
||||
if( src.empty() )
|
||||
return;
|
||||
|
||||
|
||||
@@ -1064,47 +1064,47 @@ cvBoundingRect( CvArr* array, int update )
|
||||
|
||||
if( xmin >= size.width )
|
||||
xmin = ymin = 0;
|
||||
}
|
||||
else if( ptseq->total )
|
||||
{
|
||||
int is_float = CV_SEQ_ELTYPE(ptseq) == CV_32FC2;
|
||||
cvStartReadSeq( ptseq, &reader, 0 );
|
||||
CvPoint pt;
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
#if CV_SSE4_2
|
||||
if(cv::checkHardwareSupport(CV_CPU_SSE4_2))
|
||||
{
|
||||
if( !is_float )
|
||||
{
|
||||
}
|
||||
else if( ptseq->total )
|
||||
{
|
||||
int is_float = CV_SEQ_ELTYPE(ptseq) == CV_32FC2;
|
||||
cvStartReadSeq( ptseq, &reader, 0 );
|
||||
CvPoint pt;
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
#if CV_SSE4_2
|
||||
if(cv::checkHardwareSupport(CV_CPU_SSE4_2))
|
||||
{
|
||||
if( !is_float )
|
||||
{
|
||||
__m128i minval, maxval;
|
||||
minval = maxval = _mm_loadl_epi64((const __m128i*)(&pt)); //min[0]=pt.x, min[1]=pt.y
|
||||
|
||||
for( i = 1; i < ptseq->total; i++)
|
||||
{
|
||||
__m128i ptXY = _mm_loadl_epi64((const __m128i*)(reader.ptr));
|
||||
minval = maxval = _mm_loadl_epi64((const __m128i*)(&pt)); //min[0]=pt.x, min[1]=pt.y
|
||||
|
||||
for( i = 1; i < ptseq->total; i++)
|
||||
{
|
||||
__m128i ptXY = _mm_loadl_epi64((const __m128i*)(reader.ptr));
|
||||
CV_NEXT_SEQ_ELEM(sizeof(pt), reader);
|
||||
minval = _mm_min_epi32(ptXY, minval);
|
||||
maxval = _mm_max_epi32(ptXY, maxval);
|
||||
}
|
||||
minval = _mm_min_epi32(ptXY, minval);
|
||||
maxval = _mm_max_epi32(ptXY, maxval);
|
||||
}
|
||||
xmin = _mm_cvtsi128_si32(minval);
|
||||
ymin = _mm_cvtsi128_si32(_mm_srli_si128(minval, 4));
|
||||
xmax = _mm_cvtsi128_si32(maxval);
|
||||
ymax = _mm_cvtsi128_si32(_mm_srli_si128(maxval, 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
__m128 minvalf, maxvalf, z = _mm_setzero_ps(), ptXY = _mm_setzero_ps();
|
||||
minvalf = maxvalf = _mm_loadl_pi(z, (const __m64*)(&pt));
|
||||
minvalf = maxvalf = _mm_loadl_pi(z, (const __m64*)(&pt));
|
||||
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
ptXY = _mm_loadl_pi(ptXY, (const __m64*)reader.ptr);
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
ptXY = _mm_loadl_pi(ptXY, (const __m64*)reader.ptr);
|
||||
CV_NEXT_SEQ_ELEM(sizeof(pt), reader);
|
||||
|
||||
minvalf = _mm_min_ps(minvalf, ptXY);
|
||||
maxvalf = _mm_max_ps(maxvalf, ptXY);
|
||||
}
|
||||
|
||||
minvalf = _mm_min_ps(minvalf, ptXY);
|
||||
maxvalf = _mm_max_ps(maxvalf, ptXY);
|
||||
}
|
||||
|
||||
float xyminf[2], xymaxf[2];
|
||||
_mm_storel_pi((__m64*)xyminf, minvalf);
|
||||
_mm_storel_pi((__m64*)xymaxf, maxvalf);
|
||||
@@ -1113,72 +1113,72 @@ cvBoundingRect( CvArr* array, int update )
|
||||
xmax = cvFloor(xymaxf[0]);
|
||||
ymax = cvFloor(xymaxf[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if( !is_float )
|
||||
{
|
||||
xmin = xmax = pt.x;
|
||||
ymin = ymax = pt.y;
|
||||
{
|
||||
if( !is_float )
|
||||
{
|
||||
xmin = xmax = pt.x;
|
||||
ymin = ymax = pt.y;
|
||||
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
|
||||
if( xmin > pt.x )
|
||||
xmin = pt.x;
|
||||
if( xmin > pt.x )
|
||||
xmin = pt.x;
|
||||
|
||||
if( xmax < pt.x )
|
||||
xmax = pt.x;
|
||||
if( xmax < pt.x )
|
||||
xmax = pt.x;
|
||||
|
||||
if( ymin > pt.y )
|
||||
ymin = pt.y;
|
||||
if( ymin > pt.y )
|
||||
ymin = pt.y;
|
||||
|
||||
if( ymax < pt.y )
|
||||
ymax = pt.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv32suf v;
|
||||
// init values
|
||||
xmin = xmax = CV_TOGGLE_FLT(pt.x);
|
||||
ymin = ymax = CV_TOGGLE_FLT(pt.y);
|
||||
if( ymax < pt.y )
|
||||
ymax = pt.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv32suf v;
|
||||
// init values
|
||||
xmin = xmax = CV_TOGGLE_FLT(pt.x);
|
||||
ymin = ymax = CV_TOGGLE_FLT(pt.y);
|
||||
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
pt.x = CV_TOGGLE_FLT(pt.x);
|
||||
pt.y = CV_TOGGLE_FLT(pt.y);
|
||||
for( i = 1; i < ptseq->total; i++ )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( pt, reader );
|
||||
pt.x = CV_TOGGLE_FLT(pt.x);
|
||||
pt.y = CV_TOGGLE_FLT(pt.y);
|
||||
|
||||
if( xmin > pt.x )
|
||||
xmin = pt.x;
|
||||
if( xmin > pt.x )
|
||||
xmin = pt.x;
|
||||
|
||||
if( xmax < pt.x )
|
||||
xmax = pt.x;
|
||||
if( xmax < pt.x )
|
||||
xmax = pt.x;
|
||||
|
||||
if( ymin > pt.y )
|
||||
ymin = pt.y;
|
||||
if( ymin > pt.y )
|
||||
ymin = pt.y;
|
||||
|
||||
if( ymax < pt.y )
|
||||
ymax = pt.y;
|
||||
}
|
||||
if( ymax < pt.y )
|
||||
ymax = pt.y;
|
||||
}
|
||||
|
||||
v.i = CV_TOGGLE_FLT(xmin); xmin = cvFloor(v.f);
|
||||
v.i = CV_TOGGLE_FLT(ymin); ymin = cvFloor(v.f);
|
||||
// because right and bottom sides of the bounding rectangle are not inclusive
|
||||
// (note +1 in width and height calculation below), cvFloor is used here instead of cvCeil
|
||||
v.i = CV_TOGGLE_FLT(xmax); xmax = cvFloor(v.f);
|
||||
v.i = CV_TOGGLE_FLT(ymax); ymax = cvFloor(v.f);
|
||||
}
|
||||
}
|
||||
v.i = CV_TOGGLE_FLT(xmin); xmin = cvFloor(v.f);
|
||||
v.i = CV_TOGGLE_FLT(ymin); ymin = cvFloor(v.f);
|
||||
// because right and bottom sides of the bounding rectangle are not inclusive
|
||||
// (note +1 in width and height calculation below), cvFloor is used here instead of cvCeil
|
||||
v.i = CV_TOGGLE_FLT(xmax); xmax = cvFloor(v.f);
|
||||
v.i = CV_TOGGLE_FLT(ymax); ymax = cvFloor(v.f);
|
||||
}
|
||||
}
|
||||
rect.x = xmin;
|
||||
rect.y = ymin;
|
||||
rect.width = xmax - xmin + 1;
|
||||
rect.height = ymax - ymin + 1;
|
||||
}
|
||||
if( update )
|
||||
}
|
||||
if( update )
|
||||
((CvContour*)ptseq)->rect = rect;
|
||||
return rect;
|
||||
}
|
||||
|
||||
+180
-180
@@ -215,10 +215,10 @@ template<> struct ColumnSum<int, uchar> : public BaseColumnFilter
|
||||
int* SUM;
|
||||
bool haveScale = scale != 1;
|
||||
double _scale = scale;
|
||||
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
if( width != (int)sum.size() )
|
||||
{
|
||||
@@ -229,22 +229,22 @@ template<> struct ColumnSum<int, uchar> : public BaseColumnFilter
|
||||
SUM = &sum[0];
|
||||
if( sumCount == 0 )
|
||||
{
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
for( ; sumCount < ksize - 1; sumCount++, src++ )
|
||||
{
|
||||
const int* Sp = (const int*)src[0];
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
SUM[i] += Sp[i];
|
||||
}
|
||||
@@ -262,33 +262,33 @@ template<> struct ColumnSum<int, uchar> : public BaseColumnFilter
|
||||
uchar* D = (uchar*)dst;
|
||||
if( haveScale )
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i+4)));
|
||||
|
||||
__m128i _s0T = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
__m128i _s0T1 = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s01)));
|
||||
|
||||
_s0T = _mm_packs_epi32(_s0T, _s0T1);
|
||||
__m128i _s0T = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
__m128i _s0T1 = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s01)));
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _mm_packus_epi16(_s0T, _s0T));
|
||||
_s0T = _mm_packs_epi32(_s0T, _s0T1);
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_mm_storel_epi64((__m128i*)(D+i), _mm_packus_epi16(_s0T, _s0T));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
int s0 = SUM[i] + Sp[i];
|
||||
@@ -298,29 +298,29 @@ template<> struct ColumnSum<int, uchar> : public BaseColumnFilter
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i+4)));
|
||||
|
||||
__m128i _s0T = _mm_packs_epi32(_s0, _s01);
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _mm_packus_epi16(_s0T, _s0T));
|
||||
__m128i _s0T = _mm_packs_epi32(_s0, _s01);
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_mm_storel_epi64((__m128i*)(D+i), _mm_packus_epi16(_s0T, _s0T));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
@@ -357,9 +357,9 @@ template<> struct ColumnSum<int, short> : public BaseColumnFilter
|
||||
bool haveScale = scale != 1;
|
||||
double _scale = scale;
|
||||
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
if( width != (int)sum.size() )
|
||||
{
|
||||
@@ -369,22 +369,22 @@ template<> struct ColumnSum<int, short> : public BaseColumnFilter
|
||||
SUM = &sum[0];
|
||||
if( sumCount == 0 )
|
||||
{
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
for( ; sumCount < ksize - 1; sumCount++, src++ )
|
||||
{
|
||||
const int* Sp = (const int*)src[0];
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
SUM[i] += Sp[i];
|
||||
}
|
||||
@@ -402,31 +402,31 @@ template<> struct ColumnSum<int, short> : public BaseColumnFilter
|
||||
short* D = (short*)dst;
|
||||
if( haveScale )
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i+4)));
|
||||
|
||||
__m128i _s0T = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
__m128i _s0T1 = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s01)));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(D+i), _mm_packs_epi32(_s0T, _s0T1));
|
||||
__m128i _s0T = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
__m128i _s0T1 = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s01)));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4), _mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_mm_storeu_si128((__m128i*)(D+i), _mm_packs_epi32(_s0T, _s0T1));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i),_mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4), _mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
int s0 = SUM[i] + Sp[i];
|
||||
@@ -436,28 +436,28 @@ template<> struct ColumnSum<int, short> : public BaseColumnFilter
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-8; i+=8 )
|
||||
{
|
||||
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _sm1 = _mm_loadu_si128((const __m128i*)(Sm+i+4));
|
||||
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
__m128i _s01 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i+4)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i+4)));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(D+i), _mm_packs_epi32(_s0, _s01));
|
||||
_mm_storeu_si128((__m128i*)(D+i), _mm_packs_epi32(_s0, _s01));
|
||||
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i+4),_mm_sub_epi32(_s01,_sm1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
@@ -494,9 +494,9 @@ template<> struct ColumnSum<int, ushort> : public BaseColumnFilter
|
||||
int* SUM;
|
||||
bool haveScale = scale != 1;
|
||||
double _scale = scale;
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
#if CV_SSE2
|
||||
bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
|
||||
#endif
|
||||
|
||||
if( width != (int)sum.size() )
|
||||
{
|
||||
@@ -506,22 +506,22 @@ template<> struct ColumnSum<int, ushort> : public BaseColumnFilter
|
||||
SUM = &sum[0];
|
||||
if( sumCount == 0 )
|
||||
{
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
memset((void*)SUM, 0, width*sizeof(int));
|
||||
for( ; sumCount < ksize - 1; sumCount++, src++ )
|
||||
{
|
||||
const int* Sp = (const int*)src[0];
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sum = _mm_loadu_si128((const __m128i*)(SUM+i));
|
||||
__m128i _sp = _mm_loadu_si128((const __m128i*)(Sp+i));
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_add_epi32(_sum, _sp));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
SUM[i] += Sp[i];
|
||||
}
|
||||
@@ -539,30 +539,30 @@ template<> struct ColumnSum<int, ushort> : public BaseColumnFilter
|
||||
ushort* D = (ushort*)dst;
|
||||
if( haveScale )
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
const __m128i delta0 = _mm_set1_epi32(0x8000);
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128 scale4 = _mm_set1_ps((float)_scale);
|
||||
const __m128i delta0 = _mm_set1_epi32(0x8000);
|
||||
const __m128i delta1 = _mm_set1_epi32(0x80008000);
|
||||
|
||||
for( ; i < width-4; i+=4)
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
for( ; i < width-4; i+=4)
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
|
||||
__m128i _res = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
|
||||
__m128i _res = _mm_cvtps_epi32(_mm_mul_ps(scale4, _mm_cvtepi32_ps(_s0)));
|
||||
|
||||
_res = _mm_sub_epi32(_res, delta0);
|
||||
_res = _mm_add_epi16(_mm_packs_epi32(_res, _res), delta1);
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _res);
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _res);
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
int s0 = SUM[i] + Sp[i];
|
||||
@@ -572,27 +572,27 @@ template<> struct ColumnSum<int, ushort> : public BaseColumnFilter
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128i delta0 = _mm_set1_epi32(0x8000);
|
||||
i = 0;
|
||||
#if CV_SSE2
|
||||
if(haveSSE2)
|
||||
{
|
||||
const __m128i delta0 = _mm_set1_epi32(0x8000);
|
||||
const __m128i delta1 = _mm_set1_epi32(0x80008000);
|
||||
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
for( ; i < width-4; i+=4 )
|
||||
{
|
||||
__m128i _sm = _mm_loadu_si128((const __m128i*)(Sm+i));
|
||||
__m128i _s0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(SUM+i)),
|
||||
_mm_loadu_si128((const __m128i*)(Sp+i)));
|
||||
|
||||
__m128i _res = _mm_sub_epi32(_s0, delta0);
|
||||
__m128i _res = _mm_sub_epi32(_s0, delta0);
|
||||
_res = _mm_add_epi16(_mm_packs_epi32(_res, _res), delta1);
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _res);
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_mm_storel_epi64((__m128i*)(D+i), _res);
|
||||
_mm_storeu_si128((__m128i*)(SUM+i), _mm_sub_epi32(_s0,_sm));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for( ; i < width; i++ )
|
||||
{
|
||||
@@ -1712,7 +1712,7 @@ public:
|
||||
maxk(_maxk), space_ofs(_space_ofs), space_weight(_space_weight), color_weight(_color_weight)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
int i, j, cn = dest->channels(), k;
|
||||
@@ -1723,12 +1723,12 @@ public:
|
||||
static const int CV_DECL_ALIGNED(16) bufSignMask[] = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 };
|
||||
bool haveSSE3 = checkHardwareSupport(CV_CPU_SSE3);
|
||||
#endif
|
||||
|
||||
|
||||
for( i = range.start; i < range.end; i++ )
|
||||
{
|
||||
const uchar* sptr = temp->ptr(i+radius) + radius*cn;
|
||||
uchar* dptr = dest->ptr(i);
|
||||
|
||||
|
||||
if( cn == 1 )
|
||||
{
|
||||
for( j = 0; j < size.width; j++ )
|
||||
@@ -1746,7 +1746,7 @@ public:
|
||||
{
|
||||
__m128 _valF = _mm_set_ps(sptr[j + space_ofs[k+3]], sptr[j + space_ofs[k+2]],
|
||||
sptr[j + space_ofs[k+1]], sptr[j + space_ofs[k]]);
|
||||
|
||||
|
||||
__m128 _val = _mm_andnot_ps(_signMask, _mm_sub_ps(_valF, _val0));
|
||||
_mm_store_si128((__m128i*)buf, _mm_cvtps_epi32(_val));
|
||||
|
||||
@@ -1791,7 +1791,7 @@ public:
|
||||
const __m128 _g0 = _mm_set1_ps(static_cast<float>(g0));
|
||||
const __m128 _r0 = _mm_set1_ps(static_cast<float>(r0));
|
||||
const __m128 _signMask = _mm_load_ps((const float*)bufSignMask);
|
||||
|
||||
|
||||
for( ; k <= maxk - 4; k += 4 )
|
||||
{
|
||||
const uchar* sptr_k = sptr + j + space_ofs[k];
|
||||
@@ -1851,7 +1851,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
const Mat *temp;
|
||||
Mat *dest;
|
||||
@@ -1868,41 +1868,41 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d,
|
||||
int cn = src.channels();
|
||||
int i, j, maxk, radius;
|
||||
Size size = src.size();
|
||||
|
||||
|
||||
CV_Assert( (src.type() == CV_8UC1 || src.type() == CV_8UC3) &&
|
||||
src.type() == dst.type() && src.size() == dst.size() &&
|
||||
src.data != dst.data );
|
||||
|
||||
|
||||
if( sigma_color <= 0 )
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
|
||||
|
||||
if( d <= 0 )
|
||||
radius = cvRound(sigma_space*1.5);
|
||||
else
|
||||
radius = d/2;
|
||||
radius = MAX(radius, 1);
|
||||
d = radius*2 + 1;
|
||||
|
||||
|
||||
Mat temp;
|
||||
copyMakeBorder( src, temp, radius, radius, radius, radius, borderType );
|
||||
|
||||
|
||||
vector<float> _color_weight(cn*256);
|
||||
vector<float> _space_weight(d*d);
|
||||
vector<int> _space_ofs(d*d);
|
||||
float* color_weight = &_color_weight[0];
|
||||
float* space_weight = &_space_weight[0];
|
||||
int* space_ofs = &_space_ofs[0];
|
||||
|
||||
|
||||
// initialize color-related bilateral filter coefficients
|
||||
|
||||
for( i = 0; i < 256*cn; i++ )
|
||||
color_weight[i] = (float)std::exp(i*i*gauss_color_coeff);
|
||||
|
||||
|
||||
// initialize space-related bilateral filter coefficients
|
||||
for( i = -radius, maxk = 0; i <= radius; i++ )
|
||||
{
|
||||
@@ -1917,7 +1917,7 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d,
|
||||
space_ofs[maxk++] = (int)(i*temp.step + j*cn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BilateralFilter_8u_Invoker body(dst, temp, radius, maxk, space_ofs, space_weight, color_weight);
|
||||
parallel_for_(Range(0, size.height), body, dst.total()/(double)(1<<16));
|
||||
}
|
||||
@@ -1964,7 +1964,7 @@ public:
|
||||
const __m128 _val0 = _mm_set1_ps(sptr[j]);
|
||||
const __m128 _scale_index = _mm_set1_ps(scale_index);
|
||||
const __m128 _signMask = _mm_load_ps((const float*)bufSignMask);
|
||||
|
||||
|
||||
for( ; k <= maxk - 4 ; k += 4 )
|
||||
{
|
||||
__m128 _sw = _mm_loadu_ps(space_weight + k);
|
||||
@@ -1980,7 +1980,7 @@ public:
|
||||
expLUT[idxBuf[1]], expLUT[idxBuf[0]]);
|
||||
__m128 _explut1 = _mm_set_ps(expLUT[idxBuf[3]+1], expLUT[idxBuf[2]+1],
|
||||
expLUT[idxBuf[1]+1], expLUT[idxBuf[0]+1]);
|
||||
|
||||
|
||||
__m128 _w = _mm_mul_ps(_sw, _mm_add_ps(_explut, _mm_mul_ps(_alpha, _mm_sub_ps(_explut1, _explut))));
|
||||
_val = _mm_mul_ps(_w, _val);
|
||||
|
||||
@@ -2023,7 +2023,7 @@ public:
|
||||
const __m128 _r0 = _mm_set1_ps(r0);
|
||||
const __m128 _scale_index = _mm_set1_ps(scale_index);
|
||||
const __m128 _signMask = _mm_load_ps((const float*)bufSignMask);
|
||||
|
||||
|
||||
for( ; k <= maxk-4; k += 4 )
|
||||
{
|
||||
__m128 _sw = _mm_loadu_ps(space_weight + k);
|
||||
@@ -2049,7 +2049,7 @@ public:
|
||||
|
||||
__m128 _explut = _mm_set_ps(expLUT[idxBuf[3]], expLUT[idxBuf[2]], expLUT[idxBuf[1]], expLUT[idxBuf[0]]);
|
||||
__m128 _explut1 = _mm_set_ps(expLUT[idxBuf[3]+1], expLUT[idxBuf[2]+1], expLUT[idxBuf[1]+1], expLUT[idxBuf[0]+1]);
|
||||
|
||||
|
||||
__m128 _w = _mm_mul_ps(_sw, _mm_add_ps(_explut, _mm_mul_ps(_alpha, _mm_sub_ps(_explut1, _explut))));
|
||||
|
||||
_b = _mm_mul_ps(_b, _w);
|
||||
@@ -2070,7 +2070,7 @@ public:
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for(; k < maxk; k++ )
|
||||
{
|
||||
const float* sptr_k = sptr + j + space_ofs[k];
|
||||
@@ -2099,7 +2099,7 @@ private:
|
||||
Mat *dest;
|
||||
float scale_index, *space_weight, *expLUT;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
@@ -2176,7 +2176,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
|
||||
}
|
||||
|
||||
// initialize space-related bilateral filter coefficients
|
||||
for( i = -radius, maxk = 0; i <= radius; i++ )
|
||||
for( i = -radius, maxk = 0; i <= radius; i++ )
|
||||
for( j = -radius; j <= radius; j++ )
|
||||
{
|
||||
double r = std::sqrt((double)i*i + (double)j*j);
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
int Subdiv2D::nextEdge(int edge) const
|
||||
{
|
||||
CV_DbgAssert((size_t)(edge >> 2) < qedges.size());
|
||||
@@ -114,7 +114,7 @@ Subdiv2D::Subdiv2D(Rect rect)
|
||||
freeQEdge = 0;
|
||||
freePoint = 0;
|
||||
recentEdge = 0;
|
||||
|
||||
|
||||
initDelaunay(rect);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ Subdiv2D::QuadEdge::QuadEdge(int edgeidx)
|
||||
next[1] = edgeidx+3;
|
||||
next[2] = edgeidx+2;
|
||||
next[3] = edgeidx+1;
|
||||
|
||||
|
||||
pt[0] = pt[1] = pt[2] = pt[3] = 0;
|
||||
}
|
||||
|
||||
@@ -187,10 +187,10 @@ void Subdiv2D::setEdgePoints(int edge, int orgPt, int dstPt)
|
||||
int Subdiv2D::connectEdges( int edgeA, int edgeB )
|
||||
{
|
||||
int edge = newEdge();
|
||||
|
||||
|
||||
splice(edge, getEdge(edgeA, NEXT_AROUND_LEFT));
|
||||
splice(symEdge(edge), edgeB);
|
||||
|
||||
|
||||
setEdgePoints(edge, edgeDst(edgeA), edgeOrg(edgeB));
|
||||
return edge;
|
||||
}
|
||||
@@ -200,12 +200,12 @@ void Subdiv2D::swapEdges( int edge )
|
||||
int sedge = symEdge(edge);
|
||||
int a = getEdge(edge, PREV_AROUND_ORG);
|
||||
int b = getEdge(sedge, PREV_AROUND_ORG);
|
||||
|
||||
|
||||
splice(edge, a);
|
||||
splice(sedge, b);
|
||||
|
||||
|
||||
setEdgePoints(edge, edgeDst(a), edgeDst(b));
|
||||
|
||||
|
||||
splice(edge, getEdge(a, NEXT_AROUND_LEFT));
|
||||
splice(sedge, getEdge(b, NEXT_AROUND_LEFT));
|
||||
}
|
||||
@@ -213,15 +213,15 @@ void Subdiv2D::swapEdges( int edge )
|
||||
static double triangleArea( Point2f a, Point2f b, Point2f c )
|
||||
{
|
||||
return ((double)b.x - a.x) * ((double)c.y - a.y) - ((double)b.y - a.y) * ((double)c.x - a.x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int Subdiv2D::isRightOf(Point2f pt, int edge) const
|
||||
{
|
||||
Point2f org, dst;
|
||||
edgeOrg(edge, &org);
|
||||
edgeDst(edge, &dst);
|
||||
double cw_area = triangleArea( pt, dst, org );
|
||||
|
||||
|
||||
return (cw_area > 0) - (cw_area < 0);
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ void Subdiv2D::deleteEdge(int edge)
|
||||
splice( edge, getEdge(edge, PREV_AROUND_ORG) );
|
||||
int sedge = symEdge(edge);
|
||||
splice(sedge, getEdge(sedge, PREV_AROUND_ORG) );
|
||||
|
||||
|
||||
edge >>= 2;
|
||||
qedges[edge].next[0] = 0;
|
||||
qedges[edge].next[1] = freeQEdge;
|
||||
@@ -261,7 +261,7 @@ int Subdiv2D::newPoint(Point2f pt, bool isvirtual, int firstEdge)
|
||||
int vidx = freePoint;
|
||||
freePoint = vtx[vidx].firstEdge;
|
||||
vtx[vidx] = Vertex(pt, isvirtual, firstEdge);
|
||||
|
||||
|
||||
return vidx;
|
||||
}
|
||||
|
||||
@@ -276,35 +276,35 @@ void Subdiv2D::deletePoint(int vidx)
|
||||
int Subdiv2D::locate(Point2f pt, int& _edge, int& _vertex)
|
||||
{
|
||||
int vertex = 0;
|
||||
|
||||
|
||||
int i, maxEdges = (int)(qedges.size() * 4);
|
||||
|
||||
|
||||
if( qedges.size() < (size_t)4 )
|
||||
CV_Error( CV_StsError, "Subdivision is empty" );
|
||||
|
||||
|
||||
if( pt.x < topLeft.x || pt.y < topLeft.y || pt.x >= bottomRight.x || pt.y >= bottomRight.y )
|
||||
CV_Error( CV_StsOutOfRange, "" );
|
||||
|
||||
|
||||
int edge = recentEdge;
|
||||
CV_Assert(edge > 0);
|
||||
|
||||
|
||||
int location = PTLOC_ERROR;
|
||||
|
||||
|
||||
int right_of_curr = isRightOf(pt, edge);
|
||||
if( right_of_curr > 0 )
|
||||
{
|
||||
edge = symEdge(edge);
|
||||
right_of_curr = -right_of_curr;
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < maxEdges; i++ )
|
||||
{
|
||||
int onext_edge = nextEdge( edge );
|
||||
int dprev_edge = getEdge( edge, PREV_AROUND_DST );
|
||||
|
||||
|
||||
int right_of_onext = isRightOf( pt, onext_edge );
|
||||
int right_of_dprev = isRightOf( pt, dprev_edge );
|
||||
|
||||
|
||||
if( right_of_dprev > 0 )
|
||||
{
|
||||
if( right_of_onext > 0 || (right_of_onext == 0 && right_of_curr == 0) )
|
||||
@@ -345,22 +345,22 @@ int Subdiv2D::locate(Point2f pt, int& _edge, int& _vertex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recentEdge = edge;
|
||||
|
||||
|
||||
if( location == PTLOC_INSIDE )
|
||||
{
|
||||
Point2f org_pt, dst_pt;
|
||||
edgeOrg(edge, &org_pt);
|
||||
edgeDst(edge, &dst_pt);
|
||||
|
||||
|
||||
double t1 = fabs( pt.x - org_pt.x );
|
||||
t1 += fabs( pt.y - org_pt.y );
|
||||
double t2 = fabs( pt.x - dst_pt.x );
|
||||
t2 += fabs( pt.y - dst_pt.y );
|
||||
double t3 = fabs( org_pt.x - dst_pt.x );
|
||||
t3 += fabs( org_pt.y - dst_pt.y );
|
||||
|
||||
|
||||
if( t1 < FLT_EPSILON )
|
||||
{
|
||||
location = PTLOC_VERTEX;
|
||||
@@ -380,16 +380,16 @@ int Subdiv2D::locate(Point2f pt, int& _edge, int& _vertex)
|
||||
vertex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( location == PTLOC_ERROR )
|
||||
{
|
||||
edge = 0;
|
||||
vertex = 0;
|
||||
}
|
||||
|
||||
|
||||
_edge = edge;
|
||||
_vertex = vertex;
|
||||
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ isPtInCircle3( Point2f pt, Point2f a, Point2f b, Point2f c)
|
||||
val -= ((double)b.x * b.x + (double)b.y * b.y) * triangleArea( a, c, pt );
|
||||
val += ((double)c.x * c.x + (double)c.y * c.y) * triangleArea( a, b, pt );
|
||||
val -= ((double)pt.x * pt.x + (double)pt.y * pt.y) * triangleArea( a, b, c );
|
||||
|
||||
|
||||
return val > eps ? 1 : val < -eps ? -1 : 0;
|
||||
}
|
||||
|
||||
@@ -411,16 +411,16 @@ int Subdiv2D::insert(Point2f pt)
|
||||
{
|
||||
int curr_point = 0, curr_edge = 0, deleted_edge = 0;
|
||||
int location = locate( pt, curr_edge, curr_point );
|
||||
|
||||
|
||||
if( location == PTLOC_ERROR )
|
||||
CV_Error( CV_StsBadSize, "" );
|
||||
|
||||
|
||||
if( location == PTLOC_OUTSIDE_RECT )
|
||||
CV_Error( CV_StsOutOfRange, "" );
|
||||
|
||||
|
||||
if( location == PTLOC_VERTEX )
|
||||
return curr_point;
|
||||
|
||||
|
||||
if( location == PTLOC_ON_EDGE )
|
||||
{
|
||||
deleted_edge = curr_edge;
|
||||
@@ -431,36 +431,36 @@ int Subdiv2D::insert(Point2f pt)
|
||||
;
|
||||
else
|
||||
CV_Error_(CV_StsError, ("Subdiv2D::locate returned invalid location = %d", location) );
|
||||
|
||||
|
||||
assert( curr_edge != 0 );
|
||||
validGeometry = false;
|
||||
|
||||
|
||||
curr_point = newPoint(pt, false);
|
||||
int base_edge = newEdge();
|
||||
int first_point = edgeOrg(curr_edge);
|
||||
setEdgePoints(base_edge, first_point, curr_point);
|
||||
splice(base_edge, curr_edge);
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
base_edge = connectEdges( curr_edge, symEdge(base_edge) );
|
||||
curr_edge = getEdge(base_edge, PREV_AROUND_ORG);
|
||||
}
|
||||
while( edgeDst(curr_edge) != first_point );
|
||||
|
||||
|
||||
curr_edge = getEdge( base_edge, PREV_AROUND_ORG );
|
||||
|
||||
|
||||
int i, max_edges = (int)(qedges.size()*4);
|
||||
|
||||
|
||||
for( i = 0; i < max_edges; i++ )
|
||||
{
|
||||
int temp_dst = 0, curr_org = 0, curr_dst = 0;
|
||||
int temp_edge = getEdge( curr_edge, PREV_AROUND_ORG );
|
||||
|
||||
|
||||
temp_dst = edgeDst( temp_edge );
|
||||
curr_org = edgeOrg( curr_edge );
|
||||
curr_dst = edgeDst( curr_edge );
|
||||
|
||||
|
||||
if( isRightOf( vtx[temp_dst].pt, curr_edge ) > 0 &&
|
||||
isPtInCircle3( vtx[curr_org].pt, vtx[temp_dst].pt,
|
||||
vtx[curr_dst].pt, vtx[curr_point].pt ) < 0 )
|
||||
@@ -473,7 +473,7 @@ int Subdiv2D::insert(Point2f pt)
|
||||
else
|
||||
curr_edge = getEdge( nextEdge( curr_edge ), PREV_AROUND_LEFT );
|
||||
}
|
||||
|
||||
|
||||
return curr_point;
|
||||
}
|
||||
|
||||
@@ -488,42 +488,42 @@ void Subdiv2D::initDelaunay( Rect rect )
|
||||
float big_coord = 3.f * MAX( rect.width, rect.height );
|
||||
float rx = (float)rect.x;
|
||||
float ry = (float)rect.y;
|
||||
|
||||
|
||||
vtx.clear();
|
||||
qedges.clear();
|
||||
|
||||
|
||||
recentEdge = 0;
|
||||
validGeometry = false;
|
||||
|
||||
|
||||
topLeft = Point2f( rx, ry );
|
||||
bottomRight = Point2f( rx + rect.width, ry + rect.height );
|
||||
|
||||
|
||||
Point2f ppA( rx + big_coord, ry );
|
||||
Point2f ppB( rx, ry + big_coord );
|
||||
Point2f ppC( rx - big_coord, ry - big_coord );
|
||||
|
||||
|
||||
vtx.push_back(Vertex());
|
||||
qedges.push_back(QuadEdge());
|
||||
|
||||
|
||||
freeQEdge = 0;
|
||||
freePoint = 0;
|
||||
|
||||
|
||||
int pA = newPoint(ppA, false);
|
||||
int pB = newPoint(ppB, false);
|
||||
int pC = newPoint(ppC, false);
|
||||
|
||||
|
||||
int edge_AB = newEdge();
|
||||
int edge_BC = newEdge();
|
||||
int edge_CA = newEdge();
|
||||
|
||||
|
||||
setEdgePoints( edge_AB, pA, pB );
|
||||
setEdgePoints( edge_BC, pB, pC );
|
||||
setEdgePoints( edge_CA, pC, pA );
|
||||
|
||||
|
||||
splice( edge_AB, symEdge( edge_CA ));
|
||||
splice( edge_BC, symEdge( edge_AB ));
|
||||
splice( edge_CA, symEdge( edge_BC ));
|
||||
|
||||
|
||||
recentEdge = edge_AB;
|
||||
}
|
||||
|
||||
@@ -531,17 +531,17 @@ void Subdiv2D::initDelaunay( Rect rect )
|
||||
void Subdiv2D::clearVoronoi()
|
||||
{
|
||||
size_t i, total = qedges.size();
|
||||
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
qedges[i].pt[1] = qedges[i].pt[3] = 0;
|
||||
|
||||
|
||||
total = vtx.size();
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
if( vtx[i].isvirtual() )
|
||||
deletePoint((int)i);
|
||||
}
|
||||
|
||||
|
||||
validGeometry = false;
|
||||
}
|
||||
|
||||
@@ -551,20 +551,20 @@ static Point2f computeVoronoiPoint(Point2f org0, Point2f dst0, Point2f org1, Poi
|
||||
double a0 = dst0.x - org0.x;
|
||||
double b0 = dst0.y - org0.y;
|
||||
double c0 = -0.5*(a0 * (dst0.x + org0.x) + b0 * (dst0.y + org0.y));
|
||||
|
||||
|
||||
double a1 = dst1.x - org1.x;
|
||||
double b1 = dst1.y - org1.y;
|
||||
double c1 = -0.5*(a1 * (dst1.x + org1.x) + b1 * (dst1.y + org1.y));
|
||||
|
||||
|
||||
double det = a0 * b1 - a1 * b0;
|
||||
|
||||
|
||||
if( det != 0 )
|
||||
{
|
||||
det = 1. / det;
|
||||
return Point2f((float) ((b0 * c1 - b1 * c0) * det),
|
||||
(float) ((a1 * c0 - a0 * c1) * det));
|
||||
}
|
||||
|
||||
|
||||
return Point2f(FLT_MAX, FLT_MAX);
|
||||
}
|
||||
|
||||
@@ -574,33 +574,33 @@ void Subdiv2D::calcVoronoi()
|
||||
// check if it is already calculated
|
||||
if( validGeometry )
|
||||
return;
|
||||
|
||||
|
||||
clearVoronoi();
|
||||
int i, total = (int)qedges.size();
|
||||
|
||||
|
||||
// loop through all quad-edges, except for the first 3 (#1, #2, #3 - 0 is reserved for "NULL" pointer)
|
||||
for( i = 4; i < total; i++ )
|
||||
{
|
||||
QuadEdge& quadedge = qedges[i];
|
||||
|
||||
|
||||
if( quadedge.isfree() )
|
||||
continue;
|
||||
|
||||
|
||||
int edge0 = (int)(i*4);
|
||||
Point2f org0, dst0, org1, dst1;
|
||||
|
||||
|
||||
if( !quadedge.pt[3] )
|
||||
{
|
||||
int edge1 = getEdge( edge0, NEXT_AROUND_LEFT );
|
||||
int edge2 = getEdge( edge1, NEXT_AROUND_LEFT );
|
||||
|
||||
|
||||
edgeOrg(edge0, &org0);
|
||||
edgeDst(edge0, &dst0);
|
||||
edgeOrg(edge1, &org1);
|
||||
edgeDst(edge1, &dst1);
|
||||
|
||||
|
||||
Point2f virt_point = computeVoronoiPoint(org0, dst0, org1, dst1);
|
||||
|
||||
|
||||
if( fabs( virt_point.x ) < FLT_MAX * 0.5 &&
|
||||
fabs( virt_point.y ) < FLT_MAX * 0.5 )
|
||||
{
|
||||
@@ -608,28 +608,28 @@ void Subdiv2D::calcVoronoi()
|
||||
qedges[edge2 >> 2].pt[3 - (edge2 & 2)] = newPoint(virt_point, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !quadedge.pt[1] )
|
||||
{
|
||||
int edge1 = getEdge( edge0, NEXT_AROUND_RIGHT );
|
||||
int edge2 = getEdge( edge1, NEXT_AROUND_RIGHT );
|
||||
|
||||
|
||||
edgeOrg(edge0, &org0);
|
||||
edgeDst(edge0, &dst0);
|
||||
edgeOrg(edge1, &org1);
|
||||
edgeDst(edge1, &dst1);
|
||||
|
||||
|
||||
Point2f virt_point = computeVoronoiPoint(org0, dst0, org1, dst1);
|
||||
|
||||
|
||||
if( fabs( virt_point.x ) < FLT_MAX * 0.5 &&
|
||||
fabs( virt_point.y ) < FLT_MAX * 0.5 )
|
||||
{
|
||||
quadedge.pt[1] = qedges[edge1 >> 2].pt[1 + (edge1 & 2)] =
|
||||
quadedge.pt[1] = qedges[edge1 >> 2].pt[1 + (edge1 & 2)] =
|
||||
qedges[edge2 >> 2].pt[1 + (edge2 & 2)] = newPoint(virt_point, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
validGeometry = true;
|
||||
}
|
||||
|
||||
@@ -646,70 +646,70 @@ int Subdiv2D::findNearest(Point2f pt, Point2f* nearestPt)
|
||||
{
|
||||
if( !validGeometry )
|
||||
calcVoronoi();
|
||||
|
||||
|
||||
int vertex = 0, edge = 0;
|
||||
int loc = locate( pt, edge, vertex );
|
||||
|
||||
|
||||
if( loc != PTLOC_ON_EDGE && loc != PTLOC_INSIDE )
|
||||
return vertex;
|
||||
|
||||
|
||||
vertex = 0;
|
||||
|
||||
|
||||
Point2f start;
|
||||
edgeOrg(edge, &start);
|
||||
Point2f diff = pt - start;
|
||||
|
||||
|
||||
edge = rotateEdge(edge, 1);
|
||||
|
||||
|
||||
int i, total = (int)vtx.size();
|
||||
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
Point2f t;
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
CV_Assert( edgeDst(edge, &t) > 0 );
|
||||
if( isRightOf2( t, start, diff ) >= 0 )
|
||||
break;
|
||||
|
||||
|
||||
edge = getEdge( edge, NEXT_AROUND_LEFT );
|
||||
}
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
CV_Assert( edgeOrg( edge, &t ) > 0 );
|
||||
|
||||
|
||||
if( isRightOf2( t, start, diff ) < 0 )
|
||||
break;
|
||||
|
||||
|
||||
edge = getEdge( edge, PREV_AROUND_LEFT );
|
||||
}
|
||||
|
||||
|
||||
Point2f tempDiff;
|
||||
edgeDst(edge, &tempDiff);
|
||||
edgeOrg(edge, &t);
|
||||
tempDiff -= t;
|
||||
|
||||
|
||||
if( isRightOf2( pt, t, tempDiff ) >= 0 )
|
||||
{
|
||||
vertex = edgeOrg(rotateEdge( edge, 3 ));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
edge = symEdge( edge );
|
||||
}
|
||||
|
||||
|
||||
if( nearestPt && vertex > 0 )
|
||||
*nearestPt = vtx[vertex].pt;
|
||||
|
||||
|
||||
return vertex;
|
||||
}
|
||||
|
||||
void Subdiv2D::getEdgeList(vector<Vec4f>& edgeList) const
|
||||
{
|
||||
edgeList.clear();
|
||||
|
||||
|
||||
for( size_t i = 4; i < qedges.size(); i++ )
|
||||
{
|
||||
if( qedges[i].isfree() )
|
||||
@@ -728,7 +728,7 @@ void Subdiv2D::getTriangleList(vector<Vec6f>& triangleList) const
|
||||
triangleList.clear();
|
||||
int i, total = (int)(qedges.size()*4);
|
||||
vector<bool> edgemask(total, false);
|
||||
|
||||
|
||||
for( i = 4; i < total; i += 2 )
|
||||
{
|
||||
if( edgemask[i] )
|
||||
@@ -754,23 +754,23 @@ void Subdiv2D::getVoronoiFacetList(const vector<int>& idx,
|
||||
calcVoronoi();
|
||||
facetList.clear();
|
||||
facetCenters.clear();
|
||||
|
||||
|
||||
vector<Point2f> buf;
|
||||
|
||||
|
||||
size_t i, total;
|
||||
if( idx.empty() )
|
||||
i = 4, total = vtx.size();
|
||||
else
|
||||
i = 0, total = idx.size();
|
||||
|
||||
|
||||
for( ; i < total; i++ )
|
||||
{
|
||||
int k = idx.empty() ? (int)i : idx[i];
|
||||
|
||||
|
||||
if( vtx[k].isfree() || vtx[k].isvirtual() )
|
||||
continue;
|
||||
int edge = rotateEdge(vtx[k].firstEdge, 1), t = edge;
|
||||
|
||||
int edge = rotateEdge(vtx[k].firstEdge, 1), t = edge;
|
||||
|
||||
// gather points
|
||||
buf.clear();
|
||||
do
|
||||
@@ -779,7 +779,7 @@ void Subdiv2D::getVoronoiFacetList(const vector<int>& idx,
|
||||
t = getEdge( t, NEXT_AROUND_LEFT );
|
||||
}
|
||||
while( t != edge );
|
||||
|
||||
|
||||
facetList.push_back(buf);
|
||||
facetCenters.push_back(vtx[k].pt);
|
||||
}
|
||||
@@ -789,14 +789,14 @@ void Subdiv2D::getVoronoiFacetList(const vector<int>& idx,
|
||||
void Subdiv2D::checkSubdiv() const
|
||||
{
|
||||
int i, j, total = (int)qedges.size();
|
||||
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
const QuadEdge& qe = qedges[i];
|
||||
|
||||
|
||||
if( qe.isfree() )
|
||||
continue;
|
||||
|
||||
|
||||
for( j = 0; j < 4; j++ )
|
||||
{
|
||||
int e = (int)(i*4 + j);
|
||||
@@ -804,13 +804,13 @@ void Subdiv2D::checkSubdiv() const
|
||||
int o_prev = getEdge(e, PREV_AROUND_ORG );
|
||||
int d_prev = getEdge(e, PREV_AROUND_DST );
|
||||
int d_next = getEdge(e, NEXT_AROUND_DST );
|
||||
|
||||
|
||||
// check points
|
||||
CV_Assert( edgeOrg(e) == edgeOrg(o_next));
|
||||
CV_Assert( edgeOrg(e) == edgeOrg(o_prev));
|
||||
CV_Assert( edgeDst(e) == edgeDst(d_next));
|
||||
CV_Assert( edgeDst(e) == edgeDst(d_prev));
|
||||
|
||||
|
||||
if( j % 2 == 0 )
|
||||
{
|
||||
CV_Assert( edgeDst(o_next) == edgeOrg(d_prev));
|
||||
@@ -820,8 +820,8 @@ void Subdiv2D::checkSubdiv() const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
@@ -158,7 +158,7 @@ const float icv8x32fSqrTab[] =
|
||||
61504.f, 62001.f, 62500.f, 63001.f, 63504.f, 64009.f, 64516.f, 65025.f
|
||||
};
|
||||
|
||||
const uchar icvSaturate8u_cv[] =
|
||||
const uchar icvSaturate8u_cv[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
@@ -56,26 +56,26 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
int depth = img.depth(), cn = img.channels();
|
||||
int tdepth = templ.depth(), tcn = templ.channels();
|
||||
int cdepth = CV_MAT_DEPTH(ctype), ccn = CV_MAT_CN(ctype);
|
||||
|
||||
|
||||
CV_Assert( img.dims <= 2 && templ.dims <= 2 && corr.dims <= 2 );
|
||||
|
||||
|
||||
if( depth != tdepth && tdepth != std::max(CV_32F, depth) )
|
||||
{
|
||||
_templ.convertTo(templ, std::max(CV_32F, depth));
|
||||
tdepth = templ.depth();
|
||||
}
|
||||
|
||||
|
||||
CV_Assert( depth == tdepth || tdepth == CV_32F);
|
||||
CV_Assert( corrsize.height <= img.rows + templ.rows - 1 &&
|
||||
corrsize.width <= img.cols + templ.cols - 1 );
|
||||
|
||||
|
||||
CV_Assert( ccn == 1 || delta == 0 );
|
||||
|
||||
|
||||
corr.create(corrsize, ctype);
|
||||
|
||||
int maxDepth = depth > CV_8S ? CV_64F : std::max(std::max(CV_32F, tdepth), cdepth);
|
||||
Size blocksize, dftsize;
|
||||
|
||||
|
||||
blocksize.width = cvRound(templ.cols*blockScale);
|
||||
blocksize.width = std::max( blocksize.width, minBlockSize - templ.cols + 1 );
|
||||
blocksize.width = std::min( blocksize.width, corr.cols );
|
||||
@@ -109,7 +109,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
bufSize = std::max( bufSize, blocksize.width*blocksize.height*CV_ELEM_SIZE(cdepth));
|
||||
|
||||
buf.resize(bufSize);
|
||||
|
||||
|
||||
// compute DFT of each template plane
|
||||
for( k = 0; k < tcn; k++ )
|
||||
{
|
||||
@@ -139,11 +139,11 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
int tileCountX = (corr.cols + blocksize.width - 1)/blocksize.width;
|
||||
int tileCountY = (corr.rows + blocksize.height - 1)/blocksize.height;
|
||||
int tileCount = tileCountX * tileCountY;
|
||||
|
||||
|
||||
Size wholeSize = img.size();
|
||||
Point roiofs(0,0);
|
||||
Mat img0 = img;
|
||||
|
||||
|
||||
if( !(borderType & BORDER_ISOLATED) )
|
||||
{
|
||||
img.locateROI(wholeSize, roiofs);
|
||||
@@ -151,13 +151,13 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
roiofs.x, wholeSize.width-img.cols-roiofs.x);
|
||||
}
|
||||
borderType |= BORDER_ISOLATED;
|
||||
|
||||
|
||||
// calculate correlation by blocks
|
||||
for( i = 0; i < tileCount; i++ )
|
||||
{
|
||||
int x = (i%tileCountX)*blocksize.width;
|
||||
int y = (i/tileCountX)*blocksize.height;
|
||||
|
||||
|
||||
Size bsz(std::min(blocksize.width, corr.cols - x),
|
||||
std::min(blocksize.height, corr.rows - y));
|
||||
Size dsz(bsz.width + templ.cols - 1, bsz.height + templ.rows - 1);
|
||||
@@ -169,12 +169,12 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
Mat dst(dftImg, Rect(0, 0, dsz.width, dsz.height));
|
||||
Mat dst1(dftImg, Rect(x1-x0, y1-y0, x2-x1, y2-y1));
|
||||
Mat cdst(corr, Rect(x, y, bsz.width, bsz.height));
|
||||
|
||||
|
||||
for( k = 0; k < cn; k++ )
|
||||
{
|
||||
Mat src = src0;
|
||||
dftImg = Scalar::all(0);
|
||||
|
||||
|
||||
if( cn > 1 )
|
||||
{
|
||||
src = depth == maxDepth ? dst1 : Mat(y2-y1, x2-x1, depth, &buf[0]);
|
||||
@@ -206,7 +206,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
src = plane;
|
||||
}
|
||||
int pairs[] = {0, k};
|
||||
mixChannels(&src, 1, &cdst, 1, pairs, 1);
|
||||
mixChannels(&src, 1, &cdst, 1, pairs, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -234,7 +234,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr,
|
||||
void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, int method )
|
||||
{
|
||||
CV_Assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED );
|
||||
|
||||
|
||||
int numType = method == CV_TM_CCORR || method == CV_TM_CCORR_NORMED ? 0 :
|
||||
method == CV_TM_CCOEFF || method == CV_TM_CCOEFF_NORMED ? 1 : 2;
|
||||
bool isNormed = method == CV_TM_CCORR_NORMED ||
|
||||
@@ -244,14 +244,14 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
Mat img = _img.getMat(), templ = _templ.getMat();
|
||||
if( img.rows < templ.rows || img.cols < templ.cols )
|
||||
std::swap(img, templ);
|
||||
|
||||
|
||||
CV_Assert( (img.depth() == CV_8U || img.depth() == CV_32F) &&
|
||||
img.type() == templ.type() );
|
||||
|
||||
Size corrSize(img.cols - templ.cols + 1, img.rows - templ.rows + 1);
|
||||
_result.create(corrSize, CV_32F);
|
||||
Mat result = _result.getMat();
|
||||
|
||||
|
||||
int cn = img.channels();
|
||||
crossCorr( img, templ, result, result.size(), result.type(), Point(0,0), 0, 0);
|
||||
|
||||
@@ -264,7 +264,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
Scalar templMean, templSdv;
|
||||
double *q0 = 0, *q1 = 0, *q2 = 0, *q3 = 0;
|
||||
double templNorm = 0, templSum2 = 0;
|
||||
|
||||
|
||||
if( method == CV_TM_CCOEFF )
|
||||
{
|
||||
integral(img, sum, CV_64F);
|
||||
@@ -283,7 +283,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
result = Scalar::all(1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
templSum2 = templNorm +
|
||||
CV_SQR(templMean[0]) + CV_SQR(templMean[1]) +
|
||||
CV_SQR(templMean[2]) + CV_SQR(templMean[3]);
|
||||
@@ -293,7 +293,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
templMean = Scalar::all(0);
|
||||
templNorm = templSum2;
|
||||
}
|
||||
|
||||
|
||||
templSum2 /= invArea;
|
||||
templNorm = sqrt(templNorm);
|
||||
templNorm /= sqrt(invArea); // care of accuracy here
|
||||
@@ -313,7 +313,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
int sqstep = sqsum.data ? (int)(sqsum.step / sizeof(double)) : 0;
|
||||
|
||||
int i, j, k;
|
||||
|
||||
|
||||
for( i = 0; i < result.rows; i++ )
|
||||
{
|
||||
float* rrow = (float*)(result.data + i*result.step);
|
||||
@@ -324,7 +324,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result,
|
||||
{
|
||||
double num = rrow[j], t;
|
||||
double wndMean2 = 0, wndSum2 = 0;
|
||||
|
||||
|
||||
if( numType == 1 )
|
||||
{
|
||||
for( k = 0; k < cn; k++ )
|
||||
|
||||
@@ -781,7 +781,7 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
|
||||
;
|
||||
else
|
||||
CV_Error( CV_StsUnsupportedFormat, "" );
|
||||
|
||||
|
||||
parallel_for_(Range(0, dst.rows),
|
||||
ThresholdRunner(src, dst, thresh, maxval, type),
|
||||
dst.total()/(double)(1<<16));
|
||||
|
||||
@@ -48,9 +48,9 @@ CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr,
|
||||
|
||||
int eltype;
|
||||
CvMat* mat = (CvMat*)arr;
|
||||
|
||||
|
||||
if( !CV_IS_MAT( mat ))
|
||||
CV_Error( CV_StsBadArg, "Input array is not a valid matrix" );
|
||||
CV_Error( CV_StsBadArg, "Input array is not a valid matrix" );
|
||||
|
||||
eltype = CV_MAT_TYPE( mat->type );
|
||||
if( eltype != CV_32SC2 && eltype != CV_32FC2 )
|
||||
@@ -93,14 +93,14 @@ static void copyMakeBorder_8u( const uchar* src, size_t srcstep, Size srcroi,
|
||||
int* tab = _tab;
|
||||
int right = dstroi.width - srcroi.width - left;
|
||||
int bottom = dstroi.height - srcroi.height - top;
|
||||
|
||||
|
||||
for( i = 0; i < left; i++ )
|
||||
{
|
||||
j = borderInterpolate(i - left, srcroi.width, borderType)*cn;
|
||||
for( k = 0; k < cn; k++ )
|
||||
tab[i*cn + k] = j + k;
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < right; i++ )
|
||||
{
|
||||
j = borderInterpolate(srcroi.width + i, srcroi.width, borderType)*cn;
|
||||
@@ -112,14 +112,14 @@ static void copyMakeBorder_8u( const uchar* src, size_t srcstep, Size srcroi,
|
||||
dstroi.width *= cn;
|
||||
left *= cn;
|
||||
right *= cn;
|
||||
|
||||
|
||||
uchar* dstInner = dst + dststep*top + left*elemSize;
|
||||
|
||||
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep )
|
||||
{
|
||||
if( dstInner != src )
|
||||
memcpy(dstInner, src, srcroi.width*elemSize);
|
||||
|
||||
|
||||
if( intMode )
|
||||
{
|
||||
const int* isrc = (int*)src;
|
||||
@@ -137,16 +137,16 @@ static void copyMakeBorder_8u( const uchar* src, size_t srcstep, Size srcroi,
|
||||
dstInner[j + srcroi.width] = src[tab[j + left]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dstroi.width *= elemSize;
|
||||
dst += dststep*top;
|
||||
|
||||
|
||||
for( i = 0; i < top; i++ )
|
||||
{
|
||||
j = borderInterpolate(i - top, srcroi.height, borderType);
|
||||
memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width);
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < bottom; i++ )
|
||||
{
|
||||
j = borderInterpolate(i + srcroi.height, srcroi.height, borderType);
|
||||
@@ -164,20 +164,20 @@ static void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, Size srcro
|
||||
uchar* constBuf = _constBuf;
|
||||
int right = dstroi.width - srcroi.width - left;
|
||||
int bottom = dstroi.height - srcroi.height - top;
|
||||
|
||||
|
||||
for( i = 0; i < dstroi.width; i++ )
|
||||
{
|
||||
for( j = 0; j < cn; j++ )
|
||||
constBuf[i*cn + j] = value[j];
|
||||
}
|
||||
|
||||
|
||||
srcroi.width *= cn;
|
||||
dstroi.width *= cn;
|
||||
left *= cn;
|
||||
right *= cn;
|
||||
|
||||
|
||||
uchar* dstInner = dst + dststep*top + left;
|
||||
|
||||
|
||||
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep )
|
||||
{
|
||||
if( dstInner != src )
|
||||
@@ -185,24 +185,24 @@ static void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, Size srcro
|
||||
memcpy( dstInner - left, constBuf, left );
|
||||
memcpy( dstInner + srcroi.width, constBuf, right );
|
||||
}
|
||||
|
||||
|
||||
dst += dststep*top;
|
||||
|
||||
|
||||
for( i = 0; i < top; i++ )
|
||||
memcpy(dst + (i - top)*dststep, constBuf, dstroi.width);
|
||||
|
||||
|
||||
for( i = 0; i < bottom; i++ )
|
||||
memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
||||
int left, int right, int borderType, const Scalar& value )
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 );
|
||||
|
||||
|
||||
if( src.isSubmatrix() && (borderType & BORDER_ISOLATED) == 0 )
|
||||
{
|
||||
Size wholeSize;
|
||||
@@ -228,9 +228,9 @@ void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
|
||||
src.copyTo(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
borderType &= ~BORDER_ISOLATED;
|
||||
|
||||
|
||||
if( borderType != BORDER_CONSTANT )
|
||||
copyMakeBorder_8u( src.data, src.step, src.size(),
|
||||
dst.data, dst.step, dst.size(),
|
||||
@@ -268,7 +268,7 @@ cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
|
||||
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
|
||||
int left = offset.x, right = dst.cols - src.cols - left;
|
||||
int top = offset.y, bottom = dst.rows - src.rows - top;
|
||||
|
||||
|
||||
CV_Assert( dst.type() == src.type() );
|
||||
cv::copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
|
||||
}
|
||||
|
||||
@@ -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