Matlab - Guardad varias imagenes desde GUI matlab

 
Vista:
Imágen de perfil de paloma

Guardad varias imagenes desde GUI matlab

Publicado por paloma (3 intervenciones) el 30/07/2016 03:00:22
Hola! tengo un codigo el cual guarda una secuencia de frames de un video las vuelve imagenes y las guarda en la carpeta que se le indique, pero quiero este codigo para una GUI y no me permite guardar las imagenes y me aparece este error,:
Error using horzcat
The following error occurred converting from char to struct:
Error using struct
Conversion to struct from char is not possible.

Error in Segmentar_Video>segmentacion_Callback (line 148)
namefile = [carpeta, '\im', num2str(x), '.bmp'];

se que necesito usar "sprintf" o algo asi, pero no tengo idea de como se usa, ¿alguien sabe como puedo escribir este codigo en GUI?



1
2
3
4
5
6
7
for i3 = 1:size(BB,1)
    O = imcrop(frame,BB(i2,:));
          namefile = [carpeta, '\im', num2str(x), '.bmp'];
    imwrite(O,namefile)
 
    x=x+1;
 end
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
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

Guardad varias imagenes desde GUI matlab

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 30/07/2016 14:36:18
http://www.lawebdelprogramador.com/foros/Matlab/1558889-Solucion-de-ecuaciones-complejas-en-matlab.html

Saludos.
JOSE JEREMÍAS CABALLERO
Asesoría online en Matlab
Programador en Matlab
Servicios de programación matlab
[email protected]
El correo es para servicios de programación, toda ayuda gratuita es vía foro.


http://matlabcaballero.blogspot.com
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 paloma

Guardad varias imagenes desde GUI matlab

Publicado por paloma (3 intervenciones) el 31/07/2016 22:33:21
Buenas tardes Jose, muchas gracias por responder, insertare el codigo original elcual es un archivo .m y con el cual no hay ningun problema y tambien pondre el que estoy utilizando para la interfaz grafica, asi como una captura de los elementos de la interfaz grafica, para que se vea con claridad el error.
Para poder ejecutar el primer codigo, es necesario realizar un entrenamiento de deteccion pero se puede sustituir con algun otro detector ya incluido en MATLAB, entonces lo estoy poniendo con un detector de bocas que ofrece matlab y el segundo es el que estoy usandoen la interfaz grafica que fue el que yo hice el errorque me marca esta en el boton segmentacion.


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
clc, clear all, close all
 
video = 'C:\Users';   % Nombre del video
carpeta = 'C:\Users\';  % Nombre de la carpeta para almacenar las imágenes
NumeroImagenes = 10; %Número de imágenes a extraer 
 
videoobj = VideoReader(video);
intervalo = round(linspace(1,videoobj.NumberOfFrames,NumeroImagenes));
x=1;
for i1=intervalo
    frame = read(videoobj,i1);
 
    FaceDetect = vision.CascadeObjectDetector('Face','12');%('Mouth'); 
    %FaceDetect.MergeThreshold = 100;
 
    BB = step(FaceDetect,frame,);
     for i2 = 1:size(BB,1)
 
        rectangle('Position',BB(i2,:),'LineWidth',3,'LineStyle','-','EdgeColor','r');
   end
 %crop faces 
     for i3 = 1:size(BB,1)
    O = imcrop(frame,BB(i2,:));
     end
   namefile = [carpeta, '\ima', num2str(x), '.bmp'];
    imwrite(O,namefile)
    x=x+1;
 end


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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
function varargout = Segmentar_Video(varargin)
% SEGMENTAR_VIDEO MATLAB code for Segmentar_Video.fig
%      SEGMENTAR_VIDEO, by itself, creates a new SEGMENTAR_VIDEO or raises the existing
%      singleton*.
%
%      H = SEGMENTAR_VIDEO returns the handle to a new SEGMENTAR_VIDEO or the handle to
%      the existing singleton*.
%
%      SEGMENTAR_VIDEO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SEGMENTAR_VIDEO.M with the given input arguments.
%
%      SEGMENTAR_VIDEO('Property','Value',...) creates a new SEGMENTAR_VIDEO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Segmentar_Video_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Segmentar_Video_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 Segmentar_Video

% Last Modified by GUIDE v2.5 28-Jul-2016 01:14:55

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Segmentar_Video_OpeningFcn, ...
                   'gui_OutputFcn',  @Segmentar_Video_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 Segmentar_Video is made visible.
function Segmentar_Video_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 Segmentar_Video (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Segmentar_Video_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 pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



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

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


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

%% Entrenamiento de la Adaboost
global PathFile
load('PL.mat');
positiveFolder = 'PL';
negativeFolder = 'NL';
detectorName = 'labiosL.xml';
trainCascadeObjectDetector(detectorName, positiveInstancesL, negativeFolder,...
     'FalseAlarmRate', 0.3, 'NumCascadeStages',10);


video = 'C:\Users\Paloma\Documents\MATLAB\niños\49.avi'; % Nombre del video
carpeta = get(handles.guardar); % Nombre de la carpeta para almacenar las imágenes
NumeroImagenes = str2double(get(handles.edit2, 'String'));
 
guidata(hObject,handles)
 %Número de imágenes a extraer 310
 
videoobj = VideoReader(video);
intervalo = round(linspace(1,videoobj.NumberOfFrames,NumeroImagenes));
x=1;
for i1=intervalo
     frame = read(videoobj,i1);
    FaceDetect = vision.CascadeObjectDetector('labiosL.xml');
   % FaceDetect.MergeThreshold = 300;
    BB = step(FaceDetect,frame);
     for i2 = 1:size(BB,1)
 
        rectangle('Position',BB(i2,:),'LineWidth',3,'LineStyle','-','EdgeColor','r');
   end
 %crop faces 
     for i3 = 1:size(BB,1)
      O = imcrop(frame,BB(i2,:));
          namefile = [carpeta, '\im', num2str(x), '.bmp'];
    imwrite(O,namefile)
    x=x+1;
     end
 
 
 
end
%trainingImageLabeler %para crear las Gtrain y Gtest
 
 
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
Seleccion_de_Video;
delete(handles.figure1);
 
% hObject    handle to pushbutton5 (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 guardar.
function guardar_Callback(hObject, eventdata, handles)
global PathFile
% hObject    handle to guardar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[PathFile]=uigetdir;                                     %  Con este comando abres el directorio
set(handles.edit1,'String',PathFile)
 
function edit2_Callback(hObject, eventdata, handles)
input = str2double(get(hObject,'string'));
if isnan(input)
  errordlg('You must enter a numeric value','Invalid Input','modal')
  uicontrol(hObject)
  return
else
  display(input);
end
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
 
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
duda
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

Guardad varias imagenes desde GUI matlab

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 01/08/2016 03:04:36
Bueno deberías subir tanto tu archivo fig y su archivo m. Para poder ejecutar y ver los posibles cambios. Porque de lo haz puesto, tendría que reahcer el guide con los datos que brindas pero eso implica tiempo hacerlo.
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

Guardad varias imagenes desde GUI matlab

Publicado por JOSE JEREMIAS CABALLERO (5917 intervenciones) el 01/08/2016 06:00:29
1
carpeta = PathFile; % Nombre de la carpeta para almacenar las imágenes
.

Con tu pregunta original, era imposible detectar ese error. El codigo ejecutandose correctamente. Lo he probado con un video que he tengo.

Saludos.
JOSE JEREMÍAS CABALLERO
Asesoría online en Matlab
Programador en Matlab
Servicios de programación matlab
[email protected]
El correo es para servicios de programación, toda ayuda gratuita es vía foro.


http://matlabcaballero.blogspot.com
Captura-de-pantalla-2016-07-31-23.06.50
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar
Imágen de perfil de paloma

Guardad varias imagenes desde GUI matlab

Publicado por paloma (3 intervenciones) el 05/08/2016 18:32:56
Muchas gracias, funciona perfectamente, ese era el error, saludos!
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