cvZero();是让矩阵的值都为0,有初始化的作用,或者说清零~
比如说:IplImage img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);%创建一幅图像
cvZero(img);%相当于初始化图片,值都为0,矩阵大小为640*480
cvShowImage("img",img);%就显示一幅黑色,且值都为零的图像
cvCircle(CvArr* img , CvPoint center , int radius , CvScalar color , int thickness=1 , int lineType=8 , int shift=0 )
img为图像指针,单通道多通道都行,不需要特殊要求
center为画圆的圆心坐标
radius为圆的半径
color为设定圆的颜色,比如用CV_RGB(255, 0,0)设置为红色
thickness为设置圆线条的粗细,值越大则线条越粗,为负数则是填充效果
1: #include "stdafx.h"
2: #include "opencv2/opencv.hpp"
3: #include "opencv2/opencv_modules.hpp"
4: #include "cv.h"
5: #include "cxcore.h"
6: #include "highgui.h"
7:
8: #define RaderImageWdith 720
9: #define RaderImageHeight 720
10:
11:
12: /*******************从文件中读取一副图像并在屏幕中显示***********************/
13: int main()
14:
{
15: /*********************雷达数据处理*********************/
16:
IplImage* RaderImage = cvCreateImage(cvSize(RaderImageWdith,RaderImageHeight),IPL_DEPTH_8U,1);
17:
cvZero(RaderImage);
18: int dx = RaderImageWdith/2;
19: int dy = RaderImageHeight*3/4;
20:
cvCircle(RaderImage, cvPoint(dx,dy),3, CV_RGB(0,255,255), -1, 8,0);
21: cvShowImage( "RaderImage" ,RaderImage);
22:
23:
24:
25:
26:
27:
28:
29:
30: //定义一个字符指针,并指向图片所在的位置
31: char *PFileName;
32: PFileName = "D:\\Pictures\\parrot.jpg" ;
33: //读取一张图片并载入内存,并用一个数据结构指针指向这张图片
34:
IplImage *Img = cvLoadImage(PFileName);
35: if (NULL == Img) //如果读入失败,退出程序
36:
exit(1);
37: //创建一个窗体,标题为Example,自增益
38: cvNamedWindow( "Example" ,1);
39:
40: //用指针指向图像的数据区头部
41:
uchar *pchar;
42: int width = Img ->width; //读取图像宽度
43: int height = Img ->height; //读取图像高度
44: int channel = Img ->nChannels; //读取图像的通道数
45: int widthStep = Img ->widthStep; //读取图像一行像素所占的字节数
46: int i,j;
47: for (i = 0; i < height ; i++) //以下是遍历一副图像中的每个像素点
48:
{
49:
pchar = (uchar*)Img ->imageData + i * widthStep;
50: for (j = 0; j < width; j++)
51:
{
52:
uchar *temp = pchar + j * channel;
53: temp[0] += 10; //通道B
54: temp[1] += 10; //通道G
55: temp[2] += 10; //通道R
56:
}
57:
}
58: //在窗口中显示这张图片
59: cvShowImage( "Example" ,Img);
60: //暂停程序,等待用户触发一个按键
61:
cvWaitKey(0);
62: //释放图像所分配的内存空间
63:
cvReleaseImage(&Img);
64: //销毁窗口
65: cvDestroyWindow( "Example" );
66: return 0;
67:
}