Hoje vamos olhar algumas funções de desenho! =)
Today lets study some drawing functions =)
First just some lines , rectangles, circles and ellipses;
Apenas algumas linhas, retangulos, circulos e elipses inicialmente;
#include <highgui.h>
#include <cv.h>
int main()
{
int gap;
CvPoint aux1,aux2;
cvNamedWindow("Drawing", CV_WINDOW_AUTOSIZE);
IplImage* cool;
cool = cvCreateImage(cvSize(300,300), IPL_DEPTH_8U, 3);
/* creating an image with size 300x300, unsigned 8-bit integers, 3-channels RGB */
/* criando uma imagem 300x300, 8 bits inteiros sem sinal, 3 canais RGB */
cvLine( cool, cvPoint(0,0), cvPoint(300,300), CV_RGB(0,255,0), 1,CV_AA, 0 );
cvLine( cool, cvPoint(300,0), cvPoint(0,300), CV_RGB(0,255,0), 1,CV_AA, 0 );
/* first argument obviously is the pointer to the IplImage; 2nd is the first point
of the line; CvPoint function returns a Point that opencv can work with; 3rd is
the ending point; 4th is the color of the line, you may use the CV_RGB macro;
5th argument is the line thickness; 6th argument is the line type, it can be
4 to 4-connected line, 8 for 8-connected line, CV_AA to antialiased line; last
argument is number of fractional bits in the point coordinates.
primeiro argumento é o ponteiro para a IplImage; 2° é o primeiro ponto da linha
3° é o ultimo ponto da linha; CvPoint é uma função que transforma as cordenadas
dadas em uma estrutura que o OpenCV pode trabalhar; o 4° argumento é a cor; deve-
se utilizar o macro CV_RGB; 5° é a grossura da linha; 6° é o tipo da linha, pode
assumir os valores 4, 8 ou CV_AA, 4 (4-connected line), 8 (8-connected line) e
CV_AA para anti aliased line
*/
for ( gap = 300; gap != 0; gap -= 30)
{
aux1 = cvPoint(cool->width - gap, cool->height - gap);
/* here I am accessing some informations of the IplImage directly */
/* aqui eu acessei algumas informações do IplImage diretamente */
aux2 = cvPoint(gap, gap);
cvRectangle( cool, aux1, aux2, CV_RGB(255,0,0), 1, CV_AA, 0 );
/* The arguments are the same as cvLine, only 2nd and 3rd have different
interpretations, 2nd is one of the rectangle vertices and 3rd is the
opposite vertice.
Os argumentos são iguais ao do cvLine, apenas o 2° e 3° são diferentes
2° é um dos vértices, e o 3° é o vértice oposto
*/
}
cvCircle( cool, cvPoint(150,150), 90, CV_RGB(0,0,255), 1, CV_AA, 0 );
/* first argument is the pointer to IplImage, second is the center of the circle
3rd is the radius, 4th is the color, 5th is thickness (if <0 it will be filled),
6 is the linetype, last is the shift (number of fractional bits in the point
coordinates).
Primeiro argumento é o ponteiro para uma estrutura IplImage, segundo é o centro
do circulo, terceiro é o raio, 4° é a cor, os tres ultimos são iguais ao cvLine
*/
cvEllipse( cool, cvPoint(150,150), cvSize(90,120), 0, 0, 360, CV_RGB(0,255,0), 1, CV_AA,0 );
cvEllipse( cool, cvPoint(150,150), cvSize(90,120), 90, 0, 360, CV_RGB(0,255,0), 1, CV_AA,0 );
cvEllipse( cool, cvPoint(150,150), cvSize(90,120), 45, 0, 360, CV_RGB(0,255,0), 1, CV_AA,0 );
cvEllipse( cool, cvPoint(150,150), cvSize(90,120), 145, 0, 360, CV_RGB(0,255,0), 1, CV_AA,0 );
/* This function cvEllipse draw an ellipse, 1st argument is pointer to IplImage, 2nd is the center
of the ellipse, 3rd is the size of the ellipse's axis, 4th is the angle of the elipse, 5th
is the initial angle of the elipse, 6th is the ending angle, 7th is the color, 8th is the tickness
(if it is <0 ellipse will be filled), last two arguments are the same as in cvLine.
Desenha uma elipse, primeiro argumento é o ponteiro para a imagem, 2° é o centro da elipse,
3° é o tamanho dos eixos da elipse, 4° angulo da elipse, 5° angulo inicial da elipse, 6° angulo final
,7° cor, ultimos 3 parametros igual ao do cvCircle
*/
cvShowImage("Drawing",cool);
cvSaveImage( "output.jpg", cool );
cvWaitKey(0);
cvDestroyWindow("Drawing");
cvReleaseImage(&cool);
return 0;
}
Resultado:

Output.jpg



