Machine Learning Opencv and SVM License Plate Recognition System—Computer Science Course Design (Graduation Project)

License plate recognition system based on machine learning SVM

  • Download the complete code and reference report link of the license plate recognition system of the machine learning SVM algorithm in this article (or you can contact the blogger koukou (一一23七2五六98) to obtain the source code and report)< a i=1>https://download.csdn.net/download/shooter7/88548717

  • Here is a link to another system description: a handwritten digit recognition system based on machine learning KNN algorithm, which can be used in graduate courses. https://blog.csdn.net/shooter7/article/details/113337835

Summary

License plate recognition is an important research direction in pattern recognition and has a wide range of applications. It is regarded as a core technology for security and traffic operations and can be used in important areas such as automatic toll collection, traffic control, border protection, and vehicle theft. However, in some cases it doesn't work well due to different license plate colors. Therefore, license plate recognition not only has a wide range of applications, but also has important research significance.
This article proposes a license plate recognition system based on OpenCV and SVM. The system realizes automatic recognition of license plates by preprocessing, feature extraction and classification of license plate images. Specifically, this article first preprocesses the license plate image, including image enhancement, denoising, binarization and other operations to improve the quality of the license plate image. Then, this paper uses color features, shape features and texture features to extract features from license plate images to improve the recognition accuracy of license plate images. Finally, this article uses the SVM algorithm to classify license plate images and achieve automatic recognition of license plates. Through experimental verification, the license plate recognition system designed in this article has high recognition accuracy and speed, and can meet the needs of practical applications.

Debug import and run result graph

Insert image description here
Insert image description here

Insert image description here
Insert image description here

Import operation steps

  1. Install python and pycharm locally, unzip the source code file, and import pycharm
  2. Set up the venv virtual environment in pycharm's setting
  3. Install the corresponding packages in the virtual environment
matplotlib
numpy
opencv-python
opencv-python-headless
Pillow
PyQt5
  1. After the installation is complete, run mian_ui.py to open the GUI interface.
  2. Do not have Chinese characters in the installation path, opencv will report an error

Report and defense PPT

Insert image description here
Insert image description here
Insert image description here

key code

import os
import cv2
import random
import numpy as np

class SVM(object):
    def __init__(self, fn):
        self.fn = fn
        if os.path.exists(self.fn): #判断模型是否已经训练过了
            self.model = cv2.ml.SVM_load(self.fn) #如果模型已经训练过,则加载训练好的模型
        else:
            self.model = cv2.ml.SVM_create() #否则创建分类器,重新进行训练

    def train(self, samples, responses): #模型训练代码,samples为样本,responses为结果
        self.model.setKernel(cv2.ml.SVM_INTER) #使用线性核
        self.model.train(samples, cv2.ml.ROW_SAMPLE, responses) #对数据进行训练
        self.model.save(self.fn) #保存训练模型

    def predict(self, samples): #模型预测代码,samples为样本
        _, pred = self.model.predict(samples)
        return pred.ravel()

class Reader(object): #读取数据
    def __init__(self) -> None:
        self.svms2 = SVM('./param/chars2.svm') #读取字符数据
        self.svmsChinese = SVM('./param/chars2Chinese.svm') #读取汉字数据
        self.groups2 = np.load('./param/chars2.npy') #读取字符标签
        self.groupsChinese = np.load('./param/charsChinese.npy') #读取汉字标签


    def recognize_alnum(self, img) -> str: #识别字符
        ret = self.svms2.predict(img.reshape((1, -1)).astype('float32')).astype('int32')
        return self.groups2[ret]

    def recognize_chinese(self, img) -> str: #识别汉字
        ret = self.svmsChinese.predict(img.reshape((1, -1)).astype('float32')).astype('int32')
        return self.groupsChinese[ret]

def test():
    dataset_root = './dataset'
    # datasets = ['chars2']
    datasets = ['charsChinese']
    data = []
    groups = []
    for dataset in datasets:
        for group in os.listdir(dataset_root + 
                                '/' + dataset):
            for image in os.listdir(dataset_root + 
                                    '/' + dataset + 
                                    '/' + group):
                data.append(np.append(cv2.imread(dataset_root + 
                                                 '/' + dataset + 
                                                 '/' + group + 
                                                 '/' + image, 0).ravel(), len(groups)))
            groups.append(group)

    # np.save('./chars2.npy', np.array(groups))

    random.shuffle(data)
    data = np.array(data).astype('float32')

    len_train = (int)(data.shape[0] * 0.8)
    data_train = data[:len_train]
    data_pred = data[len_train:]

    svm = SVM('./chars2Chinese.svm')
    # svm.train(data_train[:, :-1], data_train[:, -1].ravel().astype('int32'))
    pred = svm.predict(data[:, :-1])
    print('accuracy: ', np.sum(pred == data[:, -1]) / pred.ravel().shape[0])


if __name__ == '__main__':
    reader = Reader()
    # img = cv2.imread('./dataset/chars2/V/gt_215_2.jpg', 0)
    # txt = reader.recognize_alnum(img)
    img = cv2.imread('./dataset/charsChinese/zh_shan/debug_chineseMat477.jpg', 0)
    txt = reader.recognize_chinese(img)
    print(txt)

Guess you like

Origin blog.csdn.net/shooter7/article/details/129935028