Fixed highgui tests for Android

This commit is contained in:
Andrey Kamaev 2011-12-20 07:45:49 +00:00
parent 54adb3c9cf
commit 4168a698f6
6 changed files with 679 additions and 618 deletions

View File

@ -49,43 +49,43 @@ using namespace cv;
class CV_DrawingTest : public cvtest::BaseTest class CV_DrawingTest : public cvtest::BaseTest
{ {
public: public:
CV_DrawingTest(){} CV_DrawingTest(){}
protected: protected:
void run( int ); void run( int );
virtual void draw( Mat& img ) = 0; virtual void draw( Mat& img ) = 0;
virtual int checkLineIterator( Mat& img) = 0; virtual int checkLineIterator( Mat& img) = 0;
}; };
void CV_DrawingTest::run( int ) void CV_DrawingTest::run( int )
{ {
Mat testImg, valImg; Mat testImg, valImg;
const string name = "drawing/image.jpg"; const string name = "drawing/image.jpg";
string path = ts->get_data_path(), filename; string path = ts->get_data_path(), filename;
filename = path + name; filename = path + name;
draw( testImg );
valImg = imread( filename ); draw( testImg );
if( valImg.empty() )
{ valImg = imread( filename );
if( valImg.empty() )
{
imwrite( filename, testImg ); imwrite( filename, testImg );
//ts->printf( ts->LOG, "test image can not be read"); //ts->printf( ts->LOG, "test image can not be read");
//ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); //ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
} }
else else
{ {
float err = (float)norm( testImg, valImg, CV_RELATIVE_L1 ); float err = (float)norm( testImg, valImg, CV_RELATIVE_L1 );
float Eps = 0.9f; float Eps = 0.9f;
if( err > Eps) if( err > Eps)
{ {
ts->printf( ts->LOG, "CV_RELATIVE_L1 between testImg and valImg is equal %f (larger than %f)\n", err, Eps ); ts->printf( ts->LOG, "CV_RELATIVE_L1 between testImg and valImg is equal %f (larger than %f)\n", err, Eps );
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
} }
else else
{ {
ts->set_failed_test_info(checkLineIterator( testImg )); ts->set_failed_test_info(checkLineIterator( testImg ));
} }
} }
ts->set_failed_test_info(cvtest::TS::OK); ts->set_failed_test_info(cvtest::TS::OK);
} }
@ -94,148 +94,148 @@ class CV_DrawingTest_CPP : public CV_DrawingTest
public: public:
CV_DrawingTest_CPP() {} CV_DrawingTest_CPP() {}
protected: protected:
virtual void draw( Mat& img ); virtual void draw( Mat& img );
virtual int checkLineIterator( Mat& img); virtual int checkLineIterator( Mat& img);
}; };
void CV_DrawingTest_CPP::draw( Mat& img ) void CV_DrawingTest_CPP::draw( Mat& img )
{ {
Size imgSize( 600, 400 ); Size imgSize( 600, 400 );
img.create( imgSize, CV_8UC3 ); img.create( imgSize, CV_8UC3 );
vector<Point> polyline(4); vector<Point> polyline(4);
polyline[0] = Point(0, 0); polyline[0] = Point(0, 0);
polyline[1] = Point(imgSize.width, 0); polyline[1] = Point(imgSize.width, 0);
polyline[2] = Point(imgSize.width, imgSize.height); polyline[2] = Point(imgSize.width, imgSize.height);
polyline[3] = Point(0, imgSize.height); polyline[3] = Point(0, imgSize.height);
const Point* pts = &polyline[0]; const Point* pts = &polyline[0];
int n = (int)polyline.size(); int n = (int)polyline.size();
fillPoly( img, &pts, &n, 1, Scalar::all(255) ); fillPoly( img, &pts, &n, 1, Scalar::all(255) );
Point p1(1,1), p2(3,3); Point p1(1,1), p2(3,3);
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) ) if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
circle( img, Point(300,100), 40, Scalar(0,0,255), 3 ); // draw circle( img, Point(300,100), 40, Scalar(0,0,255), 3 ); // draw
p2 = Point(3,imgSize.height+1000); p2 = Point(3,imgSize.height+1000);
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) ) if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
circle( img, Point(500,300), 50, cvColorToScalar(255,CV_8UC3), 5, 8, 1 ); // draw circle( img, Point(500,300), 50, cvColorToScalar(255,CV_8UC3), 5, 8, 1 ); // draw
p1 = Point(imgSize.width,1), p2 = Point(imgSize.width,3); p1 = Point(imgSize.width,1), p2 = Point(imgSize.width,3);
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) ) if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
circle( img, Point(390,100), 10, Scalar(0,0,255), 3 ); // not draw circle( img, Point(390,100), 10, Scalar(0,0,255), 3 ); // not draw
p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3); p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3);
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) ) if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
ellipse( img, Point(390,100), Size(20,30), 60, 0, 220.0, Scalar(0,200,0), 4 ); //draw ellipse( img, Point(390,100), Size(20,30), 60, 0, 220.0, Scalar(0,200,0), 4 ); //draw
ellipse( img, RotatedRect(Point(100,200),Size(200,100),160), Scalar(200,200,255), 5 ); ellipse( img, RotatedRect(Point(100,200),Size(200,100),160), Scalar(200,200,255), 5 );
polyline.clear(); polyline.clear();
ellipse2Poly( Point(430,180), Size(100,150), 30, 0, 150, 20, polyline ); ellipse2Poly( Point(430,180), Size(100,150), 30, 0, 150, 20, polyline );
pts = &polyline[0]; pts = &polyline[0];
n = (int)polyline.size(); n = (int)polyline.size();
polylines( img, &pts, &n, 1, false, Scalar(0,0,150), 4, CV_AA ); polylines( img, &pts, &n, 1, false, Scalar(0,0,150), 4, CV_AA );
n = 0; n = 0;
for( vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ ) for( vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
{ {
line( img, *it, *(it+1), Scalar(50,250,100)); line( img, *it, *(it+1), Scalar(50,250,100));
} }
polyline.clear(); polyline.clear();
ellipse2Poly( Point(500,300), Size(50,80), 0, 0, 180, 10, polyline ); ellipse2Poly( Point(500,300), Size(50,80), 0, 0, 180, 10, polyline );
pts = &polyline[0]; pts = &polyline[0];
n = (int)polyline.size(); n = (int)polyline.size();
polylines( img, &pts, &n, 1, true, Scalar(100,200,100), 20 ); polylines( img, &pts, &n, 1, true, Scalar(100,200,100), 20 );
fillConvexPoly( img, pts, n, Scalar(0, 80, 0) ); fillConvexPoly( img, pts, n, Scalar(0, 80, 0) );
polyline.resize(8); polyline.resize(8);
// external rectengular // external rectengular
polyline[0] = Point(0, 0); polyline[0] = Point(0, 0);
polyline[1] = Point(80, 0); polyline[1] = Point(80, 0);
polyline[2] = Point(80, 80); polyline[2] = Point(80, 80);
polyline[3] = Point(0, 80); polyline[3] = Point(0, 80);
// internal rectangular // internal rectangular
polyline[4] = Point(20, 20); polyline[4] = Point(20, 20);
polyline[5] = Point(60, 20); polyline[5] = Point(60, 20);
polyline[6] = Point(60, 60); polyline[6] = Point(60, 60);
polyline[7] = Point(20, 60); polyline[7] = Point(20, 60);
const Point* ppts[] = {&polyline[0], &polyline[0]+4}; const Point* ppts[] = {&polyline[0], &polyline[0]+4};
int pn[] = {4, 4}; int pn[] = {4, 4};
fillPoly( img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20) ); fillPoly( img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20) );
rectangle( img, Point(0, 300), Point(50, 398), Scalar(0,0,255) ); rectangle( img, Point(0, 300), Point(50, 398), Scalar(0,0,255) );
string text1 = "OpenCV"; string text1 = "OpenCV";
int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
float fontScale = 2; float fontScale = 2;
Size textSize = getTextSize( text1, fontFace, fontScale, thickness, &baseline); Size textSize = getTextSize( text1, fontFace, fontScale, thickness, &baseline);
baseline += thickness; baseline += thickness;
Point textOrg((img.cols - textSize.width)/2, (img.rows + textSize.height)/2); Point textOrg((img.cols - textSize.width)/2, (img.rows + textSize.height)/2);
rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0,0,255)); rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0,0,255));
line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255)); line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255));
putText(img, text1, textOrg, fontFace, fontScale, Scalar(150,0,150), thickness, 8); putText(img, text1, textOrg, fontFace, fontScale, Scalar(150,0,150), thickness, 8);
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890"; string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
Scalar color(200,0,0); Scalar color(200,0,0);
fontScale = 0.5, thickness = 1; fontScale = 0.5, thickness = 1;
int dist = 5; int dist = 5;
textSize = getTextSize( text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline); textSize = getTextSize( text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
textOrg = Point(5,5)+Point(0,textSize.height+dist); textOrg = Point(5,5)+Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA); putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA);
fontScale = 1;
textSize = getTextSize( text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
fontScale = 0.5; fontScale = 1;
textSize = getTextSize( text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline); textSize = getTextSize( text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
textOrg += Point(0,textSize.height+dist); textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA); putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline); fontScale = 0.5;
textOrg += Point(0,textSize.height+dist); textSize = getTextSize( text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline);
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA); textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA);
textSize = getTextSize( text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline); textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline);
textOrg += Point(0,textSize.height+dist); textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA); putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA);
fontScale = 1; textSize = getTextSize( text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline);
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline); textOrg += Point(0,textSize.height+dist);
textOrg += Point(0,180) + Point(0,textSize.height+dist); putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA);
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline); fontScale = 1;
textOrg += Point(0,textSize.height+dist); textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline);
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA); textOrg += Point(0,180) + Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline); textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline);
textOrg += Point(0,textSize.height+dist); textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA); putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA);
dist = 15, fontScale = 0.5; textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline);
textSize = getTextSize( text2, FONT_ITALIC, fontScale, thickness, &baseline); textOrg += Point(0,textSize.height+dist);
textOrg += Point(0,textSize.height+dist); putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA);
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
dist = 15, fontScale = 0.5;
textSize = getTextSize( text2, FONT_ITALIC, fontScale, thickness, &baseline);
textOrg += Point(0,textSize.height+dist);
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
} }
int CV_DrawingTest_CPP::checkLineIterator( Mat& img ) int CV_DrawingTest_CPP::checkLineIterator( Mat& img )
{ {
LineIterator it( img, Point(0,300), Point(1000, 300) ); LineIterator it( img, Point(0,300), Point(1000, 300) );
for(int i = 0; i < it.count; ++it, i++ ) for(int i = 0; i < it.count; ++it, i++ )
{ {
Vec3b v = (Vec3b)(*(*it)) - img.at<Vec3b>(300,i); Vec3b v = (Vec3b)(*(*it)) - img.at<Vec3b>(300,i);
float err = (float)norm( v ); float err = (float)norm( v );
if( err != 0 ) if( err != 0 )
{ {
ts->printf( ts->LOG, "LineIterator works incorrect" ); ts->printf( ts->LOG, "LineIterator works incorrect" );
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
} }
} }
ts->set_failed_test_info(cvtest::TS::OK); ts->set_failed_test_info(cvtest::TS::OK);
return 0; return 0;
} }
class CV_DrawingTest_C : public CV_DrawingTest class CV_DrawingTest_C : public CV_DrawingTest
@ -243,167 +243,167 @@ class CV_DrawingTest_C : public CV_DrawingTest
public: public:
CV_DrawingTest_C() {} CV_DrawingTest_C() {}
protected: protected:
virtual void draw( Mat& img ); virtual void draw( Mat& img );
virtual int checkLineIterator( Mat& img); virtual int checkLineIterator( Mat& img);
}; };
void CV_DrawingTest_C::draw( Mat& _img ) void CV_DrawingTest_C::draw( Mat& _img )
{ {
CvSize imgSize = cvSize(600, 400); CvSize imgSize = cvSize(600, 400);
_img.create( imgSize, CV_8UC3 ); _img.create( imgSize, CV_8UC3 );
CvMat img = _img; CvMat img = _img;
vector<CvPoint> polyline(4);
polyline[0] = cvPoint(0, 0);
polyline[1] = cvPoint(imgSize.width, 0);
polyline[2] = cvPoint(imgSize.width, imgSize.height);
polyline[3] = cvPoint(0, imgSize.height);
CvPoint* pts = &polyline[0];
int n = (int)polyline.size();
cvFillPoly( &img, &pts, &n, 1, cvScalar(255,255,255) );
CvPoint p1 = cvPoint(1,1), p2 = cvPoint(3,3); vector<CvPoint> polyline(4);
if( cvClipLine(imgSize, &p1, &p2) ) polyline[0] = cvPoint(0, 0);
cvCircle( &img, cvPoint(300,100), 40, cvScalar(0,0,255), 3 ); // draw polyline[1] = cvPoint(imgSize.width, 0);
polyline[2] = cvPoint(imgSize.width, imgSize.height);
polyline[3] = cvPoint(0, imgSize.height);
CvPoint* pts = &polyline[0];
int n = (int)polyline.size();
cvFillPoly( &img, &pts, &n, 1, cvScalar(255,255,255) );
p1 = cvPoint(1,1), p2 = cvPoint(3,imgSize.height+1000); CvPoint p1 = cvPoint(1,1), p2 = cvPoint(3,3);
if( cvClipLine(imgSize, &p1, &p2) ) if( cvClipLine(imgSize, &p1, &p2) )
cvCircle( &img, cvPoint(500,300), 50, cvScalar(255,0,0), 5, 8, 1 ); // draw cvCircle( &img, cvPoint(300,100), 40, cvScalar(0,0,255), 3 ); // draw
p1 = cvPoint(imgSize.width,1), p2 = cvPoint(imgSize.width,3); p1 = cvPoint(1,1), p2 = cvPoint(3,imgSize.height+1000);
if( cvClipLine(imgSize, &p1, &p2) ) if( cvClipLine(imgSize, &p1, &p2) )
cvCircle( &img, cvPoint(390,100), 10, cvScalar(0,0,255), 3 ); // not draw cvCircle( &img, cvPoint(500,300), 50, cvScalar(255,0,0), 5, 8, 1 ); // draw
p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3); p1 = cvPoint(imgSize.width,1), p2 = cvPoint(imgSize.width,3);
if( cvClipLine(imgSize, &p1, &p2) ) if( cvClipLine(imgSize, &p1, &p2) )
cvEllipse( &img, cvPoint(390,100), cvSize(20,30), 60, 0, 220.0, cvScalar(0,200,0), 4 ); //draw cvCircle( &img, cvPoint(390,100), 10, cvScalar(0,0,255), 3 ); // not draw
CvBox2D box; p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3);
box.center.x = 100; if( cvClipLine(imgSize, &p1, &p2) )
box.center.y = 200; cvEllipse( &img, cvPoint(390,100), cvSize(20,30), 60, 0, 220.0, cvScalar(0,200,0), 4 ); //draw
box.size.width = 200;
box.size.height = 100;
box.angle = 160;
cvEllipseBox( &img, box, Scalar(200,200,255), 5 );
polyline.resize(9); CvBox2D box;
pts = &polyline[0]; box.center.x = 100;
n = (int)polyline.size(); box.center.y = 200;
assert( cvEllipse2Poly( cvPoint(430,180), cvSize(100,150), 30, 0, 150, &polyline[0], 20 ) == n ); box.size.width = 200;
cvPolyLine( &img, &pts, &n, 1, false, cvScalar(0,0,150), 4, CV_AA ); box.size.height = 100;
n = 0; box.angle = 160;
for( vector<CvPoint>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ ) cvEllipseBox( &img, box, Scalar(200,200,255), 5 );
{
cvLine( &img, *it, *(it+1), cvScalar(50,250,100) );
}
polyline.resize(19); polyline.resize(9);
pts = &polyline[0]; pts = &polyline[0];
n = (int)polyline.size(); n = (int)polyline.size();
assert( cvEllipse2Poly( cvPoint(500,300), cvSize(50,80), 0, 0, 180, &polyline[0], 10 ) == n ); assert( cvEllipse2Poly( cvPoint(430,180), cvSize(100,150), 30, 0, 150, &polyline[0], 20 ) == n );
cvPolyLine( &img, &pts, &n, 1, true, Scalar(100,200,100), 20 ); cvPolyLine( &img, &pts, &n, 1, false, cvScalar(0,0,150), 4, CV_AA );
cvFillConvexPoly( &img, pts, n, cvScalar(0, 80, 0) ); n = 0;
for( vector<CvPoint>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
{
cvLine( &img, *it, *(it+1), cvScalar(50,250,100) );
}
polyline.resize(8); polyline.resize(19);
// external rectengular pts = &polyline[0];
polyline[0] = cvPoint(500, 20); n = (int)polyline.size();
polyline[1] = cvPoint(580, 20); assert( cvEllipse2Poly( cvPoint(500,300), cvSize(50,80), 0, 0, 180, &polyline[0], 10 ) == n );
polyline[2] = cvPoint(580, 100); cvPolyLine( &img, &pts, &n, 1, true, Scalar(100,200,100), 20 );
polyline[3] = cvPoint(500, 100); cvFillConvexPoly( &img, pts, n, cvScalar(0, 80, 0) );
// internal rectangular
polyline[4] = cvPoint(520, 40);
polyline[5] = cvPoint(560, 40);
polyline[6] = cvPoint(560, 80);
polyline[7] = cvPoint(520, 80);
CvPoint* ppts[] = {&polyline[0], &polyline[0]+4};
int pn[] = {4, 4};
cvFillPoly( &img, ppts, pn, 2, cvScalar(100, 100, 0), 8, 0 );
cvRectangle( &img, cvPoint(0, 300), cvPoint(50, 398), cvScalar(0,0,255) ); polyline.resize(8);
// external rectengular
polyline[0] = cvPoint(500, 20);
polyline[1] = cvPoint(580, 20);
polyline[2] = cvPoint(580, 100);
polyline[3] = cvPoint(500, 100);
// internal rectangular
polyline[4] = cvPoint(520, 40);
polyline[5] = cvPoint(560, 40);
polyline[6] = cvPoint(560, 80);
polyline[7] = cvPoint(520, 80);
CvPoint* ppts[] = {&polyline[0], &polyline[0]+4};
int pn[] = {4, 4};
cvFillPoly( &img, ppts, pn, 2, cvScalar(100, 100, 0), 8, 0 );
string text1 = "OpenCV"; cvRectangle( &img, cvPoint(0, 300), cvPoint(50, 398), cvScalar(0,0,255) );
CvFont font;
cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 2, 2, 0, 3 ); string text1 = "OpenCV";
int baseline = 0; CvFont font;
CvSize textSize; cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 2, 2, 0, 3 );
cvGetTextSize( text1.c_str(), &font, &textSize, &baseline ); int baseline = 0;
baseline += font.thickness; CvSize textSize;
CvPoint textOrg = cvPoint((imgSize.width - textSize.width)/2, (imgSize.height + textSize.height)/2); cvGetTextSize( text1.c_str(), &font, &textSize, &baseline );
cvRectangle( &img, cvPoint( textOrg.x, textOrg.y + baseline), baseline += font.thickness;
cvPoint(textOrg.x + textSize.width, textOrg.y - textSize.height), cvScalar(0,0,255)); CvPoint textOrg = cvPoint((imgSize.width - textSize.width)/2, (imgSize.height + textSize.height)/2);
cvLine( &img, cvPoint(textOrg.x, textOrg.y + font.thickness), cvRectangle( &img, cvPoint( textOrg.x, textOrg.y + baseline),
cvPoint(textOrg.x + textSize.width, textOrg.y + font.thickness), cvScalar(0, 0, 255)); cvPoint(textOrg.x + textSize.width, textOrg.y - textSize.height), cvScalar(0,0,255));
cvPutText( &img, text1.c_str(), textOrg, &font, cvScalar(150,0,150) ); cvLine( &img, cvPoint(textOrg.x, textOrg.y + font.thickness),
cvPoint(textOrg.x + textSize.width, textOrg.y + font.thickness), cvScalar(0, 0, 255));
cvPutText( &img, text1.c_str(), textOrg, &font, cvScalar(150,0,150) );
int dist = 5; int dist = 5;
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890"; string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
CvScalar color = cvScalar(200,0,0); CvScalar color = cvScalar(200,0,0);
cvInitFont( &font, FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(5, 5+textSize.height+dist); textOrg = cvPoint(5, 5+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_TRIPLEX, 0.5, 0.5, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_COMPLEX_SMALL, 1, 1, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_TRIPLEX, 0.5, 0.5, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist + 180); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 1, 1, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_COMPLEX_SMALL, 1, 1, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist + 180);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvInitFont( &font, FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1, 0, 1, CV_AA ); cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 1, 1, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color ); cvPutText(&img, text2.c_str(), textOrg, &font, color );
dist = 15; cvInitFont( &font, FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1, 0, 1, CV_AA );
cvInitFont( &font, FONT_ITALIC, 0.5, 0.5, 0, 1, CV_AA ); cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline ); textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist); cvPutText(&img, text2.c_str(), textOrg, &font, color );
cvPutText(&img, text2.c_str(), textOrg, &font, color );
dist = 15;
cvInitFont( &font, FONT_ITALIC, 0.5, 0.5, 0, 1, CV_AA );
cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
cvPutText(&img, text2.c_str(), textOrg, &font, color );
} }
int CV_DrawingTest_C::checkLineIterator( Mat& _img ) int CV_DrawingTest_C::checkLineIterator( Mat& _img )
{ {
CvLineIterator it; CvLineIterator it;
CvMat img = _img; CvMat img = _img;
int count = cvInitLineIterator( &img, cvPoint(0,300), cvPoint(1000, 300), &it ); int count = cvInitLineIterator( &img, cvPoint(0,300), cvPoint(1000, 300), &it );
for(int i = 0; i < count; i++ ) for(int i = 0; i < count; i++ )
{ {
Vec3b v = (Vec3b)(*(it.ptr)) - _img.at<Vec3b>(300,i); Vec3b v = (Vec3b)(*(it.ptr)) - _img.at<Vec3b>(300,i);
float err = (float)norm( v ); float err = (float)norm( v );
if( err != 0 ) if( err != 0 )
{ {
ts->printf( ts->LOG, "CvLineIterator works incorrect" ); ts->printf( ts->LOG, "CvLineIterator works incorrect" );
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
} }
CV_NEXT_LINE_POINT(it); CV_NEXT_LINE_POINT(it);
} }
ts->set_failed_test_info(cvtest::TS::OK); ts->set_failed_test_info(cvtest::TS::OK);
return 0; return 0;
} }
TEST(Highgui_Drawing_CPP, regression) { CV_DrawingTest_CPP test; test.safe_run(); } TEST(Highgui_Drawing_CPP, regression) { CV_DrawingTest_CPP test; test.safe_run(); }
TEST(Highgui_Drawing_C, regression) { CV_DrawingTest_C test; test.safe_run(); } TEST(Highgui_Drawing_C, regression) { CV_DrawingTest_C test; test.safe_run(); }

View File

@ -43,179 +43,46 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#ifdef HAVE_FFMPEG
using namespace cv; using namespace cv;
using namespace std; using namespace std;
class CV_FFmpegWriteBigImageTest : public cvtest::BaseTest
{
public:
void run(int)
{
try
{
ts->printf(cvtest::TS::LOG, "start reading bit image\n");
Mat img = imread(string(ts->get_data_path()) + "readwrite/read.png");
ts->printf(cvtest::TS::LOG, "finish reading bit image\n");
if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
ts->printf(cvtest::TS::LOG, "start writing bit image\n");
imwrite(string(ts->get_data_path()) + "readwrite/write.png", img);
ts->printf(cvtest::TS::LOG, "finish writing bit image\n");
}
catch(...)
{
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
}
ts->set_failed_test_info(cvtest::TS::OK);
}
};
class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest
{ {
public: public:
void run(int) void run(int)
{ {
const int img_r = 4096; const int img_r = 4096;
const int img_c = 4096; const int img_c = 4096;
Size frame_s = Size(img_c, img_r); Size frame_s = Size(img_c, img_r);
const double fps = 30; const double fps = 30;
const double time_sec = 2; const double time_sec = 2;
const int coeff = static_cast<int>(static_cast<double>(cv::min(img_c, img_r)) / (fps * time_sec)); const int coeff = static_cast<int>(static_cast<double>(cv::min(img_c, img_r)) / (fps * time_sec));
Mat img(img_r, img_c, CV_8UC3, Scalar::all(0)); Mat img(img_r, img_c, CV_8UC3, Scalar::all(0));
try try
{ {
VideoWriter writer(string(ts->get_data_path()) + "video/output.avi", CV_FOURCC('X', 'V', 'I', 'D'), fps, frame_s); VideoWriter writer(string(ts->get_data_path()) + "video/output.avi", CV_FOURCC('X', 'V', 'I', 'D'), fps, frame_s);
if (writer.isOpened() == false) ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); if (writer.isOpened() == false) ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
for (int i = 0 ; i < static_cast<int>(fps * time_sec); i++ ) for (int i = 0 ; i < static_cast<int>(fps * time_sec); i++ )
{ {
//circle(img, Point2i(img_c / 2, img_r / 2), cv::min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2); //circle(img, Point2i(img_c / 2, img_r / 2), cv::min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2);
rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)), rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)),
Scalar::all(255 * (1.0 - static_cast<double>(i) / (fps * time_sec * 2) )), -1); Scalar::all(255 * (1.0 - static_cast<double>(i) / (fps * time_sec * 2) )), -1);
writer << img; writer << img;
} }
} }
catch(...) catch(...)
{ {
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
} }
ts->set_failed_test_info(cvtest::TS::OK); ts->set_failed_test_info(cvtest::TS::OK);
} }
}; };
string ext_from_int(int ext) TEST(Highgui_FFmpeg_WriteBigVideo, regression) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); }
{
if (ext == 0) return ".png";
if (ext == 1) return ".bmp";
if (ext == 2) return ".pgm";
if (ext == 3) return ".tiff";
return "";
}
class CV_FFmpegWriteSequenceImageTest : public cvtest::BaseTest #endif
{
public:
void run(int)
{
try
{
const int img_r = 640;
const int img_c = 480;
Size frame_s = Size(img_c, img_r);
for (int k = 1; k <= 5; ++k)
{
for (int ext = 0; ext < 4; ++ext) // 0 - png, 1 - bmp, 2 - pgm, 3 - tiff
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ext_from_int(ext).c_str());
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
ts->printf(ts->LOG, "writing image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
imwrite(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), img);
ts->printf(ts->LOG, "reading test image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
Mat img_test = imread(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
// jpeg
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ".jpg");
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
string filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + "_.jpg");
imwrite(filename, img);
img = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + ".jpg");
ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
// tiff
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_16U, num_channels, ".tiff");
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_16U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
string filename = string(ts->get_data_path() + "readwrite/test.tiff");
imwrite(filename, img);
ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
ts->printf(ts->LOG, "img : %d ; %d \n", img.channels(), img.depth());
ts->printf(ts->LOG, "img_test : %d ; %d \n", img_test.channels(), img_test.depth());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
}
}
catch(const cv::Exception & e)
{
ts->printf(ts->LOG, "Exception: %s\n" , e.what());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
};
TEST(Highgui_FFmpeg_WriteBigImage, regression) { CV_FFmpegWriteBigImageTest test; test.safe_run(); }
TEST(Highgui_FFmpeg_WriteBigVideo, regression) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); }
TEST(Highgui_FFmpeg_WriteSequenceImage, regression) { CV_FFmpegWriteSequenceImageTest test; test.safe_run(); }

View File

@ -0,0 +1,186 @@
/*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 "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
class CV_GrfmtWriteBigImageTest : public cvtest::BaseTest
{
public:
void run(int)
{
try
{
ts->printf(cvtest::TS::LOG, "start reading big image\n");
Mat img = imread(string(ts->get_data_path()) + "readwrite/read.png");
ts->printf(cvtest::TS::LOG, "finish reading big image\n");
if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
ts->printf(cvtest::TS::LOG, "start writing big image\n");
imwrite(string(ts->get_data_path()) + "readwrite/write.png", img);
ts->printf(cvtest::TS::LOG, "finish writing big image\n");
}
catch(...)
{
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
}
ts->set_failed_test_info(cvtest::TS::OK);
}
};
string ext_from_int(int ext)
{
if (ext == 0) return ".png";
if (ext == 1) return ".bmp";
if (ext == 2) return ".pgm";
if (ext == 3) return ".tiff";
return "";
}
class CV_GrfmtWriteSequenceImageTest : public cvtest::BaseTest
{
public:
void run(int)
{
try
{
const int img_r = 640;
const int img_c = 480;
Size frame_s = Size(img_c, img_r);
for (int k = 1; k <= 5; ++k)
{
for (int ext = 0; ext < 4; ++ext) // 0 - png, 1 - bmp, 2 - pgm, 3 - tiff
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ext_from_int(ext).c_str());
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
ts->printf(ts->LOG, "writing image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
imwrite(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), img);
ts->printf(ts->LOG, "reading test image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
Mat img_test = imread(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
// jpeg
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ".jpg");
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
string filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + "_.jpg");
imwrite(filename, img);
img = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + ".jpg");
ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
for (int num_channels = 1; num_channels <= 3; num_channels+=2)
{
// tiff
ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_16U, num_channels, ".tiff");
Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_16U, num_channels), Scalar::all(0));
circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
string filename = string(ts->get_data_path() + "readwrite/test.tiff");
imwrite(filename, img);
ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
CV_Assert(img.size() == img_test.size());
ts->printf(ts->LOG, "img : %d ; %d \n", img.channels(), img.depth());
ts->printf(ts->LOG, "img_test : %d ; %d \n", img_test.channels(), img_test.depth());
CV_Assert(img.type() == img_test.type());
double n = norm(img, img_test);
if ( n > 1.0)
{
ts->printf(ts->LOG, "norm = %f \n", n);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
}
}
catch(const cv::Exception & e)
{
ts->printf(ts->LOG, "Exception: %s\n" , e.what());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
}
}
};
TEST(Highgui_Grfmt_WriteBigImage, regression) { CV_GrfmtWriteBigImageTest test; test.safe_run(); }
TEST(Highgui_Grfmt_WriteSequenceImage, regression) { CV_GrfmtWriteSequenceImageTest test; test.safe_run(); }

View File

@ -43,13 +43,15 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#if defined HAVE_GTK || defined HAVE_QT || defined WIN32 || defined _WIN32 || HAVE_CARBON || HAVE_COCOA
using namespace cv; using namespace cv;
using namespace std; using namespace std;
class CV_HighGuiOnlyGuiTest : public cvtest::BaseTest class CV_HighGuiOnlyGuiTest : public cvtest::BaseTest
{ {
protected: protected:
void run(int); void run(int);
}; };
void Foo(int /*k*/, void* /*z*/) {} void Foo(int /*k*/, void* /*z*/) {}
@ -57,30 +59,32 @@ void Foo(int /*k*/, void* /*z*/) {}
void CV_HighGuiOnlyGuiTest::run( int /*start_from */) void CV_HighGuiOnlyGuiTest::run( int /*start_from */)
{ {
ts->printf(ts->LOG, "GUI 1\n"); ts->printf(ts->LOG, "GUI 1\n");
namedWindow("Win"); namedWindow("Win");
ts->printf(ts->LOG, "GUI 2\n"); ts->printf(ts->LOG, "GUI 2\n");
Mat m(256, 256, CV_8U); Mat m(256, 256, CV_8U);
m = Scalar(128); m = Scalar(128);
ts->printf(ts->LOG, "GUI 3\n"); ts->printf(ts->LOG, "GUI 3\n");
imshow("Win", m); imshow("Win", m);
ts->printf(ts->LOG, "GUI 4\n"); ts->printf(ts->LOG, "GUI 4\n");
int value = 50; int value = 50;
ts->printf(ts->LOG, "GUI 5\n"); ts->printf(ts->LOG, "GUI 5\n");
createTrackbar( "trackbar", "Win", &value, 100, Foo, &value); createTrackbar( "trackbar", "Win", &value, 100, Foo, &value);
ts->printf(ts->LOG, "GUI 6\n"); ts->printf(ts->LOG, "GUI 6\n");
getTrackbarPos( "trackbar", "Win" ); getTrackbarPos( "trackbar", "Win" );
ts->printf(ts->LOG, "GUI 7\n"); ts->printf(ts->LOG, "GUI 7\n");
waitKey(500); waitKey(500);
ts->printf(ts->LOG, "GUI 8\n"); ts->printf(ts->LOG, "GUI 8\n");
cvDestroyAllWindows(); cvDestroyAllWindows();
ts->set_failed_test_info(cvtest::TS::OK); ts->set_failed_test_info(cvtest::TS::OK);
} }
TEST(Highgui_GUI, regression) { CV_HighGuiOnlyGuiTest test; test.safe_run(); } TEST(Highgui_GUI, regression) { CV_HighGuiOnlyGuiTest test; test.safe_run(); }
#endif

View File

@ -1,6 +1,10 @@
#ifndef __OPENCV_TEST_PRECOMP_HPP__ #ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__ #define __OPENCV_TEST_PRECOMP_HPP__
#ifdef HAVE_CVCONFIG_H
# include "cvconfig.h"
#endif
#include "opencv2/ts/ts.hpp" #include "opencv2/ts/ts.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/imgproc/imgproc_c.h"

View File

@ -48,205 +48,205 @@ using namespace std;
class CV_HighGuiTest : public cvtest::BaseTest class CV_HighGuiTest : public cvtest::BaseTest
{ {
protected: protected:
void ImagesTest(const string& dir); void ImagesTest(const string& dir);
void VideoTest (const string& dir, int fourcc); void VideoTest (const string& dir, int fourcc);
public: public:
void run(int); void run(int);
}; };
double PSNR(const Mat& m1, const Mat& m2) double PSNR(const Mat& m1, const Mat& m2)
{ {
Mat tmp; Mat tmp;
absdiff( m1.reshape(1), m2.reshape(1), tmp); absdiff( m1.reshape(1), m2.reshape(1), tmp);
multiply(tmp, tmp, tmp); multiply(tmp, tmp, tmp);
double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0]; double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0];
return 20 * log10(255.0 / sqrt(MSE)); return 20 * log10(255.0 / sqrt(MSE));
} }
void CV_HighGuiTest::ImagesTest(const string& dir) void CV_HighGuiTest::ImagesTest(const string& dir)
{ {
string _name = dir + string("../cv/shared/baboon.jpg"); string _name = dir + string("../cv/shared/baboon.jpg");
ts->printf(ts->LOG, "reading image : %s\n", _name.c_str()); ts->printf(ts->LOG, "reading image : %s\n", _name.c_str());
Mat image = imread(_name); Mat image = imread(_name);
image.convertTo(image, CV_8UC3); image.convertTo(image, CV_8UC3);
if (image.empty())
{
ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
return;
}
const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras" }; if (image.empty())
const size_t ext_num = sizeof(exts)/sizeof(exts[0]); {
ts->set_failed_test_info(ts->FAIL_MISSING_TEST_DATA);
for(size_t i = 0; i < ext_num; ++i) return;
{ }
const string exts[] = {"png", "bmp", "tiff", "jpg", "jp2", "ppm", "ras" };
const size_t ext_num = sizeof(exts)/sizeof(exts[0]);
for(size_t i = 0; i < ext_num; ++i)
{
string ext = exts[i]; string ext = exts[i];
string full_name = dir + "img." + ext; string full_name = dir + "img." + ext;
ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str()); ts->printf(ts->LOG, " full_name : %s\n", full_name.c_str());
imwrite(full_name, image); imwrite(full_name, image);
Mat loaded = imread(full_name); Mat loaded = imread(full_name);
if (loaded.empty()) if (loaded.empty())
{ {
ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str()); ts->printf(ts->LOG, "Reading failed at fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
const double thresDbell = 20;
double psnr = PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
continue;
}
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END);
long len = ftell(f);
from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET);
from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f);
vector<uchar> buf;
imencode("." + exts[i], image, buf);
if (buf != from_file)
{
ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
Mat buf_loaded = imdecode(Mat(buf), 1);
if (buf_loaded.empty())
{
ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
const double thresDbell = 20;
double psnr = PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
ts->set_failed_test_info(ts->FAIL_BAD_ACCURACY);
continue;
}
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END);
long len = ftell(f);
from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET);
from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f);
vector<uchar> buf;
imencode("." + exts[i], image, buf);
if (buf != from_file)
{
ts->printf(ts->LOG, "Encoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
Mat buf_loaded = imdecode(Mat(buf), 1);
if (buf_loaded.empty())
{
ts->printf(ts->LOG, "Decoding failed with fmt=%s\n", ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue;
}
psnr = PSNR(buf_loaded, image); psnr = PSNR(buf_loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str()); ts->printf(ts->LOG, "Decoding image from memory: too small PSNR (=%gdb) with fmt=%s\n", psnr, ext.c_str());
ts->set_failed_test_info(ts->FAIL_MISMATCH); ts->set_failed_test_info(ts->FAIL_MISMATCH);
continue; continue;
} }
}
ts->printf(ts->LOG, "end test function : ImagesTest \n"); }
ts->set_failed_test_info(ts->OK);
ts->printf(ts->LOG, "end test function : ImagesTest \n");
ts->set_failed_test_info(ts->OK);
} }
void CV_HighGuiTest::VideoTest(const string& dir, int fourcc) void CV_HighGuiTest::VideoTest(const string& dir, int fourcc)
{ {
string src_file = dir + "../cv/shared/video_for_test.avi"; string src_file = dir + "../cv/shared/video_for_test.avi";
string tmp_name = dir + "video.avi"; string tmp_name = dir + "video.avi";
ts->printf(ts->LOG, "reading video : %s\n", src_file.c_str()); ts->printf(ts->LOG, "reading video : %s\n", src_file.c_str());
CvCapture* cap = cvCaptureFromFile(src_file.c_str());
if (!cap)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
CvVideoWriter* writer = 0;
CvCapture* cap = cvCaptureFromFile(src_file.c_str());
if (!cap)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
CvVideoWriter* writer = 0;
int counter = 0; int counter = 0;
for(;;) for(;;)
{ {
IplImage * img = cvQueryFrame( cap ); IplImage * img = cvQueryFrame( cap );
if (!img) if (!img)
break; break;
if (writer == 0)
{
writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
if (writer == 0)
{
ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n", fourcc);
cvReleaseCapture( &cap );
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
}
cvWriteFrame(writer, img);
}
cvReleaseVideoWriter( &writer ); if (writer == 0)
cvReleaseCapture( &cap ); {
writer = cvCreateVideoWriter(tmp_name.c_str(), fourcc, 24, cvGetSize(img));
cap = cvCaptureFromFile(src_file.c_str()); if (writer == 0)
{
ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n", fourcc);
cvReleaseCapture( &cap );
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
}
CvCapture *saved = cvCaptureFromFile(tmp_name.c_str()); cvWriteFrame(writer, img);
if (!saved) }
{
ts->set_failed_test_info(ts->FAIL_MISMATCH); cvReleaseVideoWriter( &writer );
return; cvReleaseCapture( &cap );
}
cap = cvCaptureFromFile(src_file.c_str());
CvCapture *saved = cvCaptureFromFile(tmp_name.c_str());
if (!saved)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
return;
}
const double thresDbell = 20;
const double thresDbell = 20;
counter = 0; counter = 0;
for(;;) for(;;)
{ {
IplImage* ipl = cvQueryFrame( cap ); IplImage* ipl = cvQueryFrame( cap );
IplImage* ipl1 = cvQueryFrame( saved ); IplImage* ipl1 = cvQueryFrame( saved );
if (!ipl || !ipl1)
break;
Mat img(ipl);
Mat img1(ipl1);
if (PSNR(img1, img) < thresDbell)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
break;
}
}
cvReleaseCapture( &cap );
cvReleaseCapture( &saved );
ts->printf(ts->LOG, "end test function : ImagesVideo \n"); if (!ipl || !ipl1)
break;
Mat img(ipl);
Mat img1(ipl1);
if (PSNR(img1, img) < thresDbell)
{
ts->set_failed_test_info(ts->FAIL_MISMATCH);
break;
}
}
cvReleaseCapture( &cap );
cvReleaseCapture( &saved );
ts->printf(ts->LOG, "end test function : ImagesVideo \n");
} }
void CV_HighGuiTest::run( int /*start_from */) void CV_HighGuiTest::run( int /*start_from */)
{ {
ImagesTest(ts->get_data_path()); ImagesTest(ts->get_data_path());
#if defined WIN32 || defined __linux__ #if defined WIN32 || (defined __linux__ && !defined ANDROID)
#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
VideoTest(ts->get_data_path(), CV_FOURCC_DEFAULT); VideoTest(ts->get_data_path(), CV_FOURCC_DEFAULT);
VideoTest(ts->get_data_path(), CV_FOURCC('X', 'V', 'I', 'D')); VideoTest(ts->get_data_path(), CV_FOURCC('X', 'V', 'I', 'D'));
VideoTest(ts->get_data_path(), CV_FOURCC('M', 'P', 'G', '2')); VideoTest(ts->get_data_path(), CV_FOURCC('M', 'P', 'G', '2'));
VideoTest(ts->get_data_path(), CV_FOURCC('M', 'J', 'P', 'G')); VideoTest(ts->get_data_path(), CV_FOURCC('M', 'J', 'P', 'G'));
#endif #endif
#endif #endif