Commit 1a3bd9c2 by 杨林龙

优化OCR审核

1 parent e5086d61
......@@ -12,6 +12,7 @@ import pymysql
import requests
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from PIL import ImageEnhance
from pyzbar.pyzbar import decode
# 连接database
......@@ -75,7 +76,7 @@ ocr = PaddleOCR(
# 定义要执行的SQL语句
SQL = """
select * from sys_order_file_ocr sofo limit 1000
select * from sys_order_file_ocr sofo limit 500
"""
# 执行SQL语句
cursor_dev.execute(SQL)
......@@ -145,7 +146,13 @@ def extract_vin(string):
match = re.search(pattern, string)
if match:
vin = match.group()
return vin
pattern01 = r"^\d+$"
match = re.match(pattern01, vin)
# 如果全是数字 则不是车架号
if bool(match):
return None
else:
return vin
else:
return None
......@@ -188,6 +195,13 @@ for index, row in enumerate(result):
original_image = Image.open(path)
# 创建对比度增强器
# enhancer = ImageEnhance.Contrast(original_image)
# 增强对比度(将对比度增强为原来的2倍)
# factor = 2.0
# original_image = enhancer.enhance(factor)
# 放大图片
scale_factor = 3 # 放大倍数
# scaled_image = original_image.resize(
......@@ -206,7 +220,7 @@ for index, row in enumerate(result):
result_list = flatten_list(result)
print("result_list", result_list)
with open("./log09.txt", "a+", encoding="utf-8") as file:
with open("./log10.txt", "a+", encoding="utf-8") as file:
if result_list is not None:
file.write(path + "----" + str(result_list) + "\n")
else:
......@@ -226,7 +240,7 @@ for index, row in enumerate(result):
print(vin_str)
# 定义要执行的SQL语句
SQL01 = f"""
INSERT INTO sys_vin_check_ocr_06 (order_id,file_id,db_vin,ocr_vin,create_time)
INSERT INTO sys_vin_check_ocr_11 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
"""
# 执行SQL语句
......@@ -243,7 +257,7 @@ for index, row in enumerate(result):
# print(line[0][1][0])
result_list = flatten_list(result)
print("result_list", result_list)
with open("./log09.txt", "a+", encoding="utf-8") as file:
with open("./log10.txt", "a+", encoding="utf-8") as file:
if result_list is not None:
file.write(path + "----" + str(result_list) + "\n")
else:
......@@ -261,7 +275,7 @@ for index, row in enumerate(result):
print(vin_str)
# 定义要执行的SQL语句
SQL01 = f"""
INSERT INTO sys_vin_check_ocr_06 (order_id,file_id,db_vin,ocr_vin,create_time)
INSERT INTO sys_vin_check_ocr_11 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
"""
# 执行SQL语句
......@@ -277,7 +291,7 @@ for index, row in enumerate(result):
# print(line[0][1][0])
result_list = flatten_list(result)
print("result_list", result_list)
with open("./log09.txt", "a+", encoding="utf-8") as file:
with open("./log10.txt", "a+", encoding="utf-8") as file:
if result_list is not None:
file.write(path + "----" + str(result_list) + "\n")
else:
......@@ -295,7 +309,7 @@ for index, row in enumerate(result):
print(vin_str)
# 定义要执行的SQL语句
SQL01 = f"""
INSERT INTO sys_vin_check_ocr_06 (order_id,file_id,db_vin,ocr_vin,create_time)
INSERT INTO sys_vin_check_ocr_11 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
"""
# 执行SQL语句
......@@ -303,15 +317,56 @@ for index, row in enumerate(result):
cursor_dev.execute(SQL01)
conn_dev.commit()
else:
# 定义要执行的SQL语句
SQL02 = f"""
INSERT INTO sys_vin_check_ocr_06 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}',null,sysdate())
"""
# 执行SQL语句
print(SQL02)
cursor_dev.execute(SQL02)
# conn_dev.commit()
# 如果识别不了 直接再放大图片
scale_factor = 6
dst = original_image.resize(
(
original_image.width * scale_factor,
original_image.height * scale_factor,
)
)
result = ocr.ocr(np.asarray(dst), cls=True)
# result = ocr.ocr(image_path.replace("train", "validation"), cls=True)
for line in result:
print(line)
# print(line[0][1][0])
result_list = flatten_list(result)
print("result_list", result_list)
with open("./log10.txt", "a+", encoding="utf-8") as file:
if result_list is not None:
file.write(path + "----" + str(result_list) + "\n")
else:
file.write(path + "----" + "NULL" + "\n")
vin_str = ""
for item in result_list:
print(item)
vin_check = extract_vin(item)
if vin_check is not None:
vin_str = vin_check
break
if vin_str:
print(str(row))
print(vin_str)
# 定义要执行的SQL语句
SQL01 = f"""
INSERT INTO sys_vin_check_ocr_11 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
"""
# 执行SQL语句
print(SQL01)
cursor_dev.execute(SQL01)
conn_dev.commit()
else:
# 定义要执行的SQL语句
SQL02 = f"""
INSERT INTO sys_vin_check_ocr_11 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}',null,sysdate())
"""
# 执行SQL语句
print(SQL02)
cursor_dev.execute(SQL02)
conn_dev.commit()
# # 关闭光标对象
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!