資源簡介
先對第一幀圖像用鼠標框選跟蹤區域,雙擊后開始自動跟蹤。代碼可以修改來處理圖片序列。

代碼片段和文件信息
%?Adam?Kukucka
%?Zach?Clay
%?Marcelo?Molina????
%?CSE?486?Project?3
%function?[?trackmov?probmov?centers?]?=?camshift?
%?******************************************************************
%?initialize?vari???ables
%?******************************************************************
rmin?=?0;?%min?row?value?for?search?window
rmax?=?0;?%max?row?value?for?search?window
cmin?=?0;?%min?col?value?for?search?window
cmax?=?0;?%max?col?value?for?search?window
numofframes?=?144;?%number?of?frames?in?the?avi
threshold?=?1;?%threshold?for?convergence
centerold?=?[0?0];?%for?convergence...?previous?center?of?window
centernew?=?[0?0];?%for?convergence...?new?center?of?window
%?******************************************************************
%?Pre?code...?load?movie?and?select?initial?frame
%?******************************************************************
%?prompt?user?for?avi?file?name
%user_entry?=?input(‘Please?enter?an?avi?filename:?‘‘s‘);
%?load?the?avi?file...?handle?is?M?
%?avi?=?VideoReader(‘E:\數據庫\視頻\in_1.AVI‘);
%?numberofframes?=?avi.NumberOfframes;
?numberofframes=610;
%?get?number?of?frames
%?initialize?matrix?to?hold?center?coordinates
imagecenters?=?zeros(numofframes?2);
%?extract?the?first?frame?from?the?avi
%?Image1?=?read(avi1);
Image1?=?imread(‘E:\數據庫\視頻\Walk1Data\46.jpg‘);
%%%?**********?images(:?:?numberofframes)?=?G(::);
%?get?search?window?for?first?frame
[picrec]=imcrop(Image1);
%[?cmin?cmax?rmin?rmax?]?=?select(?Image1);
cmin?=?round(rec(11));
cmax?=?round(rec(11)+rec(13));
rmin?=?round(rec(12));
rmax?=?round(rec(12)+rec(14));
wsize(1)?=?abs(rmax?-?rmin);
wsize(2)?=?abs(cmax?-?cmin);
%?create?histogram
%?translate?to?hsv
hsvimage?=?rgb2hsv(Image1);
%?pull?out?the?h
huenorm?=?hsvimage(::1);
%?scale?to?0?to?255
hue?=?huenorm*255;
%?set?unit?type
hue=uint8(hue);
%?Getting?Histogram?of?Image:
histogram?=?zeros(256);
for?i=rmin:rmax
????for?j=cmin:cmax
????????index?=?uint8(hue(ij)+1);???
????????%count?number?of?each?pixel
????????histogram(index)?=?histogram(index)?+?1;
????end
end
%?******************************************************************
%?Algorithm?from?pdf
%?******************************************************************
%?aviobj1?=?avifile(‘2.avi‘);
%?aviobj2?=?avifile(‘3.avi‘);
%?for?each?frame
for?n?=?46:numberofframes
????frame=strcat(‘E:\數據庫\視頻\Walk1Data\‘num2str(n)‘.jpg‘);
????I=imread(frame);??%?依次讀入各幀圖像
%?????I=read(avin);
???
????%?translate?to?hsv
????hsvimage?=?rgb2hsv(I);
????%?pull?out?the?h
????huenorm?=?hsvimage(::1);
????%?scale?to?0?to?255
????hue?=?huenorm*255;
????%?set?unit?type
????hue=uint8(hue);
????
????
????
????[rows?cols]?=?size(hue);
????
????%?choose?initial?search?window
????%?the?search?window?is?(cmin?rmin)?to?(cmax?rmax)
????
????
????%?create?a?probability?map
????probmap?=?zeros(rows?cols);
????for?r=1:rows
????????for?c=1:cols
????????????if(hue(rc)?~=?0)
????????????????probmap(rc)=?histogram(hue(rc));???
????????????end
????????end??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1272??2013-10-23?19:52??meanshift.m
?????文件???????6062??2013-10-24?10:03??camshift.m
-----------?---------??----------?-----??----
?????????????????7334????????????????????2
- 上一篇:逆變器下垂控制simuli
nk仿真程序 - 下一篇:近鄰傳播聚類-MATLAB程序
評論
共有 條評論