How do I create a video mp4 output from the following code?
4 次查看(过去 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!