-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptura_mano1.m
96 lines (83 loc) · 1.88 KB
/
captura_mano1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function jh = captura_mano()
% cam = webcam(1);
% set(gcf,'currentchar',' ');
% while get(gcf,'currentchar')==' '
% img = snapshot(cam);
%
% imshow(img,[]);
%
% end
%
cam=webcam(1);
figure(1),
m3=imread('numero3.png');
imshow(m3),hold on;
pause(1)
m2=imread('numero2.png');
imshow(m2),hold on;
pause(1)
m1=imread('numero1.png');
imshow(m1),hold on;
pause(1)
m0=imread('ya.png');
imshow(m0),hold on;
pause(1)
preview(cam), hold off;
pause(5)
img = snapshot(cam);
pause(1)
close;
clear cam;
imagen = imsubtract(img(:,:,1), rgb2gray(img));
imagen = medfilt2(imagen, [10 10]);
imb = im2bw(imagen,0.05);
ele = strel('square',10);
imagenaria = imopen(imb, ele);
%figure,imshow(imagenaria);
%centrado de la imagen
imagenaria=bwlabel(imagenaria);
centro = regionprops(imagenaria,'Centroid');
giro = regionprops(imagenaria,'Orientation');
if giro.Orientation < 0
angulo = -(giro.Orientation + 90);
else
angulo = 90 - giro.Orientation;
end
centroids = cat(1, centro.Centroid);
imagen = imrotate(imagen,angulo);
imagenaria=imrotate(imagenaria,angulo);
%figure, imshow(imagenaria);
pos = size(imagenaria,1);
max_n = 0;
centro = regionprops(imagenaria,'Centroid');
centroids = cat(1, centro.Centroid);
pos = centroids(2);
imagenaria2=imagenaria;
while pos >=1
imagenaria2(pos:size(imagenaria,1),:)=0;
[~,n] = bwlabel(imagenaria2);
if n > max_n
max_n = n
end
pos = pos - 100;
end
max_n2=max_n;
max_n = 0;
pos = centroids(2);
imagenaria(1:pos,:)=0;
pos = size(imagenaria,1);
while pos >= 1
imagenaria(pos:size(imagenaria,1),:)=0;
[~,n] = bwlabel(imagenaria);
if n > max_n
max_n = n;
end
pos = pos - 100;
end
if(max_n==2)
max_n2=max_n2+1;
end
jh=max_n2;
%jh=inputdlg({'Introduzca número del 1 al 5'},"Tú turno?",1);
% jh = str2num(cell2mat(jh));
end