Üye
- 5 Şub 2019
- 20
- 9
- 33
[CODE title="Classification using KNN"]clc;clear;close all;warning off all;
load HOG_features
% imaqreset;
% vid = videoinput('winvideo', 1, 'YUY2_640x480');
% src = getselectedsource(vid);
% vid.FramesPerTrigger = Inf;
% vid.ReturnedColorspace = 'rgb';
% start(vid);
% preview(vid);
%% Get snapshot and process frame image
% h = msgbox('Show Sign !');
% uiwait(h);
%
% im = getsnapshot(vid);
[f,p] = uigetfile('*.*');
im = imread([p,f]);
imshow(im);
% stop(vid);
cform = makecform('srgb2lab');
J = applycform(im,cform);
K=J
,:,2);
L=graythresh(J
,:,2));
BW1=im2bw(J
,:,2),L);
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
pause(0.01)
gr = rgb2gray(im);
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
figure(2);imshow(object);
[feat] = hog_feature_vector(object);
class = knnclassify(feat,data,group);
switch class
case 0
tts('Sign of 0');
case 1
tts('Sign of 1');
case 2
tts('Sign of 2');
case 3
tts('Sign of 3');
case 4
tts('Sign of 4');
case 5
tts('Sign of 5');
case 6
tts('Sign of 6');
case 7
tts('Sign of 7');
case 8
tts('Sign of 8');
case 9
tts('Sign of 9');
end
imaqreset[/CODE]
load HOG_features
% imaqreset;
% vid = videoinput('winvideo', 1, 'YUY2_640x480');
% src = getselectedsource(vid);
% vid.FramesPerTrigger = Inf;
% vid.ReturnedColorspace = 'rgb';
% start(vid);
% preview(vid);
%% Get snapshot and process frame image
% h = msgbox('Show Sign !');
% uiwait(h);
%
% im = getsnapshot(vid);
[f,p] = uigetfile('*.*');
im = imread([p,f]);
imshow(im);
% stop(vid);
cform = makecform('srgb2lab');
J = applycform(im,cform);
K=J
L=graythresh(J
BW1=im2bw(J
BW1=bwareaopen(BW1,500);
BB=regionprops(BW1,'Boundingbox');
pause(0.01)
gr = rgb2gray(im);
object = imcrop(gr,BB(1).BoundingBox);
object = imresize(object,[100,50]);
figure(2);imshow(object);
[feat] = hog_feature_vector(object);
class = knnclassify(feat,data,group);
switch class
case 0
tts('Sign of 0');
case 1
tts('Sign of 1');
case 2
tts('Sign of 2');
case 3
tts('Sign of 3');
case 4
tts('Sign of 4');
case 5
tts('Sign of 5');
case 6
tts('Sign of 6');
case 7
tts('Sign of 7');
case 8
tts('Sign of 8');
case 9
tts('Sign of 9');
end
imaqreset[/CODE]
Moderatörün son düzenlenenleri: