Separation of letters of license plates

2 次查看(过去 30 天)
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

回答(3 个)

Image Analyst
Image Analyst 2021-11-20
Use ocr() in the Computer Vision Toolbox.
  2 个评论
Blazej Staniak
Blazej Staniak 2021-11-20
I tried but I don't know how to use it exactly
Image Analyst
Image Analyst 2021-11-21
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');

请先登录,再进行评论。


yanqi liu
yanqi liu 2021-11-22
编辑:yanqi liu 2021-11-22
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 2021-11-22
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 个评论
Image Analyst
Image Analyst 2021-11-22
And what are you going to do once you have the letters into separate images? Get the number or letter they are, right? Well I did that for you and I got you the number. If you want to get each subimage, even though it is not necessary, you can use bwlabel and ismember
[labeledImage, numBlobs] = bwlabel(mask);
for k = 1 : numBlobs
% Extract and save.
thisBlob{k} = ismember(labeledImage, k);
imshow(thisBlob{k});
drawnow;
pause(0.3); % Wait long enough to see it before showing the next one.
end
Blazej Staniak
Blazej Staniak 2021-11-22
after dividing the letters into individual elements, I will want to recognize them

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by