Separation of letters of license plates

5 views (last 30 days)
Blazej Staniak
Blazej Staniak on 20 Nov 2021
Commented: Blazej Staniak on 22 Nov 2021
Hello, as in the tilt, I would like to separate the individual letters of the registration plate. Can anyone tell me how to do this?
I would like to get the same effect as in the second photo

Answers (3)

Image Analyst
Image Analyst on 20 Nov 2021
Use ocr() in the Computer Vision Toolbox.
  2 Comments
Image Analyst
Image Analyst on 21 Nov 2021
Wow. Very strange. After getting the binary image from the screenshot you posted, I just did
% Do OCR on it.
txt = ocr(mask)
letters = strtrim(txt.Text)
and it worked fine. What did you do? Here is the full demo.
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'obraz_2021-11-20_110914.png';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the blue channel.
grayImage = grayImage(:, :, 3);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(3, 1, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
drawnow;
% Crop the figure to get just the image, not all the tick labels and toolbars and surrounding blank space.
grayImage = grayImage(128:345, 189:1165)
% Display the image.
subplot(3, 1, 2);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Cropped Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
%--------------------------------------------------------------------------------------------------------
% Get a mask using thresholding.
mask = ~imbinarize(grayImage);
mask = imclearborder(mask);
% Get rid of blobs less than 300 pixels in area.
% mask = bwareaopen(mask, 300);
% Display the image.
subplot(3, 1, 3);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask/Binary/Logical Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Do OCR on it.
txt = ocr(mask)
letters = strtrim(txt.Text)
caption = sprintf('Mask/Binary/Logical Image. Text = %s', letters);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');

Sign in to comment.


yanqi liu
yanqi liu on 22 Nov 2021
Edited: yanqi liu on 22 Nov 2021
sir,may be use some image segment,such as
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/807304/obraz_2021-11-20_110914.png');
img2 = imcrop(img, [94 129 1086 217]);
bw = im2bw(img2);
bw = ~bw;
bw = imclearborder(bw);
bw = bwareaopen(bw, round(numel(bw)*0.01));
[L,num] = bwlabel(bw);
stats = regionprops(L);
rects = cat(1, stats.BoundingBox);
rects = sortrows(rects, 1);
ims = [];
figure('Color','c');
for i = 1 : size(rects, 1)
ims{i} = imcrop(img2, round(rects(i,:)));
subplot(1,size(rects, 1),i); imshow(ims{i}, []);
end
figure; montage(ims, 'Size', [1 7], 'BackgroundColor', 'r', 'BorderSize', [2 2]);

Blazej Staniak
Blazej Staniak on 22 Nov 2021
This is not what I wanted, I have the code, the photo of this license plate I received from the whole photo of the car, so the effect of the cut plate is part of my program. Now I just need to separate the letters
  2 Comments
Blazej Staniak
Blazej Staniak on 22 Nov 2021
after dividing the letters into individual elements, I will want to recognize them

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by