clc;
clear all;
close all;
%% 使用SVM做识别,测试准确率
% Files = dir(fullfile('.\Car','*.jpg'));
file_path = 'E:/matlab_0808/0816/people1/';% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
CarNum = length(img_path_list);%获取图像总数量
% Files = dir(fullfile('.\Car2','*.png'));
% CarNum = length(Files);
CarFea=[];
for i = 1:CarNum
image_name = img_path_list(i).name;% 图像名
Img = imread(strcat(file_path,image_name));
imggray = rgb2gray(Img);
[m,n] = size(imggray);
H2=lbp(imggray);
H2fea = (H2-min(H2))/(max(H2)-min(H2));
CarFea=[CarFea;H2fea];
end
%Files = dir(fullfile('.\Tank3','*.jpg'));
file_path = 'E:/matlab_0808/0816/other/';% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
TankNum = length(img_path_list);%获取图像总数量
TankFea=[];
for i = 1:TankNum
image_name = img_path_list(i).name;% 图像名
Img = imread(strcat(file_path,image_name));
imggray = rgb2gray(Img);
[m,n] = size(imggray);
H2=lbp(imggray);
H2fea = (H2-min(H2))/(max(H2)-min(H2));
TankFea=[TankFea;H2fea];
end
dataFea = [CarFea;TankFea];
Group = [0*ones(CarNum,1); 1*ones(TankNum,1)];
%classifer = fitcecoc(dataFea,Group);
% SVM train
svmStr = svmtrain(dataFea,Group,'kernel_function','linear','showplot',true);
k1=1;
for j=20:50
name=num2str(j);
name1=strcat('E:/matlab_0808/0816/test_people_other/',name);
Img2 = imread(strcat(name1,'.jpg'));
imggray2 = rgb2gray(Img2);
[m,n] = size(imggray2);
H21=lbp(imggray2);
H2fea1 = (H21-min(H21))/(max(H21)-min(H21));
pgroup(k1) = svmclassify(svmStr,H2fea1,'Showplot',true); % svm预测
k1=k1+1;
end
i=1;
for k=71:100
name=num2str(k);
name1=strcat('E:/matlab_0808/0816/test_people_other/',name);
Img2 = imread(strcat(name1,'.jpg'));
imggray2 = rgb2gray(Img2);
[m,n] = size(imggray2);
H21=lbp(imggray2);
H2fea1 = (H21-min(H21))/(max(H21)-min(H21));
pgroup1(i) = svmclassify(svmStr,H2fea1,'Showplot',true); % svm预测
i=i+1;
%pgroup1(k) = svmclassify(svmStr,H2fea1,'Showplot',true); % svm预测
end