Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
frame to video

Subject: frame to video

From: Ahmad Alkandri

Date: 12 Mar, 2011 20:18:04

Message: 1 of 3

hi

i do have a small problem ..... i'm trying to resize a movie by cropping frame by frame and the create a new video

this is the code i'm using :


vid = mmread('22.avi',1:10);
       mov = vid.frames;
       for k = 1 : 10
             newvid = mov(k).cdata;
             nn = imcrop(newvid,[225 25 511 511]);
             imwrite(nn,'tt.tiff');
             tt = imread ('tt.tiff');
             ii = immovie(tt);
       end
       implay(ii)


the problem is only one frame is recorded ?!!

please help

Subject: frame to video

From: ImageAnalyst

Date: 12 Mar, 2011 21:17:06

Message: 2 of 3

Ahmad Alkandri
See my demo:

% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.

% Demo macro to extract frames and get frame means from an avi movie
% and save individual frames to separate image files.
% Also computes the mean gray value of the color channels.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Open the rhino.avi demo movie that ships with MATLAB.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
movieFullFileName = fullfile(folder, 'rhinos.avi');
% Check to see that it exists.
if ~exist(movieFullFileName, 'file')
strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new
one, or cancel', movieFullFileName);
response = questdlg(strErrorMessage, 'File not found', 'OK - choose a
new movie.', 'Cancel', 'OK - choose a new movie.');
if strcmpi(response, 'OK - choose a new movie.')
[baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
if ~isequal(baseFileName, 0)
movieFullFileName = fullfile(folderName, baseFileName);
else
return;
end
else
return;
end
end

try
mov = aviread(movieFullFileName);
% movie(mov);
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;
% Prepare a figure to show the images in the upper half of the
screen.
figure;
screenSize = get(0, 'ScreenSize');
newWindowPosition = [1 screenSize(4)/2 - 70 screenSize(3)
screenSize(4)/2];
set(gcf, 'Position', newWindowPosition); % Maximize figure.
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
cropBox = [50 50 120 80];
    % Loop through the movie, cropping all frames out.
    for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = mov(frame).cdata;

        % Display it
        hImage = subplot(1,2,1);
        image(thisFrame);
        caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
        title(caption, 'FontSize', fontSize);
        drawnow; % Force it to refresh the window.

% Crop it.
croppedFrame = imcrop(thisFrame, cropBox);
% Display cropped frame.
hImage = subplot(1,2, 2);
imshow(croppedFrame);
% Convert the image into a "movie frame" structure.
croppedMovie(frame) = im2frame(croppedFrame);

progressIndication = sprintf('Processed frame %4d of %d.', frame,
numberOfFrames);
disp(progressIndication);
% Increment frame count (should eventually = numberOfFrames
% unless an error happens).
numberOfFramesWritten = numberOfFramesWritten + 1;
    end

    % Alert user that we're done.
    finishedMessage = sprintf('Done! It cropped %d frames of\n"%s"',
numberOfFramesWritten, movieFullFileName);
    disp(finishedMessage); % Write to command window.
    uiwait(msgbox(finishedMessage)); % Also pop up a message box.

% Ask user if they want to play the movie and display it.
promptMessage = sprintf('Do you want to replay the cropped movie?)');
button = questdlg(promptMessage, 'Play Cropped Movie?', 'Yes', 'No',
'Yes');
if strcmp(button, 'No')
return;
end
    % Play the movie in the axes.
hold off;
cla reset;
reset(gca);
    movie(croppedMovie);

    msgbox('Done with this demo!');

catch ME
% Some error happened if you get here.
stError = ME.message;
strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n
\nError: %s\n\n)', movieFullFileName, stError.message);
fprintf('%s\n', strErrorMessage);
uiwait(msgbox(strErrorMessage));
end

Subject: frame to video

From: m

Date: 22 Mar, 2013 03:32:22

Message: 3 of 3

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <be9cdbff-b8bd-4a21-b19e-ac83545f501e@t19g2000prd.googlegroups.com>...
> Ahmad Alkandri
> See my demo:
>
> % IMPORTANT: The newsreader may break long lines into multiple lines.
> % Be sure to join any long lines that got split into multiple single
> lines.
> % These can be found by the red lines on the left side of your
> % text editor, which indicate syntax errors, or else just run the
> % code and it will stop at the split lines with an error.
>
> % Demo macro to extract frames and get frame means from an avi movie
> % and save individual frames to separate image files.
> % Also computes the mean gray value of the color channels.
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 14;
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> % Open the rhino.avi demo movie that ships with MATLAB.
> folder = fullfile(matlabroot, '\toolbox\images\imdemos');
> movieFullFileName = fullfile(folder, 'rhinos.avi');
> % Check to see that it exists.
> if ~exist(movieFullFileName, 'file')
> strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new
> one, or cancel', movieFullFileName);
> response = questdlg(strErrorMessage, 'File not found', 'OK - choose a
> new movie.', 'Cancel', 'OK - choose a new movie.');
> if strcmpi(response, 'OK - choose a new movie.')
> [baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
> if ~isequal(baseFileName, 0)
> movieFullFileName = fullfile(folderName, baseFileName);
> else
> return;
> end
> else
> return;
> end
> end
>
> try
> mov = aviread(movieFullFileName);
> % movie(mov);
> % Determine how many frames there are.
> numberOfFrames = size(mov, 2);
> numberOfFramesWritten = 0;
> % Prepare a figure to show the images in the upper half of the
> screen.
> figure;
> screenSize = get(0, 'ScreenSize');
> newWindowPosition = [1 screenSize(4)/2 - 70 screenSize(3)
> screenSize(4)/2];
> set(gcf, 'Position', newWindowPosition); % Maximize figure.
> % set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
> cropBox = [50 50 120 80];
> % Loop through the movie, cropping all frames out.
> for frame = 1 : numberOfFrames
> % Extract the frame from the movie structure.
> thisFrame = mov(frame).cdata;
>
> % Display it
> hImage = subplot(1,2,1);
> image(thisFrame);
> caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
> title(caption, 'FontSize', fontSize);
> drawnow; % Force it to refresh the window.
>
> % Crop it.
> croppedFrame = imcrop(thisFrame, cropBox);
> % Display cropped frame.
> hImage = subplot(1,2, 2);
> imshow(croppedFrame);
> % Convert the image into a "movie frame" structure.
> croppedMovie(frame) = im2frame(croppedFrame);
>
> progressIndication = sprintf('Processed frame %4d of %d.', frame,
> numberOfFrames);
> disp(progressIndication);
> % Increment frame count (should eventually = numberOfFrames
> % unless an error happens).
> numberOfFramesWritten = numberOfFramesWritten + 1;
> end
>
> % Alert user that we're done.
> finishedMessage = sprintf('Done! It cropped %d frames of\n"%s"',
> numberOfFramesWritten, movieFullFileName);
> disp(finishedMessage); % Write to command window.
> uiwait(msgbox(finishedMessage)); % Also pop up a message box.
>
> % Ask user if they want to play the movie and display it.
> promptMessage = sprintf('Do you want to replay the cropped movie?)');
> button = questdlg(promptMessage, 'Play Cropped Movie?', 'Yes', 'No',
> 'Yes');
> if strcmp(button, 'No')
> return;
> end
> % Play the movie in the axes.
> hold off;
> cla reset;
> reset(gca);
> movie(croppedMovie);
>
> msgbox('Done with this demo!');
>
> catch ME
> % Some error happened if you get here.
> stError = ME.message;
> strErrorMessage = sprintf('Error extracting movie frames from:\n\n%s\n
> \nError: %s\n\n)', movieFullFileName, stError.message);
> fprintf('%s\n', strErrorMessage);
> uiwait(msgbox(strErrorMessage));
> end


Getting erros on last line while writting
erros is :
Error in newfile (line 106)
strErrorMessage = sprintf('Error extracting movie frames
from:\n\n%s\n\nError: %s\n\n)', movieFullFileName,stError.message);
 

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us