【OpenCV学习】用绘图函数画一个奥运志愿者笑脸徽章

简介:
#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);
}

本文转自gnuhpc博客园博客,原文链接:http://www.cnblogs.com/gnuhpc/archive/2012/06/30/2571323.html,如需转载请自行联系原作者
相关文章
|
2月前
|
存储 资源调度 算法
Opencv(C++)系列学习---SIFT、SURF、ORB算子特征检测
Opencv(C++)系列学习---SIFT、SURF、ORB算子特征检测
|
3月前
|
机器学习/深度学习 算法 数据可视化
计算机视觉+深度学习+机器学习+opencv+目标检测跟踪+一站式学习(代码+视频+PPT)-2
计算机视觉+深度学习+机器学习+opencv+目标检测跟踪+一站式学习(代码+视频+PPT)
100 0
|
3月前
|
机器学习/深度学习 Ubuntu Linux
计算机视觉+深度学习+机器学习+opencv+目标检测跟踪+一站式学习(代码+视频+PPT)-1
计算机视觉+深度学习+机器学习+opencv+目标检测跟踪+一站式学习(代码+视频+PPT)
56 1
|
2月前
|
算法 C++ 计算机视觉
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
Opencv(C++)学习系列---Laplacian拉普拉斯边缘检测算法
|
2月前
|
算法 计算机视觉 C++
Opencv(C++)学习系列---Sobel索贝尔算子边缘检测
Opencv(C++)学习系列---Sobel索贝尔算子边缘检测
|
2月前
|
算法 C++ 计算机视觉
Opencv(C++)学习系列---Canny边缘检测算法
Opencv(C++)学习系列---Canny边缘检测算法
|
2月前
|
存储 计算机视觉 C++
Opencv(C++)学习系列---特征点检测和匹配
Opencv(C++)学习系列---特征点检测和匹配
|
2月前
|
算法 测试技术 计算机视觉
Opencv(C++)系列学习---opencv_contrib安装
Opencv(C++)系列学习---opencv_contrib安装
|
2月前
|
C++ 计算机视觉
Opencv(C++)系列学习---读取视频文件和打开摄像头
Opencv(C++)系列学习---读取视频文件和打开摄像头
|
2月前
|
存储 计算机视觉 C++
Opencv (C++)系列学习---模板匹配
Opencv (C++)系列学习---模板匹配