资源描述:
《运动目标跟踪及检测源代码(camshift 算法)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、该运行文件在VC6.0环境下编译通过,是一个stand-alone运行程序,不需要OPENCV的DLL库支持。在运行之前,请先连接好USB接口的摄像头。然后可以用鼠标选定欲跟踪目标。#ifdef_CH_#pragmapackage#endif#ifndef_EiC#include"cv.h"#include"highgui.h"#include#include#endifIplImage*image=0,*hsv=0,*hue=0,*mask=0,*backproject=0,*histimg=0;Cv
2、Histogram*hist=0;intbackproject_mode=0;intselect_object=0;inttrack_object=0;intshow_hist=1; CvPointorigin;CvRectselection;CvRecttrack_window;CvBox2Dtrack_box; //tracking返回的区域box,带角度CvConnectedComptrack_comp;inthdims=48; //划分HIST的个数,越高越精确floathranges_arr[]={0,180};float*hrange
3、s=hranges_arr;intvmin=10,vmax=256,smin=30;voidon_mouse(intevent,intx,inty,intflags){ if(!image) return; if(image->origin) y=image->height-y; if(select_object) { selection.x=MIN(x,origin.x); selection.y=MIN(y,origin.y); selection.width=selecti
4、on.x+CV_IABS(x-origin.x); selection.height=selection.y+CV_IABS(y-origin.y); selection.x=MAX(selection.x,0); selection.y=MAX(selection.y,0); selection.width=MIN(selection.width,image->width); selection.height=MIN(selection.height,image->height
5、); selection.width-=selection.x; selection.height-=selection.y; } switch(event) { caseCV_EVENT_LBUTTONDOWN: origin=cvPoint(x,y); selection=cvRect(x,y,0,0); select_object=1; break; caseCV_EVENT_LBUTTONUP: select_object=0; i
6、f(selection.width>0&&selection.height>0) track_object=-1;#ifdef_DEBUG printf("/n#鼠标的选择区域:"); printf("/n X=%d,Y=%d,Width=%d,Height=%d", selection.x,selection.y,selection.width,selection.height);#endif break; }}CvScalarhsv2rgb(floathue){ intrgb[3],p,
7、sector; staticconstintsector_data[][3]= {{0,2,1},{1,2,0},{1,0,2},{2,0,1},{2,1,0},{0,1,2}}; hue*=0.033333333333333333333333333333333f; sector=cvFloor(hue); p=cvRound(255*(hue-sector)); p^=sector&1?255:0; rgb[sector_data[sector][0]]=255; rgb[sector_data[sector][
8、1]]=0; rgb[sector_data[sector][2]]=p;#