Code Explain
Code Explain
Code Explain
txt
import cv2 #thu vien cv2
import tkinter as tk #thu vien GUI
from tkinter import *
from tkinter.ttk import *
import numpy as np # thu vien mang array de xu ly anh
import tkinter.font as font
import PIL.Image,PIL.ImageTk # thu vien chuyen doi anh de hien thi
from tkinter import filedialog
import imutils
from tkinter import messagebox
window_=Tk()
window_.title("License Plate Recognize")
frame_camera=tk.Frame(window_, height=400, background="bisque")
frame_button=tk.Frame(window_, width=100, height=100,background="bisque")
canv= Canvas(frame_camera,width=500,height=400,bg='black')
canv_2=Canvas(frame_camera,width=500,height=400,bg='black')
dir_file=""
select_now= 0
img=np.zeros((504,304,3),np.uint8)
#new_image=np.zeros((504,304,3),np.uint8)
char_list = '0123456789ABCDEFGHKLMNPRSTUVXYZ'
dim=(0,0)
def sort_contours(cnts):
reverse = False
i = 0
boundingBoxes = [cv2.boundingRect(c) for c in cnts]
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),
key=lambda b: b[1][i], reverse=reverse))
return cnts
def start():
global img
global dim
print(dim)
#global new_image
#print("start")
try:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("gray-1", gray)
gray = cv2.bilateralFilter(gray, 13, 15, 15)
cv2.imshow("bilafilter-2", gray)
edged = cv2.Canny(gray, 30, 200)
def select():
global img
global dim
print("select")
window_.filename = filedialog.askopenfile(title="Select", filetypes=(("jpg",
"*.jpg"), ("All", "*.*")))
#print(window_.filename.name)
img = cv2.imread(window_.filename.name)
para_max = max(img.shape[1],img.shape[0])
if(para_max == img.shape[1]):
scale_percent = (int)(canv.winfo_width()/img.shape[1] *100)
else:
scale_percent = (int)(canv.winfo_height() / img.shape[0] * 100)
#print(scale_percent)
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
# print(dim)
# print("size:",canv.winfo_width(),canv.winfo_height())
# resize image
img_res = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
#cv2.imshow("s",img)
#cv2.waitKey()
picture = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(img_res))
window_.picture=picture
canv.create_image(0, 0, image=picture, anchor=tk.NW)
myFont = font.Font(font='arial 15')
button_start=tk.Button(frame_button,command=start,bd=2,width=50,height=2,fg='white'
,bg='#6cbaea',activebackground="green",text="START")
button_measure=tk.Button(frame_button,text="SELECT",command=select,borderwidth=2,fg
='white',width=50,height=2,bg='#61a1ea',activebackground="green")
display=tk.Entry(frame_button,bd=20,width=100,justify='center')
display['font']=myFont
button_start['font']=myFont
button_measure['font']=myFont
button_measure.pack(pady=40)
button_start.pack(pady=10)
display.pack(side=BOTTOM)
frame_camera.pack(side=RIGHT,fill=BOTH,expand=True)
frame_camera.pack_propagate(0)
frame_button.pack(side=LEFT,fill=BOTH,expand=True)
frame_camera.pack_propagate(0)
canv.grid(column=0,row=0)
canv_2.grid(column=1,row=0)
window_.mainloop()