Commit 8c35b739 by 周杭

ocrConsumer功能

1 parent 58500fcf
......@@ -3,8 +3,10 @@ import numpy as np
import base64
from io import BytesIO
import logging
import tf as tf
from keras.models import load_model
from keras.utils import image_utils
# from keras.utils import image_utils
from keras import backend as K
from PIL import ImageFile
......@@ -38,9 +40,9 @@ class ImageClassificationService(object):
"""
# 加载图像
img = image_utils.load_img(img_path, target_size=self.input_shape)
img = tf.keras.utils.load_img(img_path, target_size=self.input_shape)
# 图像预处理
x = image_utils.img_to_array(img) / 255.0 # 与训练一致
x = tf.keras.utils.img_to_array(img) / 255.0 # 与训练一致
x = np.expand_dims(x, axis=0)
# 对图像进行分类
......
......@@ -18,6 +18,12 @@ import requests
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from pyzbar.pyzbar import decode
# 获取当前文件所在目录的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 将根目录添加到 Python 解释器的搜索路径中
root_dir = os.path.join(current_dir, '..') # 假设根目录是当前目录的父目录
sys.path.append(root_dir)
from logger import log
environment = sys.argv[1] if len(sys.argv) > 1 else "default"
......@@ -415,20 +421,20 @@ def handle_process(jsonData):
except PermissionError:
log.info("权限不足,无法删除文件")
# 消费消息并进行逻辑处理
try:
for msg in consumer:
if msg is None:
continue
# 处理逻辑
handle_process(msg)
except Exception as e:
log.error("ocr consumer Exception: " + str(e))
finally:
# 关闭消费者
consumer.close()
# 关闭光标对象
cursor_dev.close()
# 关闭数据库连接
conn_dev.close()
def consume_kafka():
# 消费消息并进行逻辑处理
try:
for msg in consumer:
if msg is None:
continue
# 处理逻辑
handle_process(msg)
except Exception as e:
log.error("ocr consumer Exception: " + str(e))
finally:
# 关闭消费者
consumer.close()
# 关闭光标对象
cursor_dev.close()
# 关闭数据库连接
conn_dev.close()
......@@ -5,6 +5,7 @@ from flaskr.biz import user_service
from flaskr.biz.identify_service import IdentifyService
from flaskr.controller import image_classfication_controller, ocr_controller
import os
from kafka_consumer import ocr_consumer
app = create_app()
# 注册蓝图到应用程序中
......@@ -64,4 +65,5 @@ def upload():
if __name__ == "__main__":
ocr_consumer.consume_kafka()
app.run(host="0.0.0.0", port=5000)
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!