前言
本文使用的數(shù)據(jù)集包含43種交通標(biāo)志,使用opencv以及卷積神經(jīng)網(wǎng)絡(luò)訓(xùn)練模型,識(shí)別交通標(biāo)志,使用pyqt5制作交通標(biāo)志識(shí)別GUI的界面。
效果預(yù)覽
如視頻中所示,可以選擇交通標(biāo)志,然后可以進(jìn)行圖像預(yù)處理操作,如灰度化,邊緣檢測(cè)等,最后可以點(diǎn)擊識(shí)別按鈕進(jìn)行識(shí)別。
交通標(biāo)志識(shí)別
數(shù)據(jù)集下載地址
數(shù)據(jù)集中共包含43種交通標(biāo)志!
數(shù)據(jù)集下載地址:https://pan.baidu.com/wap/init?surl=5v14ieSPZntBTDzKVckEgA
提取碼:39q4文章來源:http://www.zghlxwxcb.cn/news/detail-509897.html
訓(xùn)練模型
下面是訓(xùn)練模型的代碼文章來源地址http://www.zghlxwxcb.cn/news/detail-509897.html
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 # 迭代次數(shù)
epochs_val = 10 # 整個(gè)訓(xùn)練集訓(xùn)練次數(shù)
imageDimesions = (32, 32, 3) # 32*32的彩色圖
testRatio = 0.2 # if 1000 images split will 200 for testing 測(cè)試集占比
validationRatio = 0.2 # if 1000 images 20% of remaining 800 will be 160 for validation 驗(yàn)證機(jī)占比
###################################################
############################### Importing of the Images 加載圖像與標(biāo)簽
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(" ")
# 存著對(duì)應(yīng)的圖片信息和標(biāo)簽
images = np.array(images)
classNo = np.array(classNo)
############################### Split Data 分割test集和驗(yàn)證集
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
到了這里,關(guān)于Opencv交通標(biāo)志識(shí)別的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!