필터 지우기
필터 지우기

Image recognition: extracting numbers from white paper

조회 수: 8 (최근 30일)
pldr-bny
pldr-bny 2019년 2월 10일
댓글: pldr-bny 2019년 2월 11일
I have a large dataset of coloured images, all with one person holding a white piece of paper with a printed number. I am trying to extract the number as a class label for each person. By binarizing the image and removing small areas I can create an image as shown. But from here, all implementations of the ocr function I have attempted fail to extract the number. I have also attempted using corner extraction, but this does not work easily as some candidates are obscuring the corners of the paper with their hands. Could anyone provide some tips on how to achieve this?
Code:
clc
clear all
close all
% Load an image
rgbImage = imread('person11.jpeg');
grayImage = rgb2gray(rgbImage);
% Binarize the image.
binaryImage = grayImage > 120;
% Remove small objects.
binaryImage = bwareaopen(binaryImage, 5000);
figure(1)
imshow(binaryImage);
title('Cleaned Binary Image');
% Use the 'CharacterSet' parameter to constrain OCR
results = ocr(binaryImage, 'CharacterSet', '0123456789', 'TextLayout','Block');
results.Text
Output lots of different numbers, not 11!
Image:

채택된 답변

Image Analyst
Image Analyst 2019년 2월 11일
Stephanie:
I'm sure you've got it working by now, but for others (or if you want to compare your algorithm to mine), here is how I would do it (attached). You could make it a lot faster if you didn't have the background be the same color as the sheet of paper the subject is holding. That could save us time because we wouldn't have to spend a lot of time to separate the two with an erosion. Have the background be some vivid color - any color except white or black or gray.
0000 Screenshot.png
  댓글 수: 1
pldr-bny
pldr-bny 2019년 2월 11일
Thank you for providing some very useful pointers in your example! I had not used the strel object before so that alone has helped me a lot in writing my own solution.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 2월 10일
편집: Image Analyst 2019년 2월 10일
First I would do color segmentation to find neutral colored regions (not what you have done). Use the Color Thresholder app on the Apps tab of the MATLAB tool ribbon to do this.
Then I would crop the region to only the paper they are holding. Then I would call the ocr() function in the Computer Vision System Toolbox.
Attach your original image if you still need help and I might be able to do some of it if you're unable to and I have time.
  댓글 수: 2
pldr-bny
pldr-bny 2019년 2월 10일
편집: pldr-bny 2019년 2월 10일
Thank you that's really helpful! I will try to implement your suggestions, but how would I define the region to crop given the position in the frame is slightly different for each person? Here is the original image if you are prepared to have a look for me.
Image Analyst
Image Analyst 2019년 2월 10일
I just got back after being away all day. What did you accomplish while I was gone?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computer Vision Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by