manipulating frame by frame on AVI video

hi all!
first of all i will say i usually don't write scripts and MATLAB is not my cup of tea ;-)
having said that- i really need some help with basic code that i need to write.
i am reading an AVI code and i need to mark one fixed pixel so when the movie is running i will see this mark
i tried to write a code but surprisingly it does not working.
the code;
clc
clear all
x=VideoReader('focus_m1.avi');
%frame = x.read(1);
nFrames = x.NumberOfFrames;
for i=1:10
%i=1:nFrames
currFrame = x.read(i)
%fig = figure(i)
imshow(currFrame)
hold on
plot (333,397,'r-.x','MarkerSize',20)
M=getframe;
end
movie(M)
any help will be a saver
yael

Réponses (2)

yael
yael le 29 Fév 2012

0 votes

hi Chandra Kurniawan
the frame size is 480X720, and for 10 frames it indid working but my movie is ~30000 frames and it takes hours! is some other way to do that?
Walter Roberson
Walter Roberson le 29 Fév 2012

0 votes

The data you are trying to write out is constant, and in a constant location. You can read a frame, set the specific locations in the frame array to the constant values, and then write the adjusted frame, without ever displaying the frame.

3 commentaires

yael
yael le 29 Fév 2012
can you pleas re-write it so i will understand your meaning?
Walter Roberson
Walter Roberson le 29 Fév 2012
x = VideoReader('focus_m1.avi');
xout = VideoWriter('focus_m1x.avi');
xout.FrameRate = x.FrameRate;
open(xout);
red3x3 = repmat(reshape([1 0 0], [1 1 3]), 2, 2, 1); %3x3 block of red
nFrames = x.NumberOfFrames;
for i = 1 : nFrames
currFrame = x.read(i);
currFrame(333:335, 396:398, :) = red3x3;
xout.write(currFrame);
end
xout.close;
clear x; %no close method for reader
yael
yael le 4 Mar 2012
hi walter
thanks for the code
there is one thing i dont understand what whs tour meaning:
red3x3 = repmat(reshape([1 0 0], [1 1 3]), 2, 2, 1); %3x3 block of red
(and matlab return: "Error using repmat Too many input arguments")
thanks

Connectez-vous pour commenter.

Question posée :

le 29 Fév 2012

Community Treasure Hunt

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

Start Hunting!

Translated by