How can I remove distortion from video files?

24 vues (au cours des 30 derniers jours)
EGR
EGR le 23 Juil 2019
Commenté : Luxator le 15 Déc 2020
Hi--
How can the parameters/outputs from the cameraCalibrator app be applied to video files to remove distortion from mp4 files? I have only been able to successfuly remove distortion from images using the camera parameters and code below. Thank you!
%file name
filename='D:\SideViewCalibration\CalibrationObjectSide2.jpg';
%Coefficients measured from CameraClibrator
IntrinsicMatrix=[987.111820921548,0,0;0,987.149003204452,0;539.716264741029,481.311994646507,1];
radialDistortion = [-0.301068525976252, 0.0836710021489489 ];
cameraParams = cameraParameters('IntrinsicMatrix',IntrinsicMatrix,'RadialDistortion',radialDistortion);
%Open/read file, apply undistortion, and resize to fit in screen/window
I = imread(filename);
J = undistortImage(I,cameraParams);
imshow(J);
imsave;

Réponses (1)

Sai Bhargav Avula
Sai Bhargav Avula le 2 Août 2019
Modifié(e) : Sai Bhargav Avula le 2 Août 2019
A video file can be undistorted by looping through each frame and undistorting them . vision.VideoFileReader() function will create the video file reader. vision.VideoPlayer() sets the player window. vision.VideoFileWriter sets the video file writer variable. Using these you can undistort the video file.
This sample code will provide a better understanding.
vfrUndist = vision.VideoFileReader(videoFile); % Video File Variable
vpUndist = vision.VideoPlayer(required name value arguments); % Player
vfwUdist = vision.VideoFileWriter(required name-value arguments); % video file writer variable
% Looping through each frame and undistorting each frame
while ~isDone(vfrUndist)
frame_undist = step(vfrUndist);
frame = undistortImage(frame_undist,cameraParams);
% write to the video file
step(vfwUndist, frame);
end
release(vpUndist);
release(vfrUndist);
release(vfwUdist);
  3 commentaires
Sai Bhargav Avula
Sai Bhargav Avula le 6 Août 2019
Modifié(e) : Sai Bhargav Avula le 6 Août 2019
For vision.VideoPlayer, vision.VideoFileWriter will give you indepth understanding.
For example
vpUndist = vision.VideoPlayer('Position', [100, 100, 1280, 720]);
vfwUdist = vision.VideoFileWriter(NewFileName, 'FrameRateAs ',...
videoFileReaderUNDIST.info.VideoFrameRate, 'FileFormat', 'MPEG4');
The final video can be played on on any player that supports the video codec
Hope this helps!!!
Luxator
Luxator le 15 Déc 2020
Hello, I had the same problem and tried your code
vfrUndist = vision.VideoFileReader('Filename.mp4'); % Video File Variable
vpUndist = vision.VideoPlayer('Position', [100, 100, 1280, 720]); % Player
vfwUdist = vision.VideoFileWriter('NewFileName', 'FrameRateAs ',...
videoFileReaderUNDIST.info.VideoFrameRate, 'FileFormat', 'MPEG4');
% Looping through each frame and undistorting each frame
while ~isDone(vfrUndist)
frame_undist = step(vfrUndist);
frame = undistortImage(frame_undist,cameraParams);
% write to the video file
step(vfwUndist, frame);
end
release(vpUndist);
release(vfrUndist);
release(vfwUndist);
But there is always a mistake in the vfwUdist line, Matlab is unable to resolve the name "videoFileReaderUNDIST.info.VideoFrameRate".
should i add here something?
if i remove anything form this line there is an other mistake, that there are to many value inputs.
Furthermore there is a problem with the video input, i took pictures and videos with the same camera, but they are not the same size, how can i fix this?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by