Text recognition from a dot-matrix display
Mostra commenti meno recenti
I have a video from which I extract image frames at a specified time interval. It is a video of reading from an oxygen online analyzer. I need to recognize the text in each extracted image using MATLAB and append that to a text file, instead of manually looking into each image and noting down the reading in a text file. I have tried to binarize the image and do OCR on the region containing the text alone (by getting the position of the region of interest using getPosition and drawRectangle). I have also used "seven-segment" as language model. Despite these, the recognized text is either empty character array or an array with irrelevant numbers. Can you suggest some techniques like pre-processing for better OCR of such images?

vid = VideoReader('D:\ChemE\MTech\MTP\PurityData\Closed_Pressurization_Vacuum\0.5LPM\30_c1.mp4');
numFrames = vid.NumberOfFrames;
n=numFrames;
fps = 30; %frames per second
fileID = fopen('D:\ChemE\MTech\MTP\PurityData\Closed_Pressurization_Vacuum\0.5LPM\30_c1.txt','w'); %open text file for writing
titl = "Time(s) Purity(%)"; % for the text file which will be appended with the text from OCR
fprintf(fileID,"%s\n",titl);
frames = read (vid,1); %read the first frame of the video to identify ROI
figure;imshow(frames);
rect = drawrectangle; % to select the region of interest (ROI)
roi = rect.Position;
figure(close);
for i = 1:fps:n
frames = read(vid,i); %read the ith frame (at interval of 1 second)
% set a file name for images
fname = ['D:\ChemE\MTech\MTP\PurityData\Closed_Pressurization_Vacuum\0.5LPM\30_c1\30_c1_' int2str(i),'.jpg'];
imwrite(frames,fname); %writes the frame to an image
I = imread(fname); % read the image
bI = imbinarize(rgb2gray(I)); %binarize the image after converting it to a grayscale image
ocrResults = ocr(bI,roi,Language = "seven-segment"); %recognize text
val = ocrResults.Text; %store the recognized text
conf = ocrResults.WordConfidences;
fprintf("The purity observed is ""%s"" with confidence %.4f \n", val, conf);
fprintf(fileID,'%.1f\t %s\n',(i-1)/30,val); %write the text to file
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Text Detection and Recognition 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!


