Convert Video Frames to Images

24 次查看(过去 30 天)
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!

采纳的回答

Image Analyst
Image Analyst 2018-10-11
编辑:Image Analyst 2021-11-17
I do that in my attached demo. See how I extract the frames and write them to disk.
  5 个评论
Walter Roberson
Walter Roberson 2021-11-17
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
Image Analyst 2021-11-17
@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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by