資源描述:
《運(yùn)動(dòng)目標(biāo)跟蹤及檢測(cè)源代碼(camshift 算法)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、該運(yùn)行文件在VC6.0環(huán)境下編譯通過,是一個(gè)stand-alone運(yùn)行程序,不需要OPENCV的DLL庫(kù)支持。在運(yùn)行之前,請(qǐng)先連接好USB接口的攝像頭。然后可以用鼠標(biāo)選定欲跟蹤目標(biāo)。#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返回的區(qū)域box,帶角度CvConnectedComptrack_comp;inthdims=48;????//劃分HIST的個(gè)數(shù),越高越精確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#鼠標(biāo)的選擇區(qū)域:");????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;#