Convert Video Frames to Images
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mark Jecel Rapir
il 11 Ott 2018
Modificato: Image Analyst
il 17 Nov 2021
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!
0 Commenti
Risposta accettata
Image Analyst
il 11 Ott 2018
Modificato: Image Analyst
il 17 Nov 2021
I do that in my attached demo. See how I extract the frames and write them to disk.
5 Commenti
Walter Roberson
il 17 Nov 2021
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?
Image Analyst
il 17 Nov 2021
@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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!