필터 지우기
필터 지우기

How to replace a frame (rgb image) in a small video sequence ?

조회 수: 2 (최근 30일)
raviraja
raviraja 2017년 2월 13일
편집: Walter Roberson 2018년 4월 21일
I want to replace a single rgb frame in a 4 sec video sequence, example i want to replace the 5th frame with my rgb image of same dimension as the video dimension (example 256x256)

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 13일
vid = 'NameOfTheVideo.avi';
obj = VideoReader(vid);
newobj = VideoWriter('NameOfNewVideo.avi', 'Uncompressed AVI');
replacement_frame_5 = randi([0 255], 256, 256, 3, 'uint8'); %or as appropriate
fr = 0;
while hasFrame(obj)
fr = fr + 1;
a = readFrame(obj);
if fr == 5
a = replacement_frame_5;
end
writeVideo(newobj, a);
end
close(newobj);
clear obj
  댓글 수: 2
raviraja
raviraja 2017년 2월 21일
Hi Mr. Walter, thanks for the help with minor modification it works just fine, after replacing the frame in video how to display the video ? I used implay but it showing me some error I am attaching the screenshot here can you suggest me here,, I saved the video file in 'writer' variable name attaching that variable data also again thanks for the help...
Walter Roberson
Walter Roberson 2018년 4월 21일
편집: Walter Roberson 2018년 4월 21일
It is not possible to play a video writer object. Once the video writer object is closed, use one of the techniques to play the video by name. Or create a video player object and step(player, a) as you go through outputting the frames to the video writer object.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by