#include#include#include#include#in"> #include#include#include#include#in" />
Opencv视频运动跟踪代码.docx

Opencv视频运动跟踪代码.docx

ID:58676500

大小:11.59 KB

页数:4页

时间:2020-10-15

Opencv视频运动跟踪代码.docx_第1页
Opencv视频运动跟踪代码.docx_第2页
Opencv视频运动跟踪代码.docx_第3页
Opencv视频运动跟踪代码.docx_第4页
资源描述:

《Opencv视频运动跟踪代码.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include"cv.h"#include"highgui.h"#include#include#include#include#include#include#include//跟踪参数constdoubleMHI_DURATION=0.5;//最大跟踪时间constdoubleMAX_TIME_DELTA=0.5;constdoubleMIN_TIME_DELTA=0.05;constintN=3;constintC

2、ONTOUR_MAX_AERA=100;//矩形面积IplImage**buf=0;intlast=0;intflag;IplImage*mhi=0;//MHI:motionhistoryimageCvConnectedComp*cur_comp,min_comp;CvConnectedCompcomp;CvMemStorage*storage;CvPointpt[4];//img–输入视频帧//dst–检测结果voidupdate_mhi(IplImage*img,IplImage*dst,intdiff_threshold){doubletimest

3、amp=clock()/100.;//获取当前时间CvSizesize=cvSize(img->width,img->height);inti,idx1,idx2;IplImage*silh;IplImage*pyr=cvCreateImage(cvSize((size.width&-2)/2,(size.height&-2)/2),8,1);CvMemStorage*stor;CvSeq*cont;if(!mhi

4、

5、mhi->width!=size.width

6、

7、mhi->height!=size.height){if(buf==0){buf=(Ipl

8、Image**)malloc(N*sizeof(buf[0]));//动态内存分配memset(buf,0,N*sizeof(buf[0]));}for(i=0;i

9、AY);//rgb->grayidx1=last;idx2=(last+1)%N;last=idx2;//做帧差silh=buf[idx2];cvAbsDiff(buf[idx1],buf[idx2],silh);//两帧差异//对差图像做二值化cvThreshold(silh,silh,30,255,CV_THRESH_BINARY);//src(x,y)>threshold,dst(x,y)=max_value;否则,dst(x,y)=0;cvUpdateMotionHistory(silh,mhi,timestamp,MHI_DURATION);/

10、/更新像素点的运动历史cvCvtScale(mhi,dst,255./MHI_DURATION,(MHI_DURATION-timestamp)*255./MHI_DURATION);//timestamp是时间戳;MHI_DURATION,获得的是当前时间cvCvtScale(mhi,dst,255./MHI_DURATION,0);//中值滤波,消除小的噪声cvSmooth(dst,dst,CV_MEDIAN,3,0,0,0);//向下采样,去掉噪声cvPyrDown(dst,pyr,7);cvDilate(pyr,pyr,0,1);//做膨胀操作,

11、消除目标的不连续空洞cvPyrUp(pyr,dst,7);////下面的程序段用来找到轮廓////Createdynamicstructureandsequence.stor=cvCreateMemStorage(0);cont=cvCreateSeq(CV_SEQ_ELTYPE_POINT,sizeof(CvSeq),sizeof(CvPoint),stor);//找到所有轮廓cvFindContours(dst,stor,&cont,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE,cvPoi

12、nt(0,0));//直接使用CONTOUR中的矩形来画轮廓for(;cont;

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。