LPR 与 MATLAB:如何仅找到一个矩形?

问题描述 投票:0回答:1

我在 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

盘子都有白色背景。目前,我使用矩形的宽高比来选择输出的候选区域。在白色汽车的情况下,除了几个其他不相关的矩形外,还给出了车牌矩形。我可以使用什么方法只获得一个输出:车牌? 另外,当我在一辆黑色汽车上运行代码时,我根本找不到车牌。也许这是因为汽车的颜色与车牌边缘相同。 有没有边缘检测的替代方法可以避免这个问题?

matlab computer-vision automatic-license-plate-recognition
1个回答
2
投票

试试这个!!!

I = imread('http://8pic.ir/images/88146564605446812704.jpg');
im=rgb2gray(I);
sigma=1;
f=zeros(128,128);
f(32:96,32:96)=255;
[g3, t3]=edge(im, 'canny', [0.04 0.10], sigma);
se=strel('rectangle', [1 1]);
BWimage=imerode(g3,se);
gg = imclearborder(BWimage,8);
bw = bwareaopen(gg,200);
gg1 = imclearborder(bw,26);
imshow(gg1);

%Dilation
Id = imdilate(gg1, strel('diamond', 1));
imshow(Id);

%Fill
If = imfill(Id, 'holes');
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*1 && PlateExtent >= 0.7
        im2 = imcrop(I, RectangleOfChoice);
        %figure, imshow(I);
        figure, imshow(im2);
    end
end
© www.soinside.com 2019 - 2024. All rights reserved.