@ -245,176 +245,6 @@ int CV_DrawingTest_CPP::checkLineIterator( Mat& img )
return 0 ;
}
class CV_DrawingTest_C : public CV_DrawingTest
{
public :
CV_DrawingTest_C ( ) { }
protected :
virtual void draw ( Mat & img ) ;
virtual int checkLineIterator ( Mat & img ) ;
} ;
void CV_DrawingTest_C : : draw ( Mat & _img )
{
CvSize imgSize = cvSize ( 600 , 400 ) ;
_img . create ( imgSize , CV_8UC3 ) ;
CvMat img = cvMat ( _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 ( ) ;
int actualSize = 0 ;
cvFillPoly ( & img , & pts , & n , 1 , cvScalar ( 255 , 255 , 255 ) ) ;
CvPoint p1 = cvPoint ( 1 , 1 ) , p2 = cvPoint ( 3 , 3 ) ;
if ( cvClipLine ( imgSize , & p1 , & p2 ) )
cvCircle ( & img , cvPoint ( 300 , 100 ) , 40 , cvScalar ( 0 , 0 , 255 ) , 3 ) ; // draw
p1 = cvPoint ( 1 , 1 ) , p2 = cvPoint ( 3 , imgSize . height + 1000 ) ;
if ( cvClipLine ( imgSize , & p1 , & p2 ) )
cvCircle ( & img , cvPoint ( 500 , 300 ) , 50 , cvScalar ( 255 , 0 , 0 ) , 5 , 8 , 1 ) ; // draw
p1 = cvPoint ( imgSize . width , 1 ) , p2 = cvPoint ( imgSize . width , 3 ) ;
if ( cvClipLine ( imgSize , & p1 , & p2 ) )
cvCircle ( & img , cvPoint ( 390 , 100 ) , 10 , cvScalar ( 0 , 0 , 255 ) , 3 ) ; // not draw
p1 = cvPoint ( imgSize . width - 1 , 1 ) , p2 = cvPoint ( imgSize . width , 3 ) ;
if ( cvClipLine ( imgSize , & p1 , & p2 ) )
cvEllipse ( & img , cvPoint ( 390 , 100 ) , cvSize ( 20 , 30 ) , 60 , 0 , 220.0 , cvScalar ( 0 , 200 , 0 ) , 4 ) ; //draw
CvBox2D box ;
box . center . x = 100 ;
box . center . y = 200 ;
box . size . width = 200 ;
box . size . height = 100 ;
box . angle = 160 ;
cvEllipseBox ( & img , box , cvScalar ( 200 , 200 , 255 ) , 5 ) ;
polyline . resize ( 9 ) ;
pts = & polyline [ 0 ] ;
n = ( int ) polyline . size ( ) ;
actualSize = cvEllipse2Poly ( cvPoint ( 430 , 180 ) , cvSize ( 100 , 150 ) , 30 , 0 , 150 , & polyline [ 0 ] , 20 ) ;
CV_Assert ( actualSize = = n ) ;
cvPolyLine ( & img , & pts , & n , 1 , false , cvScalar ( 0 , 0 , 150 ) , 4 , CV_AA ) ;
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 ( 19 ) ;
pts = & polyline [ 0 ] ;
n = ( int ) polyline . size ( ) ;
actualSize = cvEllipse2Poly ( cvPoint ( 500 , 300 ) , cvSize ( 50 , 80 ) , 0 , 0 , 180 , & polyline [ 0 ] , 10 ) ;
CV_Assert ( actualSize = = n ) ;
cvPolyLine ( & img , & pts , & n , 1 , true , cvScalar ( 100 , 200 , 100 ) , 20 ) ;
cvFillConvexPoly ( & img , pts , n , cvScalar ( 0 , 80 , 0 ) ) ;
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 ) ;
cvRectangle ( & img , cvPoint ( 0 , 300 ) , cvPoint ( 50 , 398 ) , cvScalar ( 0 , 0 , 255 ) ) ;
string text1 = " OpenCV " ;
CvFont font ;
cvInitFont ( & font , FONT_HERSHEY_SCRIPT_SIMPLEX , 2 , 2 , 0 , 3 ) ;
int baseline = 0 ;
CvSize textSize = { 0 , 0 } ;
cvGetTextSize ( text1 . c_str ( ) , & font , & textSize , & baseline ) ;
baseline + = font . thickness ;
CvPoint textOrg = cvPoint ( ( imgSize . width - textSize . width ) / 2 , ( imgSize . height + textSize . height ) / 2 ) ;
cvRectangle ( & img , cvPoint ( textOrg . x , textOrg . y + baseline ) ,
cvPoint ( textOrg . x + textSize . width , textOrg . y - textSize . height ) , cvScalar ( 0 , 0 , 255 ) ) ;
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 ;
string text2 = " abcdefghijklmnopqrstuvwxyz1234567890 " ;
CvScalar color = cvScalar ( 200 , 0 , 0 ) ;
cvInitFont ( & font , FONT_HERSHEY_SIMPLEX , 0.5 , 0.5 , 0 , 1 , CV_AA ) ;
cvGetTextSize ( text2 . c_str ( ) , & font , & textSize , & baseline ) ;
textOrg = cvPoint ( 5 , 5 + textSize . height + dist ) ;
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 ) ;
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_COMPLEX , 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 ) ;
cvInitFont ( & font , FONT_HERSHEY_TRIPLEX , 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 ) ;
cvInitFont ( & font , FONT_HERSHEY_COMPLEX_SMALL , 1 , 1 , 0 , 1 , CV_AA ) ;
cvGetTextSize ( text2 . c_str ( ) , & font , & textSize , & baseline ) ;
textOrg = cvPoint ( textOrg . x , textOrg . y + textSize . height + dist + 180 ) ;
cvPutText ( & img , text2 . c_str ( ) , textOrg , & font , color ) ;
cvInitFont ( & font , FONT_HERSHEY_SCRIPT_SIMPLEX , 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_SCRIPT_COMPLEX , 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 ) ;
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 )
{
CvLineIterator it ;
CvMat img = cvMat ( _img ) ;
int count = cvInitLineIterator ( & img , cvPoint ( 0 , 300 ) , cvPoint ( 1000 , 300 ) , & it ) ;
for ( int i = 0 ; i < count ; i + + )
{
Vec3b v = ( Vec3b ) ( * ( it . ptr ) ) - _img . at < Vec3b > ( 300 , i ) ;
float err = ( float ) cvtest : : norm ( v , NORM_L2 ) ;
if ( err ! = 0 )
{
ts - > printf ( ts - > LOG , " CvLineIterator works incorrect " ) ;
ts - > set_failed_test_info ( cvtest : : TS : : FAIL_INVALID_OUTPUT ) ;
}
CV_NEXT_LINE_POINT ( it ) ;
}
ts - > set_failed_test_info ( cvtest : : TS : : OK ) ;
return 0 ;
}
class CV_DrawingTest_Far : public CV_DrawingTest_CPP
{
public :
@ -549,7 +379,6 @@ void CV_DrawingTest_Far::draw(Mat& img)
}
TEST ( Drawing , cpp_regression ) { CV_DrawingTest_CPP test ; test . safe_run ( ) ; }
TEST ( Drawing , c_regression ) { CV_DrawingTest_C test ; test . safe_run ( ) ; }
TEST ( Drawing , far_regression ) { CV_DrawingTest_Far test ; test . safe_run ( ) ; }
class CV_FillConvexPolyTest : public cvtest : : BaseTest