Separation of letters of license plates
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (3)
Image Analyst
am 20 Nov. 2021
Use ocr() in the Computer Vision Toolbox.
2 Kommentare
Image Analyst
am 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/808329/image.png)
yanqi liu
am 22 Nov. 2021
Bearbeitet: yanqi liu
am 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]);
0 Kommentare
Blazej Staniak
am 22 Nov. 2021
2 Kommentare
Image Analyst
am 22 Nov. 2021
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
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!