?? 5-1.cpp
字號:
//程序5-1 曲線與形狀繪制 即繪制了一個笑臉
///*
#include <highgui.h>
#include<cv.h>
#include<iostream.h>
#define thickness 2 //線條粗細
#define line_type CV_AA // CV_AA表示抗鋸齒類型直線
void main()
{
//CV_RGB( 255., 158., 97. )三個分量是按R,G,B順序排列的
CvScalar color=CV_RGB( 255., 158., 97. );
CvPoint pt1_Rect; //確定外圍矩形畫框的兩個點(對角線上兩個點)
CvPoint pt2_Rect;
CvPoint center; //圖像中心既是笑臉的中心
int radius=0; //笑臉的半徑
//---------------------眼睛有關的變量---------------------------------
CvPoint center_l_eye; //左眼的中心
CvPoint center_r_eye; //右眼的中心
CvSize axes_eye; //左右眼的大小
double angle_l_eye=15; //左眼的偏轉角:正的表示逆時針轉
double angle_r_eye=-15; //右眼的偏轉角:負數表示順時針轉
double start_angle_eye=0.;
double end_angle_eye=360.;
//---------------------嘴巴有關的變量-----------------------------------
CvPoint pt1_l_mouth; //笑嘴的嘴角的點
CvPoint pt2_l_mouth;
CvPoint pt1_r_mouth;
CvPoint pt2_r_mouth;
CvSize axes_mouth; //嘴的大小
double angle_mouth=0.; //嘴的偏轉角
double start_angle_mouth=0.; //畫嘴的圓弧的起始角
double end_angle_mouth=360.; //畫嘴的圓弧的終止角
//--------繪制笑臉的目的圖像img的初始化-------
IplImage* img = cvCreateImage( cvSize(600,600), IPL_DEPTH_8U, 3 );
cvNamedWindow( "image", CV_WINDOW_AUTOSIZE );
//----------------------------外圍矩形畫框---------------------------
pt1_Rect.x=0;
pt1_Rect.y=0;
pt2_Rect.x=600;
pt2_Rect.y=600;
color=CV_RGB( 97., 158., 255. );
//------------------- cvRectangle畫矩形-------------
cvRectangle(img, pt1_Rect, pt2_Rect, color, CV_FILLED, line_type, 0);
//----------------------------笑臉的輪廓---------------------------
color= CV_RGB ( 255., 158., 97. ); //顏色為黃色
center.x=300;
center.y=300;
radius=200; //笑臉半徑
//------------------- cvCircle畫圓形即為笑臉的輪廓-------------
cvCircle(img,center, radius, color, CV_FILLED, line_type, 0);
//----------------------------畫眼睛---------------------------
color= CV_RGB ( 156., 25., 255. ); //眼睛顏色為紫色
center_l_eye.x=240;
center_l_eye.y=200;
center_r_eye.x=360;
center_r_eye.y=200;
axes_eye.width=16;
axes_eye.height=30;
angle_l_eye=10;
angle_r_eye=-5;
start_angle_eye=0.; //繪制整個橢圓時起始角為0°,終止角為360°
end_angle_eye=360.;
//----------左眼----------- cvEllipse畫橢圓------------
cvEllipse(img, center_l_eye, axes_eye, angle_l_eye, start_angle_eye, end_angle_eye, color, CV_FILLED, line_type, 0);
//----------右眼----------- cvEllipse畫橢圓---------------
cvEllipse(img, center_r_eye, axes_eye, angle_r_eye, start_angle_eye, end_angle_eye, color, CV_FILLED, line_type, 0);
//----------------------------畫嘴巴---------------------------
color= CV_RGB ( 255., 255., 0. ); //嘴巴顏色為黃色
pt1_l_mouth.y=300;
pt1_l_mouth.x=150;
pt2_l_mouth.y=270;
pt2_l_mouth.x=180;
pt1_r_mouth.y=270;
pt1_r_mouth.x=400;
pt2_r_mouth.y=300;
pt2_r_mouth.x=430;
axes_mouth.width=130;
axes_mouth.height=100;
start_angle_mouth=150.;
end_angle_mouth=347.;
angle_mouth=10.;
//----左邊的嘴角的線段----
cvLine(img, pt1_l_mouth, pt2_l_mouth, color, 4, line_type, 0);
//---右邊的嘴角的線段---
cvLine(img, pt1_r_mouth, pt2_r_mouth, color, 4, line_type, 0);
//---嘴巴的圓弧----------
cvEllipse(img, center, axes_mouth, angle_mouth, start_angle_mouth, end_angle_mouth, color, 4, line_type, 0);
cvShowImage( "image", img );
cvWaitKey(0);
cvReleaseImage(&img);
}
//*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -