Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
my_flask_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8c35b739
authored
Feb 28, 2024
by
周杭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ocrConsumer功能
1 parent
58500fcf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
20 deletions
flaskr/biz/image_classification_service.py
kafka_consumer/orc_consumer.py → kafka_consumer/ocr_consumer.py
manage.py
requirements.txt
flaskr/biz/image_classification_service.py
View file @
8c35b73
...
@@ -3,8 +3,10 @@ import numpy as np
...
@@ -3,8 +3,10 @@ import numpy as np
import
base64
import
base64
from
io
import
BytesIO
from
io
import
BytesIO
import
logging
import
logging
import
tf
as
tf
from
keras.models
import
load_model
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
keras
import
backend
as
K
from
PIL
import
ImageFile
from
PIL
import
ImageFile
...
@@ -38,9 +40,9 @@ class ImageClassificationService(object):
...
@@ -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
)
x
=
np
.
expand_dims
(
x
,
axis
=
0
)
# 对图像进行分类
# 对图像进行分类
...
...
kafka_consumer/o
rc
_consumer.py
→
kafka_consumer/o
cr
_consumer.py
View file @
8c35b73
...
@@ -18,6 +18,12 @@ import requests
...
@@ -18,6 +18,12 @@ import requests
from
paddleocr
import
PaddleOCR
,
draw_ocr
from
paddleocr
import
PaddleOCR
,
draw_ocr
from
PIL
import
Image
from
PIL
import
Image
from
pyzbar.pyzbar
import
decode
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
from
logger
import
log
environment
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"default"
environment
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
"default"
...
@@ -415,20 +421,20 @@ def handle_process(jsonData):
...
@@ -415,20 +421,20 @@ def handle_process(jsonData):
except
PermissionError
:
except
PermissionError
:
log
.
info
(
"权限不足,无法删除文件"
)
log
.
info
(
"权限不足,无法删除文件"
)
def
consume_kafka
():
# 消费消息并进行逻辑处理
# 消费消息并进行逻辑处理
try
:
try
:
for
msg
in
consumer
:
for
msg
in
consumer
:
if
msg
is
None
:
if
msg
is
None
:
continue
continue
# 处理逻辑
# 处理逻辑
handle_process
(
msg
)
handle_process
(
msg
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
"ocr consumer Exception: "
+
str
(
e
))
log
.
error
(
"ocr consumer Exception: "
+
str
(
e
))
finally
:
finally
:
# 关闭消费者
# 关闭消费者
consumer
.
close
()
consumer
.
close
()
# 关闭光标对象
# 关闭光标对象
cursor_dev
.
close
()
cursor_dev
.
close
()
# 关闭数据库连接
# 关闭数据库连接
conn_dev
.
close
()
conn_dev
.
close
()
manage.py
View file @
8c35b73
...
@@ -5,6 +5,7 @@ from flaskr.biz import user_service
...
@@ -5,6 +5,7 @@ from flaskr.biz import user_service
from
flaskr.biz.identify_service
import
IdentifyService
from
flaskr.biz.identify_service
import
IdentifyService
from
flaskr.controller
import
image_classfication_controller
,
ocr_controller
from
flaskr.controller
import
image_classfication_controller
,
ocr_controller
import
os
import
os
from
kafka_consumer
import
ocr_consumer
app
=
create_app
()
app
=
create_app
()
# 注册蓝图到应用程序中
# 注册蓝图到应用程序中
...
@@ -64,4 +65,5 @@ def upload():
...
@@ -64,4 +65,5 @@ def upload():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
ocr_consumer
.
consume_kafka
()
app
.
run
(
host
=
"0.0.0.0"
,
port
=
5000
)
app
.
run
(
host
=
"0.0.0.0"
,
port
=
5000
)
requirements.txt
View file @
8c35b73
No preview for this file type
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment