Opencv交通标志识别

您所在的位置:网站首页 logo识别算法库 Opencv交通标志识别

Opencv交通标志识别

2024-07-17 20:23| 来源: 网络整理| 查看: 265

文章目录 前言 效果预览 数据集下载地址 训练模型 模型预测 项目结构及源码下载

前言

本文使用的数据集包含43种交通标志,使用opencv以及卷积神经网络训练模型,识别交通标志,使用pyqt5制作交通标志识别GUI的界面。

效果预览

如视频中所示,可以选择交通标志,然后可以进行图像预处理操作,如灰度化,边缘检测等,最后可以点击识别按钮进行识别。

交通标志识别

数据集下载地址

数据集中共包含43种交通标志! 数据集下载地址:https://pan.baidu.com/wap/init?surl=5v14ieSPZntBTDzKVckEgA 提取码:39q4

训练模型

下面是训练模型的代码

import numpy as np import matplotlib.pyplot as plt from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense from tensorflow.keras.optimizers import Adam from tensorflow.python.keras.utils.np_utils import to_categorical from tensorflow.keras.layers import Dropout, Flatten from tensorflow.keras.layers import Conv2D, MaxPooling2D import cv2 from sklearn.model_selection import train_test_split import pickle import os import pandas as pd import random from tensorflow.keras.preprocessing.image import ImageDataGenerator ################# Parameters ##################### path = "./data/myData" # folder with all the class folders labelFile = './data/labels.csv' # file with all names of classes batch_size_val = 50 # how many to process together steps_per_epoch_val = 446 # 迭代次数 epochs_val = 10 # 整个训练集训练次数 imageDimesions = (32, 32, 3) # 32*32的彩色图 testRatio = 0.2 # if 1000 images split will 200 for testing 测试集占比 validationRatio = 0.2 # if 1000 images 20% of remaining 800 will be 160 for validation 验证机占比 ################################################### ############################### Importing of the Images 加载图像与标签 count = 0 images = [] classNo = [] myList = os.listdir(path) print("Total Classes Detected:", len(myList)) noOfClasses = len(myList) print("Importing Classes.....") for x in range(0, len(myList)): myPicList = os.listdir(path + "/" + str(count)) for y in myPicList: curImg = cv2.imread(path + "/" + str(count) + "/" + y) images.append(curImg) classNo.append(count) print(count, end=" ") count += 1 print(" ") # 存着对应的图片信息和标签 images = np.array(images) classNo = np.array(classNo) ############################### Split Data 分割test集和验证集 X_train, X_test, y_train, y_test = train_test_split(images, classNo, test_size=testRatio) X_train, X_validation, y_train, y_validation = train_test_split(X_train, y_train, test_size=validationRatio) # X_train = ARRAY OF IMAGES TO TRAIN # y_train = CORRESPONDING CLASS ID ############################### TO CHECK IF NUMBER OF IMAGES MATCHES TO NUMBER OF LABELS FOR EACH DATA SET print("Data Shapes") print("Train", end=""); print(X_train.shape, y_train.shape) print("Validation", end=""); print(X_validation.shape, y_validation.shape) print("Test", end=""); print(X_test.shape, y_test.shape) assert (X_train.shape[0] == y_train.shape[ 0]), "The number of images in not equal to the number of lables in training set" assert (X_validation.shape[0] == y_validation.shape[ 0]), "The number of images in not equal to the number of lables in validation set" assert (X_test.shape[0] == y_test.shape[0]), "The number of images in not equal to the number of lables in test set" assert (X_train.shape[1:] == (imageDimesions)), " The dimesions of the Training images are wrong " assert (X_validation.


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3