当前位置: 代码迷 >> 综合 >> MATLAB 车牌识别程序介绍 SVM、神经网络[毕业设计]
  详细解决方案

MATLAB 车牌识别程序介绍 SVM、神经网络[毕业设计]

热度:94   发布时间:2023-10-25 14:55:04.0

程序付费分享:

微信:1075933062

这个文章介绍使用matlab 识别车牌内的信息:

识别的步骤如下:

1、导入图片

2、定位到车牌矩形框的位置

3、进行畸形矫正

4、字符分割

5、生成字符库

6、SVM训练

7、基于SVM 车牌识别系统 的设计

由于需要进行SVM训练 所以需要建立一个对应的车牌字符库

下面建立一个生成字符库的APP ,来生成对应的库

然后会生成一个下面这样的字符库最后可以通过SVM 训练

关于SVM 的训练可以参考这篇博客
基于MATLAB,使用SVM和ANN实现车牌识别_weixin_42864037的博客-CSDN博客_matlab svm车牌识别

由于该程序的图片是灰度的所以需要对函数进行相应的更改 然后就可以进行训练了:

提取图片特征函数:

function [trainingFeatures,trainingLabels,testFeatures,testLabels]=extractFeature(trainingSet,testSet)
%% 确定特征向量尺寸
img = read(trainingSet(1),1);
%转化为灰度图像
% img=im2gray(img);
% %转化为2值图像
% lvl = graythresh(img);
% img = im2bw(img, lvl);
img=imresize(img,[256 256]);
cellSize = [4 4];
[hog_feature, vis_hog] = extractHOGFeatures(img,'CellSize',cellSize);
glcm_feature = getGLCMFeatures(img);
SizeOfFeature = length(hog_feature)+ length(glcm_feature);trainingFeatures = [];
trainingLabels   = [];
for digit = 1:numel(trainingSet)       numImages = trainingSet(digit).Count;features  = zeros(numImages, SizeOfFeature, 'single');%初始化特征向量% 遍历每张图片for i = 1:numImagesimg = read(trainingSet(digit), i);% 取出第i张图片        
%         img=rgb2gray(img);                % 转化为灰度图像
%         glcm_feature = getGLCMFeatures(img);  % 提取GLCM特征       
%         lvl = graythresh(img);            % 阈值化
%         img = im2bw(img, lvl);            % 转化为2值图像img=imresize(img,[256 256]);% 提取HOG特征[hog_feature, vis_hog] = extractHOGFeatures(img,'CellSize',cellSize);       % 合并两个特征features(i, :) = [hog_feature glcm_feature];end% 使用图像描述作为训练标签labels = repmat(trainingSet(digit).Description, numImages, 1);  % 逐个添加每张训练图片的特征和标签trainingFeatures = [trainingFeatures; features];trainingLabels   = [trainingLabels; labels];       
endtestFeatures = [];
testLabels   = [];
for digit = 1:numel(testSet)           numImages = testSet(digit).Count;    %初始化特征向量features  = zeros(numImages, SizeOfFeature, 'single');    for i = 1:numImages        img = read(testSet(digit), i);        %转化为灰度图像
%         img=rgb2gray(img);
%         glcm_feature = getGLCMFeatures(img);        %转化为2值图像
%         lvl = graythresh(img);
%         img = im2bw(img, lvl);img=imresize(img,[256 256]);[hog_4x4, vis4x4] = extractHOGFeatures(img,'CellSize',cellSize);features(i, :) = [hog_4x4 glcm_feature];end    % 使用图像描述作为训练标签labels = repmat(testSet(digit).Description, numImages, 1);    testFeatures = [testFeatures; features];testLabels=[testLabels; labels];end
end
function [features] = getGLCMFeatures(image)
features_all  = [];
for i = 1:10glcm = graycomatrix(image, 'Offset', [0,i]);stats = graycoprops(glcm);glcm45 = graycomatrix(image, 'Offset', [-i,i]);stats45 = graycoprops(glcm45);glcm90 = graycomatrix(image, 'Offset', [-i,0]);stats90 = graycoprops(glcm90);glcm135 = graycomatrix(image, 'Offset', [-i,-i]);stats135 = graycoprops(glcm135);stats7x4 = [stats.Contrast stats.Correlation stats.Energy stats.Homogeneity;stats45.Contrast stats45.Correlation stats45.Energy stats45.Homogeneity;stats90.Contrast stats90.Correlation stats90.Energy stats90.Homogeneity;stats135.Contrast stats135.Correlation stats135.Energy stats135.Homogeneity];features_all = [features_all mean(stats7x4,1) std(stats7x4,0,1)];
end
features = features_all;
clear;
dir=('\DataWork\车牌识别SVM\GUI\train');
testdir=('\DataWork\车牌识别SVM\GUI\train');
trainingSet = imageSet(dir,'recursive');
testSet = imageSet(testdir,'recursive');[trainingFeatures,trainingLabels,testFeatures,testLabels]=extractFeature(trainingSet,testSet);classifier = fitcecoc(trainingFeatures, trainingLabels);
save classifier.mat classifier -v7.3;
predictedLabels = predict(classifier, testFeatures);confMat=confusionmat(testLabels, predictedLabels)
accuracy=(confMat(1,1)/sum(confMat(1,:))+confMat(2,2)/sum(confMat(2,:)))/2
          
load classifier.mat;     % 加载训练好的SVM模型            img=imread("img034-00026.png");                
glcm_feature = getGLCMFeatures(img);     %提取GLCM特征                
% lvl = graythresh(img);                
% img = im2bw(img, lvl);                
img=imresize(img,[256 256]);                
[hog_4x4, ~] = extractHOGFeatures(img,'CellSize',[4 4]);      %提取HOG特征                
testFeature = [hog_4x4 glcm_feature];       %合并特征                                
predictedLabel = predict(classifier, testFeature) %使用predict函数进行分类                

  相关解决方案