资源简介

camshift+kalman视频跟踪matlab代码,主要是对人脸的识别跟踪,也可以自己拍些合适的视频测试,last.m是主函数,程序是通的,下载就能使用。

资源截图

代码片段和文件信息

%% *************************************************************************************** %%
%% Face Detection and Tracking 
%% This example shows how to automatically detect and track a face.
%% Adopt Algorithm: Camshift
%% Author: Zhang Changchun
%% Email:zhangchangchun1989@163.com
%% Date :10/07/2015
%% *************************************************************************************** %%

clear all; 
clc
close all
closepreview %%关闭视频预览窗口

faceDetector = vision.CascadeobjectDetector();%%人脸检测利用Matlab计算机视觉工具箱自带的vision.CascadeobjectDetector();
%videoFileReader = vision.VideoFileReader(‘visionface.avi‘);
%videoframe      = step(videoFileReader);
%bbox            = step(faceDetector videoframe);

 obj = VideoReader(‘zn1.avi‘);
 Image1 = read(obj1);
 bbox = step(faceDetectorImage1);
 numberofframes = obj.NumberOfframes;
% get search window for first frame

        
cmin = round(bbox(11));
cmax = round(bbox(11)+bbox(14));
rmin = round(bbox(12));
rmax = round(bbox(12)+bbox(13));
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

for n = 1:numberofframes
     I=read(objn); % 依次读入各帧图像
     
      % 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)

        probmap = zeros(rows cols);
    for r=1:rows
        for c=1:cols
            if(hue(rc) ~= 0)
                probmap(rc)= histogram(hue(rc));   
            end
        end  
    end
    probmap = probmap/max(max(probmap));
    probmap = probmap*255;
    
    count = 0;
    
    rowcenter = 0;  % any number just so it runs through at least twice
    colcenter = 0;
    rowcenterold = 30;
    colcenterold = 30;
    % Mean Shift for 15 iterations or until convergence(the center doesnt
    % change)
    
     while (((abs(rowcenter - rowcenterold) > 10) && (abs(colcenter - colcenterold) > 10)) || (count < 15) )
    %for j = 1:5
        %disp(‘meanshift‘);
       % disp(j);
        rmin = rmin - 20;  %increase window size and check for center
        rmax = rmax + 20;
        cmin = cmin - 20;
        cmax = cmax + 20;
        
        rowcenterold = rowcenter; %save old center for convergence check
        colcenterold = colcenter;
        
        [ rowcenter colcenter M00 ] = meanshift(I rmin rmax cmin...
            cmax probmap);
        % given image (I) search window(rmin rmax cmin cmax)
        % r

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4763  2015-11-15 16:55  last_edition\camshift.m

     文件       5432  2015-10-07 15:53  last_edition\cam_kal.m

     文件        848  2005-04-25 19:29  last_edition\gaussian_prob.m

     文件      22580  2015-10-07 19:28  last_edition\hs_err_pid4480.log

     文件       2899  2002-05-29 11:59  last_edition\kalman_filter.m

     文件       1584  2002-05-29 11:59  last_edition\kalman_smoother.m

     文件       1840  2002-05-29 11:59  last_edition\kalman_update.m

     文件       5564  2015-11-15 17:02  last_edition\last.m

     文件       1272  2013-10-23 19:52  last_edition\meanshift.m

     文件        524  2005-04-25 19:29  last_edition\sample_gaussian.m

     文件       1797  2008-05-06 18:20  last_edition\sample_lds.m

     文件       1199  2002-05-29 11:59  last_edition\smooth_update.m

     文件    2320584  2011-11-14 14:42  last_edition\visionface.avi

     目录          0  2016-03-26 23:26  last_edition

----------- ---------  ---------- -----  ----

              2370886                    14


评论

共有 条评论