Displaying a difference image as a video
이전 댓글 표시
Hello All,
I have a video with 18000 frames in it and also a frame rate of 30 fps and I wrote a small code.
vidobj = mmreader('myvideo.asf');
lframe = read(vidobj,Inf);
numFrames = vidobj.NumberOfFrames;
vidHeight = vidobj.Height;
vidWidth = vidobj.Width;
for k=1:numFrames
sFrame = rgb2gray(read(vidobj,k);
if k<numFrames
pFrame = rgb2gray(read(vidobj,k+1);
else
pFrame = sFrame;
temp{k} = pFrame - sFrame;
end
end
Now what should I do to play all temp{k} (where k=1:numFrames) as a video ? I have tried something like this though I know it's not correct
movie(temp);
But it doesn't work!!!Apart from that, the difference image would be a binary image and I would like to plot row vs column for maximum index (pixel intensity) and display it as a video too. So at the end of my program the user should be able to see three videos 1.My original video. 2.My Difference Video. 3.My row vs column video.
Any help would be sincerely appreciated.
채택된 답변
추가 답변 (1개)
Walter Roberson
2011년 6월 28일
Efficiency improvement to your posted code; I will leave it to you to adapt the other changes:
vidobj = mmreader('myvideo.asf');
read(vidobj,Inf); %to count variable-rate frames
numFrames = vidobj.NumberOfFrames;
vidHeight = vidobj.Height;
vidWidth = vidobj.Width;
%no need to read every frame twice, just remember the previous frame
sFrame = rgb2gray(read(videobj,1));
for k=1:numFrames-1
pFrame = rgb2gray(read(vidobj,k+1);
temp{k} = pFrame - sFrame;
sFrame = pFrame;
end
temp{numFrames} = 0 .* sFrame;
카테고리
도움말 센터 및 File Exchange에서 Motion Detection에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!