Matlab - Mantener activa webcam en toda la Gui

 
Vista:

Mantener activa webcam en toda la Gui

Publicado por javo (4 intervenciones) el 22/10/2013 17:45:41
Buen día! tengo una duda respecto a una Gui. El problema es el siguiente! Cree una gui con 3 botones, activar cámara, start y desactivar cámara. Al activar cámara me muestra mi cámara web en un axes sin ningún problema, pero al presionar start, me congela la cámara web y hasta que termina el proceso de start (getsnapshoot) vuelve la imagen de la web cam!! Necesito que se muestre en tiempo real lo que capta la web cam, independientemente de usar el getsnapshoot. Alguna sugerencia? De antemanp, gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Mantener activa webcam en toda la Gui

Publicado por javo (4 intervenciones) el 22/10/2013 18:11:04
Adjunto el codigo! De antemano gracias!

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function varargout = inicio(varargin)
% INICIO MATLAB code for inicio.fig
%      INICIO, by itself, creates a new INICIO or raises the existing
%      singleton*.
%
%      H = INICIO returns the handle to a new INICIO or the handle to
%      the existing singleton*.
%
%      INICIO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in INICIO.M with the given input arguments.
%
%      INICIO('Property','Value',...) creates a new INICIO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before inicio_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to inicio_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 inicio

% Last Modified by GUIDE v2.5 25-Sep-2013 16:39:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @inicio_OpeningFcn, ...
                   'gui_OutputFcn',  @inicio_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 inicio is made visible.
function inicio_OpeningFcn(hObject, eventdata, handles, varargin)


scrsz=get(0,'ScreenSize');
pos_act=get(gcf,'position');
xr=scrsz(3)-pos_act(3);
xp=round(xr/2);
yr=scrsz(4)-pos_act(4);
yp=round(yr/2);
set(gcf,'Position',[xp yp pos_act(3) pos_act(4)]);
A=imread('fondo.jpg');
set(handles.axes1,'Visible','off');
image(A,'Parent',handles.axes1)


set(handles.cameraAxes,'Visible','off');
set(handles.axes3,'Visible','off')
handles.output = hObject;
guidata(hObject, handles);

% 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 inicio (see VARARGIN)

% Choose default command line output for inicio
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes inicio wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = inicio_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;

%%%%
function entrada_Callback(hObject, eventdata, handles)
function entrada_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
    get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%%%%


% --- Executes on button press in ActCam.
function ActCam_Callback(hObject, eventdata, handles)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%javo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global vid

vid = videoinput('winvideo', 1,'YUY2_320x240')
set(vid,'TriggerRepeat',Inf);
%vid.FrameGrabInterval=Inf;
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
%cla;
hImage = image( zeros(imHeight, imWidth, nBands),'Parent',handles.cameraAxes );
preview(vid,hImage);
start(vid);

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%javo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% hObject    handle to ActCam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject    handle to Start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%%%%%%%%%%%%%%%%% j a v o %%%%%%%%%%%%%%%%%%%%%%%%%%%
global vid
global s



%%%%%%%%%%%%%%% Declaración del puerto serial %%%%%%%%%%%%%%%%%
s=serial('COM100'); % Puerto serial a utilizar
set(s,'BaudRate',9600)
set(s,'DataBits',8)
set(s,'Parity','none')
set(s,'StopBits',1)
set(s,'Terminator','LF')
set(s,'Timeout',100)
set(s,'OutputBufferSize',6)
set(s,'InputBufferSize',2)
 
fopen(s); % Abrimos puerto

A=fgetl(s); % Leemos puerto, esperando la señal para tomar foto
IM=getsnapshot(vid); % Obtenemos la imagen a analizar


axes(handles.axes3);
axis off;
imshow(IM);


%%%%%%%%%%%%%%%%%javo%%%%%%%%%%%%%%%%%%%

% --- Executes on button press in DesacCam.
function DesacCam_Callback(hObject, eventdata, handles)

global vid
global s
stop(vid)
delete(vid)
cla(handles.cameraAxes)
cla(handles.axes3)
fclose(s)
delete(s)
clear s

% hObject    handle to DesacCam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of DesacCam
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Mantener activa webcam en toda la Gui

Publicado por javo (4 intervenciones) el 24/10/2013 18:12:55
Lo que congela o le da ruido al axes de la cámara es la comunicación serial, el problema es que por ese medio mando la señal para tomar la foto!! Alguna sugerencia?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Mantener activa webcam en toda la Gui

Publicado por javo (4 intervenciones) el 29/10/2013 17:11:11
Por si tenían el pendiente... Ya encontré la solución!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de JOSE JEREMIAS CABALLERO
Val: 6.975
Oro
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

Mantener activa webcam en toda la Gui

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 29/10/2013 18:00:09
Y cual es la solución. podrías compartirnos.
Ya que yo no trabajo mucho con puertos seriales.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar