写了一个小程序,获得摄像头输出之后直接在上面画图。
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" #include "highgui.h" #include "cv.h" #include "stdio.h" #include <ctype.h> int main(int argc,char ** argv) { int r=0; CvCapture *capture = 0; //从摄像头读取 capture = cvCaptureFromCAM(0); if(!capture) { fprintf(stderr,"Could not initialize capturing...\n"); return -1; } cvNamedWindow("Laplacian",1); //循环捕捉,直到用户按键跳出循环体 for(;;) { IplImage * frame =0; //抓起一祯 frame = cvQueryFrame(capture); if(!frame) break; r>20?r=0:r++; //画一个圈 cvCircle(frame,cvPoint(frame->width / 2,frame->height /2 ), 45+abs(10-r), CV_RGB(150, 100,100), 4, 8, 0); cvShowImage("Laplacian",frame); if(cvWaitKey(10)>0) break; } cvReleaseCapture(&capture); cvDestroyWindow("Laplacian"); return 0; }
参考:
1.http://blog.163.com/yuhua_kui/blog/static/9679964420141104385570/ OpenCV cvCircle函数
2.http://wiki.opencv.org.cn/index.php/Cxcore%E7%BB%98%E5%9B%BE%E5%87%BD%E6%95%B0 Cxcore绘图函数