#include "highgui.h" #include "cv.h" #include <iostream> #include <iomanip> using namespace std; #define thickness 2//线条粗细 #define line_type CV_AA//抗锯型直线 int main() { CvScalar color=CV_RGB(255,158,97);//按RGB顺序排列 CvPoint pt1_Rect,pt2_Rect;//确定对角线上的两点 CvPoint center;//确定笑脸中心 int radius=0;//笑脸的半径 //Eye 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; //Mouth 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; //画图初始化 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(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(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; end_angle_eye=360; cvEllipse(img,center_l_eye,axes_eye,angle_l_eye,start_angle_eye,end_angle_eye, color,CV_FILLED,line_type,0);//画左眼 cvEllipse(img,center_r_eye,axes_eye,angle_r_eye,start_angle_eye,end_angle_eye, color,CV_FILLED,line_type,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); cvSaveImage("smile.jpg",img); cvReleaseImage(&img); }
【OpenCV学习】用绘图函数画一个奥运志愿者笑脸徽章
内容版权声明:除非注明,否则皆为本站原创文章。