Matlab - seguimiento del color rojo web cam tiempo real.

 
Vista:

seguimiento del color rojo web cam tiempo real.

Publicado por David (5 intervenciones) el 25/04/2013 21:11:24
Hola muy buenas a todos.
Mi pregunta esta relacionada con el seguimiento del color rojo mediante la web cam a tiempo real en una GUI.
Mi problema es el siguiente:

Doy al botón de encender web cam y esta se enciende representándome en el axis1 lo que ve en ese momento y me señala mediante rectangulo rojo el seguimiento del color rojo. Bien hasta aqui.

Ahora vienen los problemas, la representación que me hace la web cam no es de forma fluida sino a tirones, otro problema es que el programa cuando salgo de la ejecución de la gui me realiza figures ( de lo que esta viendo la web cam en ese momento) y cierro la figure que me realiza y me vuelve a sacar otra vez otra fugure y asi sucesivamente ( el problema es que el comand window esta funcionando y no se como pararlo), mi unica solucion es salir del matlab y volver a entrar....

me gustaría que me ayudaseis en corregir estos dos problemas por favor ya que lo necesito para el proyecto final de carrera (ingeniería electrónica).
En la gui solo e creado un botón que me active la webcam y el axis nada mas ( estoy probando).

Aqui dejo mi codigo (solo pongo el codigo que e puesto al pulsar el boton) a ver si me podríais ayudarme por favor:

% --- Executes on button press in Pulsar.
function Pulsar_Callback(hObject, eventdata, handles)

vid = videoinput('winvideo', 1, 'YUY2_320x240');

% only capture one frame per trigger, we are not recording a video
vid.FramesPerTrigger = 1;

% output would image in RGB color space
vid.ReturnedColorspace = 'rgb';

% tell matlab to start the webcam on user request, not automatically
triggerconfig(vid, 'manual');

% we need this to know the image height and width
vidRes = get(vid, 'VideoResolution');
% image width

imWidth = vidRes(1);
% image height
imHeight = vidRes(2);

% number of bands of our image (should be 3 because it's RGB)
nBands = get(vid, 'NumberOfBands');
%axes(handles.axPreview);

% create an empty image container and show it on axPreview
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axes1);
% begin the webcam preview
preview(vid, hImage);

while(vid.FramesAcquired<=100)
vid.FrameGrabInterval = 1;
set(vid,'TriggerRepeat',Inf);
vid.FramesPerTrigger=50;
data =getsnapshot(vid)
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
diff_im = medfilt2(diff_im,[3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,30);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(data);
hold on

for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end

hold off
end
stop(vid);


% hObject handle to WebCam_On (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% hObject handle to Pulsar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
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