using OCR on a custom, discontinuous font

조회 수: 16 (최근 30일)
Tae Lim
Tae Lim 2021년 1월 19일
답변: yanqi liu 2021년 2월 1일
Hello,
I need help using an OCR to extract numbers from a video. I have a few video files, each goes over an hour, that recorded pressure. I am trying to extract data (4 digit numbers) from these videos by 1) extract certain number of frames and save them as png files, and 2) use OCR to read values off from each of the png file. A sample picture is shown below. This collage image contains 71 frames. I tried using 'ocrTrainer' with over 50 frames but I couldn't make Matlab read any values from the images. The non-continuous shape of the font also makes it hard to use ocrTrainer. Matlab recognized each of the digitized lines that form numbers as separate numbers and required a lot of manual manipulation to correctly define ROI. Hence, using a large number of frames for training becomes a challenge. I am wondering if there's an easy way to use ocrTrainer or if Matlab can import/use the type of font that resemble this. So far I was not able to identify any default font that looks like this.
Thank you in advance for your comments!

답변 (2개)

yanqi liu
yanqi liu 2021년 2월 1일
use cnn to make self ocr
clc; clear all; close all;
x = imread('ceshi.png');
y = rgb2hsv(x);
v = mat2gray(y(:,:,3));
bw = im2bw(v, 0.7);
bw2 = bwareaopen(bw, 100);
bw3 = bwareafilt(bw2, 1);
bw2(bw3) = 0;
bw2 = imclose(bw2, strel('line', 10, 90));
sz = size(bw2);
bw3 = imclose(bw2, strel('line', round(sz(2)*0.5), 0));
[L, num] = bwlabel(bw3);
stats = regionprops(L);
figure; imshow(x);
for i = 1 : length(stats)
rect = round(stats(i).BoundingBox);
bwt = bw2;
bwt(L~=i) = 0;
stats2 = regionprops(bwt);
for j = 1:length(stats2)
rect2 = round(stats2(j).BoundingBox);
bwt2 = imcrop(bwt, rect2);
hold on; rectangle('Position', rect2, 'EdgeColor', 'c', 'LineWidth', 2);
end
end

yanqi liu
yanqi liu 2021년 2월 1일
or = ocr(~bwt2,'TextLayout' ,'Block','CharacterSet','0123456789');

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by