How do I create a video mp4 output from the following code?
조회 수: 5 (최근 30일)
이전 댓글 표시
I am using Video Stabilization Using Point Feature Matching - MATLAB & Simulink (mathworks.com) code to stabilze a video. I am wanting to adapt it for my own use. The code uses the Computer Vision Toolbox video player, but I would like to have an mp4 output rather than just the MATLAB videoplayer that only works 20% of the time. Below is the code (Step 6 of the link) I want to change. I am not quite sure how to create an MP4 output.
% Reset the video source to the beginning of the file
read(hVideoSrc,1);
hVPlayer = vision.VideoPlayer; % Create video viewer
% Process all frames in the video
movMean = rgb2gray(im2single(readFrame(hVideoSrc)));
imgB = movMean;
imgBp = imgB;
correctedMean = imgBp;
ii = 2;
cumulativeTform = simtform2d;
while hasFrame(hVideoSrc) && ii < 10
% Read in new frame
imgA = imgB; % z^-1
imgAp = imgBp; % z^-1
imgB = rgb2gray(im2single(readFrame(hVideoSrc)));
movMean = movMean + imgB;
% Estimate transformation from frame A to frame B, and fit as an s-R-t
tformAffine = cvexEstStabilizationTform(imgA,imgB);
sRtTform = cvexTformToSRT(tformAffine);
cumulativeTform = simtform2d(cumulativeTform.A * sRtTform.A);
imgBp = imwarp(imgB,cumulativeTform,OutputView=imref2d(size(imgB)));
% Display as color composite with last corrected frame
step(hVPlayer,imfuse(imgAp,imgBp,ColorChannels='red-cyan'));
correctedMean = correctedMean + imgBp;
ii = ii+1;
end
correctedMean = correctedMean/(ii-2);
movMean = movMean/(ii-2);
% Here you call the release method on the objects to close any open files
% and release memory.
release(hVPlayer);
댓글 수: 0
채택된 답변
Walter Roberson
2022년 10월 31일
Note that the step() call is entirely valid but in the last years the style is to use the name of the video object as a function. Instead of
step(object, data)
You would now typically write
object(data)
댓글 수: 2
Walter Roberson
2022년 11월 1일
video_filename = 'SomeAppropriateFile.mp4';
% Reset the video source to the beginning of the file
read(hVideoSrc,1);
hVWriter = VideoWriter(video_filename);
open(hVWriter);
% Process all frames in the video
movMean = rgb2gray(im2single(readFrame(hVideoSrc)));
imgB = movMean;
imgBp = imgB;
correctedMean = imgBp;
ii = 2;
cumulativeTform = simtform2d;
while hasFrame(hVideoSrc) && ii < 10
% Read in new frame
imgA = imgB; % z^-1
imgAp = imgBp; % z^-1
imgB = rgb2gray(im2single(readFrame(hVideoSrc)));
movMean = movMean + imgB;
% Estimate transformation from frame A to frame B, and fit as an s-R-t
tformAffine = cvexEstStabilizationTform(imgA,imgB);
sRtTform = cvexTformToSRT(tformAffine);
cumulativeTform = simtform2d(cumulativeTform.A * sRtTform.A);
imgBp = imwarp(imgB,cumulativeTform,OutputView=imref2d(size(imgB)));
% Display as color composite with last corrected frame
hVWriter( imfuse(imgAp,imgBp,ColorChannels='red-cyan') );
correctedMean = correctedMean + imgBp;
ii = ii+1;
end
correctedMean = correctedMean/(ii-2);
movMean = movMean/(ii-2);
% Here you call the release method on the objects to close any open files
% and release memory.
close(hVWriter);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!