mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #22754 from mshabunin:c-cleanup
C-API cleanup for OpenCV 5.x (imgproc, highgui) * imgproc: C-API cleanup * imgproc: increase cvtColor test diff threshold * imgproc: C-API cleanup pt.2 * imgproc: C-API cleanup pt.3 * imgproc: C-API cleanup pt.4 * imgproc: C-API cleanup pt.5 * imgproc: C-API cleanup pt.5 * imgproc: C-API cleanup pt.6 * highgui: C-API cleanup * highgui: C-API cleanup pt.2 * highgui: C-API cleanup pt.3 * highgui: C-API cleanup pt.3 * imgproc: C-API cleanup pt.7 * fixup! highgui: C-API cleanup pt.3 * fixup! imgproc: C-API cleanup pt.6 * imgproc: C-API cleanup pt.8 * imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9 * fixup! imgproc: C-API cleanup pt.9
This commit is contained in:
@@ -174,15 +174,12 @@ protected:
|
||||
int dims;
|
||||
bool enable_flt_points;
|
||||
|
||||
CvMemStorage* storage;
|
||||
CvSeq* points1;
|
||||
CvMat* points2;
|
||||
void* points;
|
||||
void* result;
|
||||
double low_high_range;
|
||||
Scalar low, high;
|
||||
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
@@ -191,7 +188,6 @@ CV_BaseShapeDescrTest::CV_BaseShapeDescrTest()
|
||||
points1 = 0;
|
||||
points2 = 0;
|
||||
points = 0;
|
||||
storage = 0;
|
||||
test_case_count = 500;
|
||||
min_log_size = 0;
|
||||
max_log_size = 10;
|
||||
@@ -199,8 +195,6 @@ CV_BaseShapeDescrTest::CV_BaseShapeDescrTest()
|
||||
low_high_range = 50;
|
||||
dims = 2;
|
||||
enable_flt_points = true;
|
||||
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +207,6 @@ CV_BaseShapeDescrTest::~CV_BaseShapeDescrTest()
|
||||
void CV_BaseShapeDescrTest::clear()
|
||||
{
|
||||
cvtest::BaseTest::clear();
|
||||
cvReleaseMemStorage( &storage );
|
||||
cvReleaseMat( &points2 );
|
||||
points1 = 0;
|
||||
points = 0;
|
||||
@@ -306,7 +299,6 @@ void CV_BaseShapeDescrTest::generate_point_set( void* pointsSet )
|
||||
int CV_BaseShapeDescrTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int size;
|
||||
int use_storage = 0;
|
||||
int point_type;
|
||||
int i;
|
||||
RNG& rng = ts->get_rng();
|
||||
@@ -315,26 +307,15 @@ int CV_BaseShapeDescrTest::prepare_test_case( int test_case_idx )
|
||||
|
||||
clear();
|
||||
size = cvRound( exp((cvtest::randReal(rng) * (max_log_size - min_log_size) + min_log_size)*CV_LOG2) );
|
||||
use_storage = cvtest::randInt(rng) % 2;
|
||||
point_type = CV_MAKETYPE(cvtest::randInt(rng) %
|
||||
(enable_flt_points ? 2 : 1) ? CV_32F : CV_32S, dims);
|
||||
|
||||
if( use_storage )
|
||||
{
|
||||
storage = cvCreateMemStorage( (cvtest::randInt(rng)%10 + 1)*1024 );
|
||||
points1 = cvCreateSeq( point_type, sizeof(CvSeq), CV_ELEM_SIZE(point_type), storage );
|
||||
cvSeqPushMulti( points1, 0, size );
|
||||
points = points1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int rows = 1, cols = size;
|
||||
if( cvtest::randInt(rng) % 2 )
|
||||
rows = size, cols = 1;
|
||||
int rows = 1, cols = size;
|
||||
if( cvtest::randInt(rng) % 2 )
|
||||
rows = size, cols = 1;
|
||||
|
||||
points2 = cvCreateMat( rows, cols, point_type );
|
||||
points = points2;
|
||||
}
|
||||
points2 = cvCreateMat( rows, cols, point_type );
|
||||
points = points2;
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
@@ -350,8 +331,6 @@ int CV_BaseShapeDescrTest::prepare_test_case( int test_case_idx )
|
||||
}
|
||||
|
||||
generate_point_set( points );
|
||||
|
||||
test_cpp = (cvtest::randInt(rng) & 16) == 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -403,8 +382,7 @@ protected:
|
||||
|
||||
CvSeq* hull1;
|
||||
CvMat* hull2;
|
||||
void* hull_storage;
|
||||
int orientation;
|
||||
bool clockwise;
|
||||
int return_points;
|
||||
};
|
||||
|
||||
@@ -413,8 +391,8 @@ CV_ConvHullTest::CV_ConvHullTest()
|
||||
{
|
||||
hull1 = 0;
|
||||
hull2 = 0;
|
||||
hull_storage = 0;
|
||||
orientation = return_points = 0;
|
||||
return_points = 0;
|
||||
clockwise = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,43 +407,30 @@ void CV_ConvHullTest::clear()
|
||||
CV_BaseShapeDescrTest::clear();
|
||||
cvReleaseMat( &hull2 );
|
||||
hull1 = 0;
|
||||
hull_storage = 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_ConvHullTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CV_BaseShapeDescrTest::prepare_test_case( test_case_idx );
|
||||
int use_storage_for_hull = 0;
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
if( code <= 0 )
|
||||
return code;
|
||||
|
||||
orientation = cvtest::randInt(rng) % 2 ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE;
|
||||
clockwise = cvtest::randInt(rng) % 2 != 0;
|
||||
return_points = cvtest::randInt(rng) % 2;
|
||||
|
||||
use_storage_for_hull = (cvtest::randInt(rng) % 2) && !test_cpp;
|
||||
if( use_storage_for_hull )
|
||||
{
|
||||
if( !storage )
|
||||
storage = cvCreateMemStorage( (cvtest::randInt(rng)%10 + 1)*1024 );
|
||||
hull_storage = storage;
|
||||
}
|
||||
int rows, cols;
|
||||
int sz = points1 ? points1->total : points2->cols + points2->rows - 1;
|
||||
int point_type = points1 ? CV_SEQ_ELTYPE(points1) : CV_MAT_TYPE(points2->type);
|
||||
|
||||
if( cvtest::randInt(rng) % 2 )
|
||||
rows = sz, cols = 1;
|
||||
else
|
||||
{
|
||||
int rows, cols;
|
||||
int sz = points1 ? points1->total : points2->cols + points2->rows - 1;
|
||||
int point_type = points1 ? CV_SEQ_ELTYPE(points1) : CV_MAT_TYPE(points2->type);
|
||||
rows = 1, cols = sz;
|
||||
|
||||
if( cvtest::randInt(rng) % 2 )
|
||||
rows = sz, cols = 1;
|
||||
else
|
||||
rows = 1, cols = sz;
|
||||
|
||||
hull2 = cvCreateMat( rows, cols, return_points ? point_type : CV_32SC1 );
|
||||
hull_storage = hull2;
|
||||
}
|
||||
hull2 = cvCreateMat( rows, cols, return_points ? point_type : CV_32SC1 );
|
||||
|
||||
return code;
|
||||
}
|
||||
@@ -473,39 +438,33 @@ int CV_ConvHullTest::prepare_test_case( int test_case_idx )
|
||||
|
||||
void CV_ConvHullTest::run_func()
|
||||
{
|
||||
if(!test_cpp)
|
||||
hull1 = cvConvexHull2( points, hull_storage, orientation, return_points );
|
||||
else
|
||||
cv::Mat _points = cv::cvarrToMat(points);
|
||||
size_t n = 0;
|
||||
if( !return_points )
|
||||
{
|
||||
cv::Mat _points = cv::cvarrToMat(points);
|
||||
bool clockwise = orientation == CV_CLOCKWISE;
|
||||
size_t n = 0;
|
||||
if( !return_points )
|
||||
{
|
||||
std::vector<int> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
else if(_points.type() == CV_32SC2)
|
||||
{
|
||||
std::vector<cv::Point> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
else if(_points.type() == CV_32FC2)
|
||||
{
|
||||
std::vector<cv::Point2f> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
if(hull2->rows > hull2->cols)
|
||||
hull2->rows = (int)n;
|
||||
else
|
||||
hull2->cols = (int)n;
|
||||
std::vector<int> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
else if(_points.type() == CV_32SC2)
|
||||
{
|
||||
std::vector<cv::Point> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
else if(_points.type() == CV_32FC2)
|
||||
{
|
||||
std::vector<cv::Point2f> _hull;
|
||||
cv::convexHull(_points, _hull, clockwise);
|
||||
n = _hull.size();
|
||||
memcpy(hull2->data.ptr, &_hull[0], n*sizeof(_hull[0]));
|
||||
}
|
||||
if(hull2->rows > hull2->cols)
|
||||
hull2->rows = (int)n;
|
||||
else
|
||||
hull2->cols = (int)n;
|
||||
}
|
||||
|
||||
|
||||
@@ -589,7 +548,7 @@ int CV_ConvHullTest::validate_test_results( int test_case_idx )
|
||||
float dx0 = pt1.x - pt0.x, dy0 = pt1.y - pt0.y;
|
||||
float dx1 = pt2.x - pt1.x, dy1 = pt2.y - pt1.y;
|
||||
double t = (double)dx0*dy1 - (double)dx1*dy0;
|
||||
if( (t < 0) ^ (orientation != CV_COUNTER_CLOCKWISE) )
|
||||
if( (t < 0) ^ clockwise )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "The convex hull is not convex or has a wrong orientation (vtx %d)\n", i );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
@@ -1056,115 +1015,6 @@ TEST(Imgproc_minEnclosingCircle, regression_16051) {
|
||||
EXPECT_NEAR(2.1024551f, radius, 1e-3);
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* Perimeter Test *
|
||||
\****************************************************************************************/
|
||||
|
||||
class CV_PerimeterTest : public CV_BaseShapeDescrTest
|
||||
{
|
||||
public:
|
||||
CV_PerimeterTest();
|
||||
|
||||
protected:
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void run_func(void);
|
||||
int validate_test_results( int test_case_idx );
|
||||
CvSlice slice;
|
||||
int is_closed;
|
||||
double result;
|
||||
};
|
||||
|
||||
|
||||
CV_PerimeterTest::CV_PerimeterTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CV_PerimeterTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = CV_BaseShapeDescrTest::prepare_test_case( test_case_idx );
|
||||
RNG& rng = ts->get_rng();
|
||||
int total;
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
is_closed = cvtest::randInt(rng) % 2;
|
||||
|
||||
if( points1 )
|
||||
{
|
||||
points1->flags |= CV_SEQ_KIND_CURVE;
|
||||
if( is_closed )
|
||||
points1->flags |= CV_SEQ_FLAG_CLOSED;
|
||||
total = points1->total;
|
||||
}
|
||||
else
|
||||
total = points2->cols + points2->rows - 1;
|
||||
|
||||
if( (cvtest::randInt(rng) % 3) && !test_cpp )
|
||||
{
|
||||
slice.start_index = cvtest::randInt(rng) % total;
|
||||
slice.end_index = cvtest::randInt(rng) % total;
|
||||
}
|
||||
else
|
||||
slice = CV_WHOLE_SEQ;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_PerimeterTest::run_func()
|
||||
{
|
||||
if(!test_cpp)
|
||||
result = cvArcLength( points, slice, points1 ? -1 : is_closed );
|
||||
else
|
||||
result = cv::arcLength(cv::cvarrToMat(points),
|
||||
!points1 ? is_closed != 0 : (points1->flags & CV_SEQ_FLAG_CLOSED) != 0);
|
||||
}
|
||||
|
||||
|
||||
int CV_PerimeterTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
int code = CV_BaseShapeDescrTest::validate_test_results( test_case_idx );
|
||||
int i, len = slice.end_index - slice.start_index, total = points2->cols + points2->rows - 1;
|
||||
double result0 = 0;
|
||||
Point2f prev_pt, pt;
|
||||
CvPoint2D32f *ptr;
|
||||
|
||||
if( len < 0 )
|
||||
len += total;
|
||||
|
||||
len = MIN( len, total );
|
||||
//len -= !is_closed && len == total;
|
||||
|
||||
ptr = (CvPoint2D32f*)points2->data.fl;
|
||||
prev_pt = ptr[(is_closed ? slice.start_index+len-1 : slice.start_index) % total];
|
||||
|
||||
for( i = 0; i < len + (len < total && (!is_closed || len==1)); i++ )
|
||||
{
|
||||
pt = ptr[(i + slice.start_index) % total];
|
||||
double dx = pt.x - prev_pt.x, dy = pt.y - prev_pt.y;
|
||||
result0 += sqrt(dx*dx + dy*dy);
|
||||
prev_pt = pt;
|
||||
}
|
||||
|
||||
if( cvIsNaN(result) || cvIsInf(result) )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "cvArcLength() returned invalid value (%g)\n", result );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
}
|
||||
else if( fabs(result - result0) > FLT_EPSILON*100*result0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "The function returned %g, while the correct result is %g\n", result, result0 );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* FitEllipse Test *
|
||||
\****************************************************************************************/
|
||||
@@ -1530,7 +1380,7 @@ int CV_FitLineTest::prepare_test_case( int test_case_idx )
|
||||
max_log_size = MAX(min_log_size,max_log_size);
|
||||
int code = CV_BaseShapeDescrTest::prepare_test_case( test_case_idx );
|
||||
dist_type = cvtest::randInt(rng) % 6 + 1;
|
||||
dist_type += dist_type == CV_DIST_C;
|
||||
dist_type += dist_type == cv::DIST_C;
|
||||
reps = 0.1; aeps = 0.01;
|
||||
return code;
|
||||
}
|
||||
@@ -1624,290 +1474,15 @@ _exit_:
|
||||
return code;
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* ContourMoments Test *
|
||||
\****************************************************************************************/
|
||||
|
||||
|
||||
static void
|
||||
cvTsGenerateTousledBlob( CvPoint2D32f center, CvSize2D32f axes,
|
||||
double max_r_scale, double angle, CvArr* points, RNG& rng )
|
||||
{
|
||||
int i, total, point_type;
|
||||
uchar* data = 0;
|
||||
CvSeqReader reader;
|
||||
memset( &reader, 0, sizeof(reader) );
|
||||
|
||||
if( CV_IS_SEQ(points) )
|
||||
{
|
||||
CvSeq* ptseq = (CvSeq*)points;
|
||||
total = ptseq->total;
|
||||
point_type = CV_SEQ_ELTYPE(ptseq);
|
||||
cvStartReadSeq( ptseq, &reader );
|
||||
}
|
||||
else
|
||||
{
|
||||
CvMat* ptm = (CvMat*)points;
|
||||
CV_Assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) );
|
||||
total = ptm->rows + ptm->cols - 1;
|
||||
point_type = CV_MAT_TYPE(ptm->type);
|
||||
data = ptm->data.ptr;
|
||||
}
|
||||
|
||||
CV_Assert( point_type == CV_32SC2 || point_type == CV_32FC2 );
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
CvPoint* pp;
|
||||
Point2f p;
|
||||
|
||||
double phi0 = 2*CV_PI*i/total;
|
||||
double phi = CV_PI*angle/180.;
|
||||
double t = cvtest::randReal(rng)*max_r_scale + (1 - max_r_scale);
|
||||
double ta = axes.height*t;
|
||||
double tb = axes.width*t;
|
||||
double c0 = cos(phi0)*ta, s0 = sin(phi0)*tb;
|
||||
double c = cos(phi), s = sin(phi);
|
||||
p.x = (float)(c0*c - s0*s + center.x);
|
||||
p.y = (float)(c0*s + s0*c + center.y);
|
||||
|
||||
if( reader.ptr )
|
||||
{
|
||||
pp = (CvPoint*)reader.ptr;
|
||||
CV_NEXT_SEQ_ELEM( sizeof(*pp), reader );
|
||||
}
|
||||
else
|
||||
pp = ((CvPoint*)data) + i;
|
||||
|
||||
if( point_type == CV_32SC2 )
|
||||
{
|
||||
pp->x = cvRound(p.x);
|
||||
pp->y = cvRound(p.y);
|
||||
}
|
||||
else
|
||||
*(CvPoint2D32f*)pp = cvPoint2D32f(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CV_ContourMomentsTest : public CV_BaseShapeDescrTest
|
||||
{
|
||||
public:
|
||||
CV_ContourMomentsTest();
|
||||
|
||||
protected:
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void generate_point_set( void* points );
|
||||
void run_func(void);
|
||||
int validate_test_results( int test_case_idx );
|
||||
CvMoments moments0, moments;
|
||||
double area0, area;
|
||||
Size2f axes;
|
||||
Point2f center;
|
||||
int max_max_r_scale;
|
||||
double max_r_scale, angle;
|
||||
Size img_size;
|
||||
};
|
||||
|
||||
|
||||
CV_ContourMomentsTest::CV_ContourMomentsTest()
|
||||
{
|
||||
min_log_size = 3;
|
||||
max_log_size = 8;
|
||||
max_max_r_scale = 15;
|
||||
low_high_range = 200;
|
||||
enable_flt_points = false;
|
||||
}
|
||||
|
||||
|
||||
void CV_ContourMomentsTest::generate_point_set( void* pointsSet )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
float max_sz;
|
||||
|
||||
axes.width = (float)((cvtest::randReal(rng)*0.9 + 0.1)*low_high_range);
|
||||
axes.height = (float)((cvtest::randReal(rng)*0.9 + 0.1)*low_high_range);
|
||||
max_sz = MAX(axes.width, axes.height);
|
||||
|
||||
img_size.width = img_size.height = cvRound(low_high_range*2.2);
|
||||
|
||||
center.x = (float)(img_size.width*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.width - max_sz*2)*0.8);
|
||||
center.y = (float)(img_size.height*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.height - max_sz*2)*0.8);
|
||||
|
||||
CV_Assert( 0 < center.x - max_sz && center.x + max_sz < img_size.width &&
|
||||
0 < center.y - max_sz && center.y + max_sz < img_size.height );
|
||||
|
||||
max_r_scale = cvtest::randReal(rng)*max_max_r_scale*0.01;
|
||||
angle = cvtest::randReal(rng)*360;
|
||||
|
||||
cvTsGenerateTousledBlob( cvPoint2D32f(center), cvSize2D32f(axes), max_r_scale, angle, pointsSet, rng );
|
||||
|
||||
if( points1 )
|
||||
points1->flags = CV_SEQ_MAGIC_VAL + CV_SEQ_POLYGON;
|
||||
}
|
||||
|
||||
|
||||
int CV_ContourMomentsTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
min_log_size = MAX(min_log_size,3);
|
||||
max_log_size = MIN(max_log_size,8);
|
||||
max_log_size = MAX(min_log_size,max_log_size);
|
||||
int code = CV_BaseShapeDescrTest::prepare_test_case( test_case_idx );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_ContourMomentsTest::run_func()
|
||||
{
|
||||
moments = cvMoments(cv::moments(cv::cvarrToMat(points)));
|
||||
area = cv::contourArea(cv::cvarrToMat(points));
|
||||
}
|
||||
|
||||
|
||||
int CV_ContourMomentsTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
int code = CV_BaseShapeDescrTest::validate_test_results( test_case_idx );
|
||||
int i, n = (int)(sizeof(moments)/sizeof(moments.inv_sqrt_m00));
|
||||
CvMat* img = cvCreateMat( img_size.height, img_size.width, CV_8UC1 );
|
||||
CvPoint* pt = (CvPoint*)points2->data.i;
|
||||
int count = points2->cols + points2->rows - 1;
|
||||
double max_v0 = 0;
|
||||
|
||||
cvZero(img);
|
||||
cvFillPoly( img, &pt, &count, 1, cvScalarAll(1));
|
||||
cvMoments( img, &moments0 );
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
double t = fabs((&moments0.m00)[i]);
|
||||
max_v0 = MAX(max_v0, t);
|
||||
}
|
||||
|
||||
for( i = 0; i <= n; i++ )
|
||||
{
|
||||
double v = i < n ? (&moments.m00)[i] : area;
|
||||
double v0 = i < n ? (&moments0.m00)[i] : moments0.m00;
|
||||
|
||||
if( cvIsNaN(v) || cvIsInf(v) )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The contour %s is invalid (=%g)\n", i < n ? "moment" : "area", v );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
break;
|
||||
}
|
||||
|
||||
if( fabs(v - v0) > 0.1*max_v0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The computed contour %s is %g, while it should be %g\n",
|
||||
i < n ? "moment" : "area", v, v0 );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
{
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
cvReleaseMat( &img );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////// Perimeter/Area/Slice test ///////////////////////////////////
|
||||
|
||||
class CV_PerimeterAreaSliceTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_PerimeterAreaSliceTest();
|
||||
~CV_PerimeterAreaSliceTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_PerimeterAreaSliceTest::CV_PerimeterAreaSliceTest()
|
||||
{
|
||||
}
|
||||
CV_PerimeterAreaSliceTest::~CV_PerimeterAreaSliceTest() {}
|
||||
|
||||
void CV_PerimeterAreaSliceTest::run( int )
|
||||
{
|
||||
Ptr<CvMemStorage> storage(cvCreateMemStorage());
|
||||
RNG& rng = theRNG();
|
||||
const double min_r = 90, max_r = 120;
|
||||
|
||||
for( int i = 0; i < 100; i++ )
|
||||
{
|
||||
ts->update_context( this, i, true );
|
||||
int n = rng.uniform(3, 30);
|
||||
cvClearMemStorage(storage);
|
||||
CvSeq* contour = cvCreateSeq(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(CvPoint), storage);
|
||||
double dphi = CV_PI*2/n;
|
||||
Point center;
|
||||
center.x = rng.uniform(cvCeil(max_r), cvFloor(640-max_r));
|
||||
center.y = rng.uniform(cvCeil(max_r), cvFloor(480-max_r));
|
||||
|
||||
for( int j = 0; j < n; j++ )
|
||||
{
|
||||
CvPoint pt = CV_STRUCT_INITIALIZER;
|
||||
double r = rng.uniform(min_r, max_r);
|
||||
double phi = j*dphi;
|
||||
pt.x = cvRound(center.x + r*cos(phi));
|
||||
pt.y = cvRound(center.y - r*sin(phi));
|
||||
cvSeqPush(contour, &pt);
|
||||
}
|
||||
|
||||
CvSlice slice = {0, 0};
|
||||
for(;;)
|
||||
{
|
||||
slice.start_index = rng.uniform(-n/2, 3*n/2);
|
||||
slice.end_index = rng.uniform(-n/2, 3*n/2);
|
||||
int len = cvSliceLength(slice, contour);
|
||||
if( len > 2 )
|
||||
break;
|
||||
}
|
||||
CvSeq *cslice = cvSeqSlice(contour, slice);
|
||||
/*printf( "%d. (%d, %d) of %d, length = %d, length1 = %d\n",
|
||||
i, slice.start_index, slice.end_index,
|
||||
contour->total, cvSliceLength(slice, contour), cslice->total );
|
||||
|
||||
double area0 = cvContourArea(cslice);
|
||||
double area1 = cvContourArea(contour, slice);
|
||||
if( area0 != area1 )
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG,
|
||||
"The contour area slice is computed differently (%g vs %g)\n", area0, area1 );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}*/
|
||||
|
||||
double len0 = cvArcLength(cslice, CV_WHOLE_SEQ, 1);
|
||||
double len1 = cvArcLength(contour, slice, 1);
|
||||
if( len0 != len1 )
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG,
|
||||
"The contour arc length is computed differently (%g vs %g)\n", len0, len1 );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_ConvexHull, accuracy) { CV_ConvHullTest test; test.safe_run(); }
|
||||
TEST(Imgproc_MinAreaRect, accuracy) { CV_MinAreaRectTest test; test.safe_run(); }
|
||||
TEST(Imgproc_MinTriangle, accuracy) { CV_MinTriangleTest test; test.safe_run(); }
|
||||
TEST(Imgproc_MinCircle, accuracy) { CV_MinCircleTest test; test.safe_run(); }
|
||||
TEST(Imgproc_MinCircle2, accuracy) { CV_MinCircleTest2 test; test.safe_run(); }
|
||||
TEST(Imgproc_ContourPerimeter, accuracy) { CV_PerimeterTest test; test.safe_run(); }
|
||||
TEST(Imgproc_FitEllipse, accuracy) { CV_FitEllipseTest test; test.safe_run(); }
|
||||
TEST(Imgproc_FitEllipse, parallel) { CV_FitEllipseParallelTest test; test.safe_run(); }
|
||||
TEST(Imgproc_FitLine, accuracy) { CV_FitLineTest test; test.safe_run(); }
|
||||
TEST(Imgproc_ContourMoments, accuracy) { CV_ContourMomentsTest test; test.safe_run(); }
|
||||
TEST(Imgproc_ContourPerimeterSlice, accuracy) { CV_PerimeterAreaSliceTest test; test.safe_run(); }
|
||||
TEST(Imgproc_FitEllipse, small) { CV_FitEllipseSmallTest test; test.safe_run(); }
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user