Skip to content

Instantly share code, notes, and snippets.

View quangnhat185's full-sized avatar

Quang Nguyen quangnhat185

View GitHub Profile
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connect COLAB with Google Drive"
]
},
{
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@quangnhat185
quangnhat185 / import_library.py
Last active July 29, 2020 09:35
Detection License Plate with Wpod-Net
import cv2
import numpy as np
import matplotlib.pyplot as plt
from local_utils import detect_lp
from os.path import splitext, basename
from keras.models import model_from_json
import glob
%matplotlib.inline
@quangnhat185
quangnhat185 / load_model.py
Last active April 11, 2020 07:34
Load pre-trained model
def load_model(path):
try:
path = splitext(path)[0]
with open('%s.json' % path, 'r') as json_file:
model_json = json_file.read()
model = model_from_json(model_json, custom_objects={})
model.load_weights('%s.h5' % path)
print("Loading model successfully...")
return model
except Exception as e:
def preprocess_image(image_path,resize=False):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = img / 255
if resize:
img = cv2.resize(img, (224,224))
return img
# Create a list of image paths
image_paths = glob.glob("Plate_examples/*.jpg")
print("Found %i images..."%(len(image_paths)))
# Visualize data in subplot
fig = plt.figure(figsize=(12,8))
cols = 5
rows = 4
fig_list = []
for i in range(cols*rows):
def get_plate(image_path, Dmax=608, Dmin=256):
vehicle = preprocess_image(image_path)
ratio = float(max(vehicle.shape[:2])) / min(vehicle.shape[:2])
side = int(ratio * Dmin)
bound_dim = min(side, Dmax)
_ , LpImg, _, cor = detect_lp(wpod_net, vehicle, bound_dim, lp_threshold=0.5)
return LpImg, cor
# Obtain plate image and its coordinates from an image
test_image = image_paths[0]
def draw_box(image_path, cor, thickness=3):
pts=[]
x_coordinates=cor[0][0]
y_coordinates=cor[0][1]
# store the top-left, top-right, bottom-left, bottom-right
# of the plate license respectively
for i in range(4):
pts.append([int(x_coordinates[i]),int(y_coordinates[i])])
pts = np.array(pts, np.int32)
# Viualize all obtained plate images
fig = plt.figure(figsize=(12,6))
cols = 5
rows = 4
fig_list = []
for i in range(cols*rows):
fig_list.append(fig.add_subplot(rows,cols,i+1))
title = splitext(basename(image_paths[i]))[0]
fig_list[-1].set_title(title)
# Extract mutiple plate license in one image
multiple_plates_image = "Plate_examples/multiple_plates.png"
LpImg,cor = get_plate(multiple_plates_image)
print("Detect %i plate(s) in"%len(LpImg),splitext(basename(multiple_plates_image))[0])
# Visualize the original image
plt.figure(figsize=(10,5))
plt.axis(False)