Demo entry 6632998

gesture detection code

   

Submitted by anonymous on Jul 31, 2017 at 11:09
Language: Matlab. Code size: 1.5 kB.

clear; close all; clc;

datapath = 'data/clean_image/';
image_list = dir(strcat(datapath,'*.bmp'));
labels = ones(size(image_list,1),1);
labels(end-13:end) = -1;

%% feature calculation
for m = 1:size(image_list,1)
    I = rgb2gray(imread(strcat(datapath,image_list(m).name)));
    % I_temp = imResample(single(I),[size(I,1)/10, size(I,2)/10])/255;
%     I_temp = imResample(double(I),[size(I,1)/20, size(I,2)/40])/255;
    I_temp = imResample(double(I),[38, 8])/255;
%     im(I_temp);
    I_temp = reshape(I_temp,[1,size(I_temp,1)*size(I_temp,2)]);  
    if(m == 1)
        I_smps = zeros(0,size(I_temp,2));
    end
    I_smps = [I_smps;I_temp];
end

%% SVM train
gesture_model = libsvmtrain(labels,I_smps,'-w-1 3');
save('gesture_model.mat','gesture_model');
% model = libsvmtrain(labels,I_smps);

%% SVM test
load('gesture_model.mat');
datapath = 'data/clean_extra_image/';
image_list = dir(strcat(datapath,'*.bmp'));
labels = ones(size(image_list,1),1);

for m = 1:size(image_list,1)
    I = imread(strcat(datapath,image_list(m).name));
    % I_temp = imResample(single(I),[size(I,1)/10, size(I,2)/10])/255;
    I_temp = imResample(double(I),[38, 8])/255;
%     im(I_temp);
    I_temp = reshape(I_temp,[1,size(I_temp,1)*size(I_temp,2)]);  
    if(m == 1)
        I_smps = zeros(0,size(I_temp,2));
    end
    I_smps = [I_smps;I_temp];
end

tic;
[predicted_label, accuracy, decision_values] = libsvmpredict(labels,I_smps,gesture_model);
toc;

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).