我在 MATLAB 中使用以下代码来查找包含汽车牌照的矩形:
clc
clear
close all
%Open Image
I = imread('plate_1.jpg');
figure, imshow(I);
%Gray Image
Ib = rgb2gray(I);
figure,
subplot(1,2,1), imshow(Ib);
%Enhancement
Ih = histeq(Ib);
subplot(1,2,2), imshow(Ih);
figure,
subplot(1,2,1), imhist(Ib);
subplot(1,2,2), imhist(Ih);
%Edge Detection
Ie = edge(Ih, 'sobel');
figure,
subplot(1,2,1), imshow(Ie);
%Dilation
Id = imdilate(Ie, strel('diamond', 1));
subplot(1,2,2), imshow(Id);
%Fill
If = imfill(Id, 'holes');
figure, imshow(If);
%Find Plate
[lab, n] = bwlabel(If);
regions = regionprops(lab, 'All');
regionsCount = size(regions, 1) ;
for i = 1:regionsCount
region = regions(i);
RectangleOfChoice = region.BoundingBox;
PlateExtent = region.Extent;
PlateStartX = fix(RectangleOfChoice(1));
PlateStartY = fix(RectangleOfChoice(2));
PlateWidth = fix(RectangleOfChoice(3));
PlateHeight = fix(RectangleOfChoice(4));
if PlateWidth >= PlateHeight*3 && PlateExtent >= 0.7
im2 = imcrop(I, RectangleOfChoice);
figure, imshow(im2);
end
end
盘子都有白色背景。目前,我使用矩形的宽高比来选择输出的候选区域。在白色汽车的情况下,除了其他几个不相关的矩形之外,这还给出了板矩形。我可以使用什么方法只获得一个输出:车牌?另外,当我在黑色汽车上运行代码时,我根本找不到车牌。也许那是因为汽车的颜色与板边缘相同。是否有任何替代边缘检测的方法来避免这个问题?