Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Left-Right Hand detection using K-Nearest Neighbor Classifier | MATLAB--Complete Project (with code)

%Code for extracting features and train the knn model:

%Code to train the model:

clc;

clear all;

close all;

warning off;

net=alexnet;

layers=net.Layers;

featureLayer='fc7';

imds=imageDatastore('Training','IncludeSubFolders',true,'LabelSource','foldernames');

trainingLabels=imds.Labels;      

inputSize = net.Layers(1).InputSize;

augimdsTrain = augmentedImageDatastore(inputSize(1:2),imds);

featuresTrain = activations(net,augimdsTrain,featureLayer,'OutputAs','rows');

classifier=fitcknn(featuresTrain,trainingLabels,'NumNeighbors',5,'Standardize',1);

save classifier classifier

 

 

 

%Code for Testing:

clc

clear all

close all

warning off

c=webcam;

load classifier;

net=alexnet;

featureLayer='fc7';

while true

    e=c.snapshot;

    ab=imresize(e,[227 227]);

    featuresTrain = activations(net,ab,featureLayer,'OutputAs','rows');

    gs=predict(classifier,featuresTrain);

    imshow(e);

    title(char(gs));

    ax = gca;

    ax.TitleFontSizeMultiplier =1.5;

    drawnow;

end



 %Code to create Database:

 

clc

clear all

close all

warning off;

cao=webcam;

c=200;

temp=0;

while temp<=200

    e=cao.snapshot;

    filename=strcat(num2str(temp),'.bmp');

    imwrite(e,filename);

    temp=temp+1;

    imshow(e);

    drawnow;

end

 

 



Join us on Telegram: https://t.me/matlabcastor

No comments

Popular Posts

Followers