SVM目标识别分类基于MATLAB的SVM移动目标识别和分类仿真

Posted fpga&matlab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SVM目标识别分类基于MATLAB的SVM移动目标识别和分类仿真相关的知识,希望对你有一定的参考价值。

1.软件版本

matlab2017b

2.部分核心代码

clc;
clear;
close all;
warning off;


video          = mmreader('vedios\\test21.avi');
nFrames        = video.NumberOfFrames; %得到帧数
H              = video.Height;         %得到高度
W              = video.Width;          %得到宽度
Rate           = video.FrameRate;
mov(1:nFrames) = struct('cdata',zeros(H,W,3,'uint8'),'colormap',[]);




Npix           = [video.Width video.Height];
F_update       = [1 0 1 0; 
                  0 1 0 1; 
                  0 0 1 0; 
                  0 0 0 1];

Npop           = 5000;

Xstd_rgb = 50;
Xstd_pos = 25;
Xstd_vec = 5;

Xrgb_trgt = [255; 255; 255];

X = func_create_particles(Npix,Npop);





%%
%SVM预先训练
[svmModel1,svmModel2]=func_SVM_Train();






Xtrack=cell(1,nFrames);
Ytrack=cell(1,nFrames);
%read one frame every time

Xview=[];
Yview=[];





for i = 340:nFrames-10
    i
    Vedios       = read(video,i);
    
    
    P1           = im2double(rgb2gray(read(video,i)));
    P2           = im2double(rgb2gray(read(video,i+1)));
    P3           = im2double(rgb2gray(read(video,i+2)));

    [Pd,X]       = func_tracking(P1,P2,P3,X,F_update,Xstd_pos,Xstd_vec,Xstd_rgb,Xrgb_trgt);
    
    %跟踪效果显示
    [P3,Ss,Xd,Yd]= func_track(Vedios,Pd);
    
    %基于SVM进行分类
    %获得面积
    C1 = [];
    C2 = [];
    C  = [];
    
    if isempty(Ss) == 0;
       for jj = 1:length(Ss)
           %对面积进行识别
           C1 = svmclassify(svmModel1,Ss(jj),'showplot',false);  
           C2 = svmclassify(svmModel2,Ss(jj),'showplot',false);   
           if C1 == 'false'
              C(jj) = 1;
           end
           if C1 == 'true'
               if C2 == 'false'
                  C(jj) = 2;
               end
               if C2 == 'true'
                  C(jj) = 3;
               end    
           end    
       end
    end
    
%      Ss
%     C
    
    
    [P4,Ss,Xd,Yd,Xt,Yt] = func_track2(Vedios,Pd,Ss,C);
    
    Xtracki=[Xd];
    Ytracki=[Yd];
    

    figure(1);
    subplot(221);
    imshow(P1);
    title('原始视频');
    subplot(222);
    image(Vedios);
    hold on
    plot(X(2,1:1:end), X(1,1:1:end), '.')
    hold off
    title('粒子滤波跟踪');
    
    subplot(223);
    %跟踪效果
    imshow(Pd);
    title('跟踪效果');
    
    subplot(224);
    %跟踪效果
    imshow(P4);
    title('跟踪效果');  
    for jj = 1:length(C)
        if C(jj)==1
           text(Yt(jj),Xt(jj),'People');
        end
        if C(jj)==2
           text(Yt(jj),Xt(jj),'Electric');
        end
        if C(jj)==3
           text(Yt(jj),Xt(jj),'Car');
        end
    end
    hold on
 
    hold on
    
    
    
end










function [svmModel1,svmModel2]=func_SVM_Train();

M          = 3;
N          = 1000;
trainData  = M*rand(1,N);     
for i = 1:length(trainData);
    if trainData(i)<=0.5
       trainLabel1(i) = 0;%人
    end
    if trainData(i)>0.5
       trainLabel1(i) = 1;
    end         
end
trainLabel1s = nominal(ismember(trainLabel1,1));   

for i = 1:length(trainData);
    if trainData(i)<=1.8
       trainLabel2(i) = 0;
    end    
    if trainData(i)>1.8
       trainLabel2(i) = 1;
    end        
end
trainLabel2s = nominal(ismember(trainLabel2,1));   
           
svmModel1   = svmtrain(trainData, trainLabel1s,'kernel_function','rbf' ,'showplot',false);
svmModel2   = svmtrain(trainData, trainLabel2s,'kernel_function','rbf' ,'showplot',false);

3.操作步骤与仿真结论

 

4.参考文献 

A10-42

6.完整源码获得方式

方式1:微信或者QQ联系博主

方式2:订阅MATLAB/FPGA教程,免费获得教程案例以及任意2份完整源码

创作挑战赛 新人创作奖励来咯,坚持创作打卡瓜分现金大奖

以上是关于SVM目标识别分类基于MATLAB的SVM移动目标识别和分类仿真的主要内容,如果未能解决你的问题,请参考以下文章

基于SVM支持向量机的彩色图像目标分割算法matlab仿真

matlab利用hinge loss实现多分类SVM

SVM预测基于SVM进行股票预测matlab源码

第十八节基于传统图像处理的目标检测与识别(HOG+SVM附代码)

SVM分类基于matlab鸽群算法优化支持向量机SVM分类含Matlab源码 2242期

疾病识别基于matlab GUI SVM农作物叶子虫害识别与分类含Matlab源码 1322期