| import matplotlib.pyplot as plt |
| import numpy as np |
| import cv2 |
| import tensorflow as tf |
| from sklearn.metrics import f1_score |
| from tensorflow.keras.models import load_model |
| from tensorflow.keras import optimizers |
| from tensorflow.keras.models import Sequential |
| from tensorflow.keras.preprocessing.image import ImageDataGenerator |
| from tensorflow.keras.layers import Dense, Flatten, MaxPooling2D, Dropout, Conv2D |
| import streamlit as st |
|
|
|
|
| |
| plate_cascade = cv2.CascadeClassifier('indian_license_plate.xml') |
| |
|
|
|
|
| model = load_model('licence_trained_model.h5', compile=False) |
|
|
|
|
|
|
|
|
| def detect_plate(img, text=''): |
| plate_img = img.copy() |
| roi = img.copy() |
| plate_rect = plate_cascade.detectMultiScale(plate_img, scaleFactor = 1.2, minNeighbors = 7) |
| for (x,y,w,h) in plate_rect: |
| roi_ = roi[y:y+h, x:x+w, :] |
| plate = roi[y:y+h, x:x+w, :] |
| cv2.rectangle(plate_img, (x+2,y), (x+w-3, y+h-5), (51,181,155), 3) |
| if text!='': |
| plate_img = cv2.putText(plate_img, text, (x-w//2,y-h//2), |
| cv2.FONT_HERSHEY_COMPLEX_SMALL , 0.5, (51,181,155), 1, cv2.LINE_AA) |
| |
| return plate_img, plate |
|
|
|
|
|
|
|
|
| |
| def display(img, title=''): |
| img = cv2.cvtColor(img_, cv2.COLOR_BGR2RGB) |
| fig = plt.figure(figsize=(10,6)) |
| ax = plt.subplot(111) |
| ax.imshow(img) |
| plt.axis('off') |
| plt.title(title) |
| plt.show() |
| |
|
|
|
|
| display(img,'input image') |
|
|
|
|
| ''' |
| |
| |
| |
| def segment_characters(image) : |
| |
| # Preprocess cropped license plate image |
| img_lp = cv2.resize(image, (333, 75)) |
| img_gray_lp = cv2.cvtColor(img_lp, cv2.COLOR_BGR2GRAY) |
| _, img_binary_lp = cv2.threshold(img_gray_lp, 200, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU) |
| img_binary_lp = cv2.erode(img_binary_lp, (3,3)) |
| img_binary_lp = cv2.dilate(img_binary_lp, (3,3)) |
| |
| LP_WIDTH = img_binary_lp.shape[0] |
| LP_HEIGHT = img_binary_lp.shape[1] |
| |
| # Make borders white |
| img_binary_lp |
| ''' |
|
|
|
|
|
|
| |
| def run(): |
| st.write('##### Traffic Sign Classifier') |
| |
| |
| with st.form(key='vehicle number plate'): |
| |
| |
| img= st.file_uploader("Upload a file of one of these format .JPEG/.JPG/.PNG file", accept_multiple_files=True) |
|
|
|
|
| |
| if __name__ == '__main__': |
| run() |
|
|
| |
|
|
|
|