Convert Video Frames to Images

Good Day!
I am trying to convert video frames to images and consequently process those images for character recognition. I found the code here and it goes this way
% Video to Frame Convertion
file=VideoReader(filename);
filename= (filename); % to get inforamtaion abt video file
frm_cnt = file.NumberOfFrames; % No.of frames in the video file
h = waitbar(0,'Please wait...');
font = '.bmp';
for i=1:frm_cnt
frm(i) = VideoReader(filename,i); % read the Video file
RGBimg = frame2im(frm(i)); % Convert Frame to image file
strNmae = num2str(i);
writeName = strcat(strNmae,font);
% imwrite(RGBimg,writeName);
%figure(1), imshow(RGBimg); % Color Image
grayImg = rgb2gray(RGBimg); %convert gray
% figure(2), imshow(grayImg);
% median filter is applied for smoothing and unwanted noise removal
grayImg = medfilt2(grayImg,[3 3]);
% dynamic thresholding is appiled
grayImg = adapthisteq(grayImg);
% figure(3), imshow(grayImg);
c
the error message goes like this
% Error using VideoReader/set Invalid input argument type to 'set'. Type 'help set' for options. Error in VideoReader (line 176) set(obj, varargin{:}); Error in LPRmain (line 69) frm(i) = VideoReader(filename,i); % read the Video file
Can anyone please help me how to remove this error? TIA!

 Risposta accettata

Image Analyst
Image Analyst il 11 Ott 2018
Modificato: Image Analyst il 17 Nov 2021

1 voto

I do that in my attached demo. See how I extract the frames and write them to disk.

5 Commenti

I am struggling to incorporate your demo on the mine. I used read but says dimension mismatch
for frame=1:numberOfFrames frm(i)=read(file, i)
Then show how you modified my code, and attach your video.
Hey!
I tried out your code, it worked very well. However, the output images are in somewhat low quality although the original video is of higher resolution. I tried to figure out where in the code are we dealing with the properties of the image frames... but not able to do so, can you help @Image Analyst
The lower resolution is a side effect of the method used to insert the frame numbers into the movie. Do you need the frame numbers to be drawn? If not, then there are better ways to write out the frames.
If you do need the frame numbers inserted into the video, then do you have the Computer Vision Toolbox?
@Aman Swaraj, Walter's right. If you have the Computer Vision Toolbox, you can use insertText() and then use imwrite() instead of getframe(). That is a very old demo in my original Answer. I have since updated it to use the Computer VIsion Toolbox, if you have it. That newer code is attached. Here are the key lines:
if wantsFrameStamps
thisFrame = insertText(thisFrame, [5, 5], caption, 'FontSize', 20, 'TextColor', 'yellow', 'BoxColor', 'black'); % Burn text into image
end
imwrite(thisFrame, outputFullFileName) % Original size image
I have made the suggestion to the Mathworks that insertText() should be made part of base MATLAB.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing and Computer Vision in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by