Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6934c592
authored
2020-11-12 20:09:49 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix bug
1 parent
b34cd942
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
src/apps/doc/management/commands/folder_ocr_process.py
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/management/commands/folder_ocr_process.py
View file @
6934c59
...
...
@@ -6,6 +6,7 @@ import base64
import
signal
import
requests
import
traceback
from
datetime
import
datetime
from
django.core.management
import
BaseCommand
from
multiprocessing
import
Process
...
...
@@ -57,7 +58,7 @@ class Command(BaseCommand, LoggerMixin):
@staticmethod
def
get_path
(
name
,
img_output_dir
,
wb_output_dir
,
pdf_output_dir
):
time_stamp
=
int
(
time
.
time
()
)
time_stamp
=
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d_
%
H:
%
M:
%
S'
)
new_name
=
'{0}_{1}'
.
format
(
time_stamp
,
name
)
img_save_path
=
os
.
path
.
join
(
img_output_dir
,
new_name
)
pdf_save_path
=
os
.
path
.
join
(
pdf_output_dir
,
new_name
)
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
6934c59
...
...
@@ -365,13 +365,17 @@ class Command(BaseCommand, LoggerMixin):
def
pdf_2_img_2_queue
(
self
,
img_queue
,
todo_count_dict
,
lock
):
while
self
.
switch
:
try
:
# 1. 从队列获取文件信息
doc
,
business_type
,
task_str
=
self
.
get_doc_info
()
# 队列为空时的处理
if
doc
is
None
:
time
.
sleep
(
self
.
sleep_time_doc_get
)
continue
except
Exception
as
e
:
self
.
cronjob_log
.
error
(
'{0} [process failed (get doc into)] [error={1}]'
.
format
(
self
.
log_base
,
traceback
.
format_exc
()))
else
:
try
:
# 2. 从EDMS获取PDF文件
doc_data_path
=
os
.
path
.
join
(
self
.
data_dir
,
business_type
,
consts
.
TMP_DIR_NAME
,
str
(
doc
.
id
))
...
...
@@ -418,6 +422,9 @@ class Command(BaseCommand, LoggerMixin):
continue
else
:
self
.
cronjob_log
.
info
(
'{0} [img_2_ocr_1] [get img] [img_path={1}]'
.
format
(
self
.
log_base
,
img_path
))
for
times
in
range
(
consts
.
RETRY_TIMES
):
try
:
with
open
(
img_path
,
'rb'
)
as
f
:
base64_data
=
base64
.
b64encode
(
f
.
read
())
# 获取解码后的base64值
...
...
@@ -426,8 +433,6 @@ class Command(BaseCommand, LoggerMixin):
"file"
:
file_data
}
for
times
in
range
(
consts
.
RETRY_TIMES
):
try
:
start_time
=
time
.
time
()
ocr_1_response
=
requests
.
post
(
url
,
json
=
json_data_1
)
if
ocr_1_response
.
status_code
!=
200
:
...
...
@@ -447,6 +452,7 @@ class Command(BaseCommand, LoggerMixin):
self
.
cronjob_log
.
warn
(
'{0} [ocr_1 failed] [img_path={1}]'
.
format
(
self
.
log_base
,
img_path
))
# continue
try
:
del
json_data_1
# /data/bmw-ocr-data/AFC/tmp/6/img/page_0_img_0.jpeg
# AFC_2
...
...
@@ -463,6 +469,9 @@ class Command(BaseCommand, LoggerMixin):
del
todo_count_dict
[
task_str
]
else
:
todo_count_dict
[
task_str
]
=
todo_count
-
1
except
Exception
as
e
:
self
.
cronjob_log
.
error
(
'{0} [process failed (store ocr res)] [img_path={1}] [error={2}]'
.
format
(
self
.
log_base
,
img_path
,
traceback
.
format_exc
()))
def
res_2_wb
(
self
,
res_dict
,
finish_queue
,
lock
):
while
True
:
...
...
Write
Preview
Styling with
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