📄 adrawing_regress.cpp
字号:
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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 <windows.h>
#include "cvtest.h"
extern "C"
{
#include "HighGUI.h"
}
static char* funcs = "cvLine cvLineAA cvRectangle cvCircle cvCircleAA "
"cvEllipse cvEllipseAA cvFillConvexPoly cvFillPoly"
"cvPolyLine cvPolyLineAA cvPutText";
static char* test_desc = "Drawing to image (regression test)";
static char* filedir_ = "drawing";
static int CheckImage(IplImage* image, char* file, char* /*funcname*/)
{
IplImage* read = atsCreateImageFromFile( file );
if( !read )
{
trsWrite( ATS_CON | ATS_LST, "can't read image\n" );
return 1;
}
int err = 0;
for( int i = 0; i < image->height; i++ )
{
for( int j = 0; j < image->width; j++ )
{
for( int k = 0; k < image->nChannels; k++ )
{
if( image->imageData[i * image->widthStep + j * image->nChannels + k] !=
read->imageData[i * read->widthStep + j * read->nChannels + k] )
{
/*trsWrite( ATS_CON | ATS_LST, "%s: (%d, %d) ch %d act %d exp %d\n",
funcname, i, j, k,
image->imageData[i * image->widthStep + j * image->nChannels + k],
read->imageData[i * read->widthStep + j * read->nChannels + k] );*/
err++;
}
}
}
}
atsReleaseImage( read );
return err;
}
static int ProcessImage( IplImage* image, char* funcname, int read )
{
char name[1000];
int err;
if( read )
{
err = CheckImage( image,
atsGetTestDataPath(name, filedir_, funcname, "bmp"),
funcname );
if( err )
trsWrite( ATS_CON | ATS_LST, "Error in %s\n", funcname );
return err;
}
else
{
save_iplimage( atsGetTestDataPath(name, filedir_, funcname, "bmp"), image );
return 0;
}
}
static int drawing_test()
{
static int read_params = 0;
static int read = 0;
const int channel = 3;
CvSize size = cvSize(600, 300);
int i, j;
int Errors = 0;
if( !read_params )
{
read_params = 1;
trsCaseRead( &read, "/n/y", "y", "Read from file ?" );
}
// Create image
IplImage* image = cvCreateImage( size, IPL_DEPTH_8U, channel );
// cvLine
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i++ )
{
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
cvLine( image, p1, p2, RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvLine", read );
// cvLineAA
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i++ )
{
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
cvLineAA( image, p1, p2, RGB(i, 255 - i, 178 + i), 0 );
}
//Errors += ProcessImage( image, "cvLineAA", read );
// cvRectangle
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i++ )
{
CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );
cvRectangle( image, p1, p2, RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvRectangle", read );
// cvCircle
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i++ )
{
CvPoint p1 = cvPoint( i * 3, i * 2 );
CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );
cvCircle( image, p1, i, RGB(i, 255 - i, 178 + i), i % 10 );
cvCircle( image, p2, i, RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvCircle", read );
// cvCircleAA
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i++ )
{
CvPoint p1 = cvPoint( i * 3, i * 2 );
CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );
cvCircleAA( image, p1, i, RGB(i, 255 - i, 178 + i), 0 );
cvCircleAA( image, p2, i, RGB(i, 255 - i, 178 + i), 0 );
}
Errors += ProcessImage( image, "cvCircleAA", read );
// cvEllipse
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 10; i < 100; i += 10 )
{
CvPoint p1 = cvPoint( i * 6, i * 3 );
CvSize axes = cvSize( i * 3, i * 2 );
cvEllipse( image, p1, axes,
180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvEllipse", read );
// cvEllipseAA
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 10; i < 100; i += 10 )
{
CvPoint p1 = cvPoint( i * 6, i * 3 );
CvSize axes = cvSize( i * 3, i * 2 );
cvEllipseAA( image, p1, axes,
180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvEllipseAA", read );
// cvFillConvexPoly
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( j = 0; j < 5; j++ )
for( i = 0; i < 100; i += 10 )
{
CvPoint p[4] = {{ j * 100 - 10, i }, { j * 100 + 10, i },
{ j * 100 + 30, i * 2 }, { j * 100 + 170, i * 3 }};
cvFillConvexPoly( image, p, 4, RGB(i, 255 - i, 178 + i) );
}
Errors += ProcessImage( image, "cvFillConvexPoly", read );
// cvFillPoly
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i += 10 )
{
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
CvPoint* p[] = {p0, p1, p2, p3, p4};
int n[] = {4, 4, 4, 4, 4};
cvFillPoly( image, p, n, 5, RGB(i, 255 - i, 178 + i) );
}
Errors += ProcessImage( image, "cvFillPoly", read );
// cvPolyLine
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i += 10 )
{
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
CvPoint* p[] = {p0, p1, p2, p3, p4};
int n[] = {4, 4, 4, 4, 4};
cvPolyLine( image, p, n, 5, 1, RGB(i, 255 - i, 178 + i), i % 10 );
}
Errors += ProcessImage( image, "cvPolyLine", read );
// cvPolyLineAA
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 0; i < 100; i += 10 )
{
CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};
CvPoint* p[] = {p0, p1, p2, p3, p4};
int n[] = {4, 4, 4, 4, 4};
cvPolyLineAA( image, p, n, 5, 1, RGB(i, 255 - i, 178 + i), 0 );
}
Errors += ProcessImage( image, "cvPolyLineAA", read );
// cvPolyLineAA
for( i = 0; i < image->widthStep * image->height; i++ )
image->imageData[i] = 0;
for( i = 1; i < 10; i++ )
{
CvFont font;
cvInitFont( &font, CV_FONT_VECTOR0,
(double)i / 5, (double)i / 5, (double)i / 10, i );
cvPutText( image, "privet. this is test. :)", cvPoint(0, i * 20), &font, RGB(i, 255 - i, 178 + i) );
}
Errors += ProcessImage( image, "cvPutText", read );
cvReleaseImage( &image );
return Errors ? trsResult( TRS_FAIL, "errors" ) : trsResult( TRS_OK, "ok" );
}
void InitADrawingRegress()
{
/* Register test functions */
trsReg( funcs, test_desc, atsAlgoClass, drawing_test );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -