function varargout = Reconocimiento(varargin)
% RECONOCIMIENTO MATLAB code for Reconocimiento.fig
% RECONOCIMIENTO, by itself, creates a new RECONOCIMIENTO or raises the existing
% singleton*.
%
% H = RECONOCIMIENTO returns the handle to a new RECONOCIMIENTO or the handle to
% the existing singleton*.
%
% RECONOCIMIENTO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RECONOCIMIENTO.M with the given input arguments.
%
% RECONOCIMIENTO('Property','Value',...) creates a new RECONOCIMIENTO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Reconocimiento_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Reconocimiento_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Reconocimiento
% Last Modified by GUIDE v2.5 11-Nov-2014 20:47:25
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Reconocimiento_OpeningFcn, ...
'gui_OutputFcn', @Reconocimiento_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Reconocimiento is made visible.
function Reconocimiento_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Reconocimiento (see VARARGIN)
%Colocar Imagen de fondo
;
% Choose default command line output for Reconocimiento
handles.output = hObject;
imshow('190x190.png','Parent',handles.axCamara)
imshow('190x190.png','Parent',handles.axPrueba)
imshow('190x190.png','Parent',handles.axP1)
imshow('190x190.png','Parent',handles.axP2)
imshow('190x190.png','Parent',handles.axResultado)
set(handles.textSERIAL,'String','')
warning('off')
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Reconocimiento wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Reconocimiento_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in buttonPreview.
function buttonPreview_Callback(hObject, eventdata, handles)
% hObject handle to buttonPreview (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global vid
vid=videoinput('winvideo',1,'MJPG_640x360');
vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';
triggerconfig(vid, 'manual');
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axCamara);
preview(vid, hImage);
% --- Executes on button press in buttonCapture.
function buttonCapture_Callback(hObject, eventdata, handles)
% hObject handle to buttonCapture (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global vid PTf x y
prueba=getsnapshot(vid);
pru=im2bw(prueba,0.6);
%imshow(pru,'Parent',handles.axPrueba)
A = imcrop(pru, [120 70 189 189]); %imcrop(f,[xmin ymin ancho alto ])
a=imresize(A, 0.25);
prt=im2bw(a);
pt=double(prt);
[x,y]=size(pt);
for i=1:1:x
for j=1:1:y
PT(i,j)=pt(i,j);
if(PT(i,j)==0)
PT(i,j)=-1;
end
end
end
cont = 1;
[f,g]=size(PT);
for r=1:1:g
for c=1:1:f
PTf(cont,1)=PT(c,r);
cont=cont+1;
end
end
imshow(PT,'Parent',handles.axPrueba)
% --- Executes on button press in buttonFiguras.
function buttonFiguras_Callback(hObject, eventdata, handles)
% hObject handle to buttonFiguras (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global P1 P2 P1f P2f x y
%ENSEÑAR MANZANA
MA=imread('manzana.png');
m=imresize(MA,0.25);
pr1=im2bw(m);
p1=double(pr1);
[x,y]=size(p1);
for i=1:1:x
for j=1:1:y
P1(i,j)=p1(i,j);
if(P1(i,j)==0)
P1(i,j)=-1;
end
end
end
cont = 1;
[f,g]=size(P1);
for r=1:1:g
for c=1:1:f
P1f(cont,1)=P1(c,r);
cont=cont+1;
end
end
%ENSEÑAR PLATANO
PL=imread('platano.png');
p=imresize(PL,0.25);
pr2=im2bw(p);
p2=double(pr2);
[x,y]=size(p2);
for i=1:1:x
for j=1:1:y
P2(i,j)=p2(i,j);
if(P2(i,j)==0)
P2(i,j)=-1;
end
end
end
cont = 1;
[f,g]=size(P2);
for r=1:1:g
for c=1:1:f
P2f(cont,1)=P2(c,r);
cont=cont+1;
end
end
%MOSTRAR IMAGENES EN LA GUI
imshow(MA,'Parent',handles.axP1)
imshow(PL,'Parent',handles.axP2)
% --- Executes on button press in buttonResultado.
function buttonResultado_Callback(hObject, eventdata, handles)
% hObject handle to buttonResultado (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global P1f P2f PTf x y A2
T=[P1f P2f];
P=[P1f P2f]';
W=T*P;
A=hardlims(W*PTf);
cont = 1;
for c=1:1:y
for r=1:1:x
A2(r,c)=A(cont,1);
cont=cont+1;
end
end
imshow(A2,'Parent',handles.axResultado)
% --- Executes on button press in buttonLetras.
function buttonLetras_Callback(hObject, eventdata, handles)
% hObject handle to buttonLetras (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global P1 P2 P1f P2f x y
%ENSEÑAR M
MA=imread('M.png');
m=imresize(MA,0.25);
pr1=im2bw(m);
p1=double(pr1);
[x,y]=size(p1);
for i=1:1:x
for j=1:1:y
P1(i,j)=p1(i,j);
if(P1(i,j)==0)
P1(i,j)=-1;
end
end
end
cont = 1;
[f,g]=size(P1);
for r=1:1:g
for c=1:1:f
P1f(cont,1)=P1(c,r);
cont=cont+1;
end
end
%ENSEÑAR P
PL=imread('P.png');
p=imresize(PL,0.25);
pr2=im2bw(p);
p2=double(pr2);
[x,y]=size(p2);
for i=1:1:x
for j=1:1:y
P2(i,j)=p2(i,j);
if(P2(i,j)==0)
P2(i,j)=-1;
end
end
end
cont = 1;
[f,g]=size(P2);
for r=1:1:g
for c=1:1:f
P2f(cont,1)=P2(c,r);
cont=cont+1;
end
end
%MOSTRAR IMAGENES EN LA GUI
imshow(PL,'Parent',handles.axP1)
imshow(MA,'Parent',handles.axP2)
% --- Executes on button press in buttonEnviar.
function buttonEnviar_Callback(hObject, eventdata, handles)
% hObject handle to buttonEnviar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.textSERIAL,'String','')
global A2 P1 P2
if(A2==P1)
set(handles.textSERIAL,'String','M')
end
if(A2==P2)
set(handles.textSERIAL,'String','P')
end
% delete(instrfind({'Port'},{'COM4'}));
% pserial = serial ('COM4');
% pserial.Baudrate = 9600;
% warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
% fopen(pserial);
%
% if(A2==P1)
% set(handles.textSERIAL,'String','M')
% fprintf(pserial,'1');
% end
%
% if(A2==P2)
% set(handles.textSERIAL,'String','P')
% fprintf(pserial,'1');
% end
%
% fclose(pserial);
% delete(pserial);
Para utilizar la cámara WEB se requiere saber que cámara se va a utilizar y modificar la siguiente linea:
vid=videoinput('winvideo',1,'MJPG_640x360');
Cambiar el número de cámara y los formatos que soporta la cámara, para obtener esos datos ejecutar el siguiente comando (Windows)
-imaqhwinfo('winvideo')
-Doble clic en ans -> Workspace
-Doble clic sobre DeviceInfo <1x_ Struct>
-Seleccionar alguna de las cámaras que aparezcan y les mostrará información de que cámara esta haciendo referencia
-Doble clic sobre SupportedFormats <1x_ cell>
-Seleccionar alguno de los formatos que aparezcan, por lo regular las cámaras WEB integradas por default manejan el formato 'YUY2_160x1202'
Ya que sabemos el número de cámara y los formatos que soportan, se necesita cambiar la siguiente linea:
vid=videoinput('winvideo',2,'YUY2_160x1202');
El numero 1 o 2 depende del número de cámaras conectadas al PC.