基于opencv的计算机视觉技术实现 第五章节第一个程序 改错
2017-02-13 18:25
741 查看
在5.1中,程序是要调用cvCircle,cvEllipse,cvLine等函数实现下面的笑脸:
但是源程序给出的结果如下:
代码如下:
#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);
}
分析一下,错误出现在这里:
start_angle_mouth=150.;
end_angle_mouth=347.;
angle_mouth=10.;
绘制出来的圆弧是反方向的,因此需要将各个值的大小变为负向。
即:
start_angle_mouth=-150.;
end_angle_mouth=-347.;
angle_mouth=-10.;
才是正确的结果。
但是源程序给出的结果如下:
代码如下:
#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);
}
分析一下,错误出现在这里:
start_angle_mouth=150.;
end_angle_mouth=347.;
angle_mouth=10.;
绘制出来的圆弧是反方向的,因此需要将各个值的大小变为负向。
即:
start_angle_mouth=-150.;
end_angle_mouth=-347.;
angle_mouth=-10.;
才是正确的结果。
相关文章推荐
- 【计算机视觉】 完全基于opencv的双目景深与测距的实现
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于WS-MEX的实现](提供模拟程序)
- 练练手,近期实现的一个基于alpha-beta剪枝技术的机器人“追逐”程序
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于WS-MEX的实现](提供模拟程序)
- opencv2实现多张图片路线路牌(直线和圆)检测并将处理后的图片合成视频_计算机视觉大作业2
- 用C语言编写函数实现一个整数计算机,程序接受三个参数,第一个参数为操作项,后两个参数为操作数。
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序)
- 计算机视觉算法开源实现 代码程序 Computer Vision Algorithm Implementations
- 使用WPF技术实现基于MSN协议的五子棋程序
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序)
- [置顶] 基于DL的计算机视觉(2)--实现图像分类最简单的方法:KNN
- 基于计算机视觉的水果分级技术研究进展
- opencv2实现多张图片路线路牌检测_计算机视觉大作业2
- 基于android平台的视觉检测智能相机的实现-opencv4android的应用
- 使用WPF技术实现基于MSN协议的五子棋程序
- 视频监控 形态学 OpenCV致力于计算机视觉技术研究(高密度环境下行人检测和统计)
- opencv2实现n张图像拼接_stitcher具体之代码1_计算机视觉大作业1
- 基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写
- 用C语言编写函数实现一个整数计算机,程序接受三个参数,第一个参数为操作项,后两个参数为操作数。
- 基于directshow技术实现的录音程序