Convert Video Frames to Images

조회 수: 8 (최근 30일)
Mark Jecel Rapir
Mark Jecel Rapir 2018년 10월 11일
편집: Image Analyst 2021년 11월 17일
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에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by