from . import pipline2 as pp
import cv2
#import sys
import mysql.connector
import time


host = '127.0.0.1'
user = 'root'
password = 'root'
db = 'school'

# 写入本地文件
#file = open("D:\message.txt", "w")
#str = "".join(res)
#file.write(str)
#file.write('\n')
#file.close()


#图片的起始和结束
img_start = 1
img_end = 101


t0 = time.time()

for num in range(img_start, img_end):
    conn = mysql.connector.connect(user=user, password=password, database=db, host=host)
    plate_number = ""
    now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    # 自行修改文件名
    image = cv2.imread("in/" + str(num) + ".jpg")
    #image, res = pp.SimpleRecognizePlate(image)
    res, resultEnd = pp.SimpleRecognizePlate(image)
    #sre_plate = ''.join(res)
    new_plate = ''.join(resultEnd)
    #plate_number = sre_plate if(sre_plate.strip() != "") else ""
    new_plate = new_plate if(new_plate.strip() != "") else ""
    #print(plate_number)
    print(new_plate)
    print(now_time)
    cursor = conn.cursor()
    cursor.execute("insert into inner_school (plate_number,in_date) values(%s,%s)", [new_plate, now_time])
    conn.commit()
    cursor.close()
    conn.close()


print("total time:")
print(time.time() - t0)

