My frame is capturing the same beginning video frame in multiple figures. I want the multiple figure to be images of the video as it progrosses, not the same figure for multiple figures. Here is my code. Please fix it
obj = VideoReader('Climate.mp4');
for k = 1 : 5 %fill in the appropriate number
this_frame = read(obj, k);
thisfig = figure();
%thisfig = gcf;
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
title(thisax, sprintf('Frame #%d', k));
end

 Respuesta aceptada

Image Analyst
Image Analyst el 7 de Abr. de 2017

0 votos

So don't create a new figure each frame. How does this work:
obj = VideoReader('Climate.mp4');
for k = 1 : obj.NumberOfFrames
this_frame = read(obj, k);
imshow(this_frame);
title(sprintf('Frame #%d', k), 'FontSize', 14);
drawnow; % Force immediate repaint of screen.
pause(0.1); % Increase number to slow it down more.
end

11 comentarios

Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
how do I pause a frame?
Thank you very much by the way
Image Analyst
Image Analyst el 7 de Abr. de 2017
To put in a pause so that the user needs to click to continue on to the next frame, insert this code just before the "end" of the loop:
promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
break;
end
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
wow, that is really awesome. It works very well. Thank you so much. Final question, the pop up bar appears for every frame, and it takes a while since I have to keep on clicking continue and continue to get to the specific frame that i want, Is there a way to slow down the pop up bar so that it appears slower and not every single frame.
Thanks alot!! YOU ROCK!!!
Image Analyst
Image Analyst el 7 de Abr. de 2017
You can put it inside an if where you use rem to call it every n'th time.
if rem(k, 5) == 0
% Ask every fifth frame
buttonText = questdlg(..........
end
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
is this proper syntax?
obj = VideoReader('Climate.mp4'); for k = 1 : obj.NumberOfFrames this_frame = read(obj, k); imshow(this_frame); title(sprintf('Frame #%d', k), 'FontSize', 14); drawnow; % Force immediate repaint of screen. pause(0.1); % Increase number to slow it down more. promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k); titleBarCaption = 'Continue?'; buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); if strcmpi(buttonText, 'Quit') break; end if rem(k, 5) == 0 % Ask every fifth frame buttonText = questdlg(.......... end end
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
i have this code,
for k = 1 : obj.NumberOfFrames this_frame = read(obj, k); imshow(this_frame); title(sprintf('Frame #%d', k), 'FontSize', 14); drawnow; % Force immediate repaint of screen. pause(0.1); % Increase number to slow it down more. promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k); titleBarCaption = 'Continue?'; buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); if strcmpi(buttonText, 'Quit') break; rem(k, 5) == 0 % Ask every fifth frame buttonText = questdlg(..........
end
end
and for the rem(k, 5) == 0 , the double '==' is underlined in red with the statement and possibly following ones cannot be reached
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
This is my latest code
obj = VideoReader('Climate.mp4'); for k = 1 : obj.NumberOfFrames this_frame = read(obj, k); imshow(this_frame); title(sprintf('Frame #%d', k), 'FontSize', 14); drawnow; % Force immediate repaint of screen. pause(0.1); % Increase number to slow it down more. promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k); titleBarCaption = 'Continue?'; buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); if strcmpi(buttonText, 'Quit') break; rem(k, 5) == 0 % Ask every fifth frame buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); end
end
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
it runs but it is still displaying the prompt every single frame
Image Analyst
Image Analyst el 7 de Abr. de 2017
You didn't use the "if" before the rem() like I had. Put that back in.
Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
obj = VideoReader('Climate.mp4'); for k = 1 : obj.NumberOfFrames this_frame = read(obj, k); imshow(this_frame); title(sprintf('Frame #%d', k), 'FontSize', 14); drawnow; % Force immediate repaint of screen. pause(0.1); % Increase number to slow it down more. promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k); titleBarCaption = 'Continue?'; buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); if strcmpi(buttonText, 'Quit') break; if rem(k, 5) == 0 % Ask every fifth frame buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); end end end
i put the if in but now it underlines everything...
Image Analyst
Image Analyst el 7 de Abr. de 2017
You need to think about the logic flow. This works just fine.
obj = VideoReader('Climate.mp4');
for k = 1 : obj.NumberOfFrames
this_frame = read(obj, k);
imshow(this_frame);
title(sprintf('Frame #%d', k), 'FontSize', 14);
drawnow; % Force immediate repaint of screen.
pause(0.1); % Increase number to slow it down more.
if rem(k, 5) == 0 % Ask every fifth frame
promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k);
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(buttonText, 'Quit')
break;
end
end
end

Iniciar sesión para comentar.

Más respuestas (1)

Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017

0 votos

Here is another look

4 comentarios

Osita Onyejekwe
Osita Onyejekwe el 7 de Abr. de 2017
????
Image Analyst
Image Analyst el 7 de Abr. de 2017
This is NOT an answer to your original question. It should have been appended as a comment to your and my prior comments above.
Osita Onyejekwe
Osita Onyejekwe el 10 de Abr. de 2017
Thank you so much. All is perfect now!!!
Osita Onyejekwe
Osita Onyejekwe el 10 de Abr. de 2017
Final Final Final question.
Given this code, is there a way I can save all the frames into a folder as image files as I run the code?
obj = VideoReader('Climate.mp4'); for k = 1 : obj.NumberOfFrames this_frame = read(obj, k); imshow(this_frame); title(sprintf('Frame #%d', k), 'FontSize', 14); drawnow; % Force immediate repaint of screen. pause(0.1); % Increase number to slow it down more. if rem(k, 5) == 0 % Ask every fifth frame promptMessage = sprintf('Showing Frame #%d.\nDo you want to Continue processing,\nor Quit processing?', k); titleBarCaption = 'Continue?'; buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue'); if strcmpi(buttonText, 'Quit') break; end end end
thank you!!!

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 7 de Abr. de 2017

Comentada:

el 10 de Abr. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by