台灣最大程式設計社群網站
線上人數
1794
 
會員總數:241166
討論主題:186825
歡迎您免費加入會員
討論區列表 >> 其他語言 >> matlab 人臉辨識(用Nearest Neighbor)
[ 變換順序 ]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
matlab 人臉辨識(用Nearest Neighbor)
價值 : 40 QP  點閱數:128 回應數:0

樓主

Sanji
門外漢
0 23
335 62
發送站內信

總共有38個人,每個人有65張照片

training set 是每個人的前35張照片
testing set 是剩下的照片

要計算
SAD(sum of absolute distance)
SSD(sum of square distance)
的準確度

讀檔的部分是沒有問題的
目前小弟已經寫了一個做法:
clear

% Read File
directory = dir(); % directory record name,folder(folderpath),date,bytes,isdir,datanum
first = true;
correct_sad = 0;
correct_ssd = 0;
testcnt = 0;

for i = 4:41 %training
foldername = directory(i).name; % foldername is every folder that we wanted
file = dir([foldername '\*.pgm']); % get all data in the folder
for j = 1:35
filename = file(j).name; % get first 35 pgm file to be the training file ex:xxx.pgm
X = imread([foldername '\' filename]);
if first
allPic = X(:)';
first = false;
else
allPic = [allPic; X(:)'];
end
% printf("\n");
end
end



for i = 4:41 %testing
foldername = directory(i).name;
file = dir([foldername '\*.pgm']);
for k = 36:size(file,1) - 1
filename = file(k).name;
% fprintf('%s',filename);
X = imread([foldername '\' filename]);
test_file = X(:)';
who = nn_sad(allPic, test_file); %sad
if (ceil(who/35.0) + 3) == i
correct_sad = correct_sad + 1;
end
who = nn_ssd(allPic, test_file); %ssd
if (ceil(who/35.0) + 3) == i
correct_ssd = correct_ssd + 1;
end
testcnt = testcnt + 1;
end
end

fprintf('NN_SAD:%f%%\n',double(correct_sad / testcnt) * 100);
fprintf('NN_SSD:%f%%\n',double(correct_ssd / testcnt) * 100);

% a = abs(int16(allPic(2, :)) - int16(test_file));

function who = nn_sad(allPic, test_file)
mindis = sum(abs(int16(allPic(1, :)) - int16(test_file)));
who = 1;
for i=1:size(allPic,1)
dis = sum(abs(int16(allPic(i, :)) - int16(test_file)));
if mindis > dis
who = i;
mindis = dis;
end
end
end

function who = nn_ssd(allPic, test_file)
% mindis = (int16(allPic(1, :)) - int16(test_file)) * (int16(allPic(1, :)) - int16(test_file))';
mindis = sum((int16(allPic(1, :)) - int16(test_file)).^2);
who = 1;
for i=1:size(allPic,1)
dis = sum((int16(allPic(i, :)) - int16(test_file)).^2);
if mindis > dis
who = i;
mindis = dis;
end
end
end


output:
NN_SAD:45.110701%
NN_SSD:46.217712%


可是不知道這個做法正不正確
請求各位大大幫我看一下


搜尋相關Tags的文章: [ matlab ] , [ 人臉辨識 ] , [ SAD ] , [ NN ] ,
本篇文章發表於2017-10-31 01:23
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
[ 變換順序 ]   

回覆
如要回應,請先登入.