Question

I have a video of about 200 frames. I want to capture every 10th frame, do some image processing on it and display the original image along with the plot (after my image processing steps). The output should be first the 10th frame and its plot, and only after i click a push button should it move on and do the processing on the 20th frame, display it and so on. Once i get the desired frame for eg. 180th frame, i want to display the total time elapsed to reach that frame (if frame rate is 10 frames/sec then it should display 18 sec).

Till now i was dealing with separate frames and doing image processing on them and manually calculating the results. But a GUI would make this process more efficient

Était-ce utile?

La solution

Neat problem. Here's what you can do:

  1. At program startup, use dir, (like this: filelist = dir('*.bmp')) to get a list of all of the image files in the folder in which you are working.
  2. Assign that list to the guidata handles, like so: handles.filelist = filelist. While your at it, add another handle value to hold your current image index, handles.frameindex = 1, you'll need this later. Don't forget to update guidata afterwards!
  3. In the pressed callback function of your pushbutton, do something like this:

    filelist = handles.filelist; frameindex = handles.frameindex; currentframefile = filelist(frameindex); handles.frameindex = frameindex+1;

  4. Use the currentframefile, which is a string containing the name of the current frame, with your existing GUI.

This should answer your question, if I understand it correctly. Let me know if you need clarification. Good Luck!

Autres conseils

Well the your problem is very straight forward
You will have to iterate for every 10th frame you need to process your image.

You can use subplot function to plot different figures in one single figure.

subplot(n,m,p) = takes 3 arguments
n = number of rows
m = number of columns
p = location of current figure (from left to right , top to bottom flow)

thus subplot(1,2,2) will divide a figure in two parts (single row and two cols) and plot a figure in the second column.

waitforbuttonpress will allow you to pause the screen until you click mouse on the figure or press any key.

Luckily I had done something very similar
I changed a little code and I think this is what you are trying to do.

The code is self explanatory because of the comments...

% get a video file
[f, p] = uigetfile({'*.avi'});

% create a video reader object.
frames = VideoReader([p,f]);
get(frames);
% get the framerate of video
fps = frames.FrameRate;
% get the number of frames in video
nframes = frames.NumberOfFrames;

pickind = 'jpg';

% create a figure to plot on
figure,

% iterate for each 10th frame in image (in step of 10)
for i = 10:10:nframes

    %Use your fps to calculate time elasped
    disp('Time Elasped:');
    disp(i/fps);

    % read a frame to image
    I = read(frames, i);

    % in first row & first column 1st plot will be the original image
    % itself
    subplot(1,2,1);
    imshow(I) ;

    % in first row & second column 2nd plot will be a graph of
    % processed image (do your image processing here)
    subplot(1,2,2);
    imhist(rgb2gray(I));

    % Hit a key to process next 10th frame from video
    k = waitforbuttonpress ;
end

%close the figure
close

For proper annotation of your plots learn about figures, plots and subplots as there is a lot of material in matlab documentation itself.

Happy Learning

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top