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 e5086d61
authored
Jan 23, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化OCR识别
1 parent
d260b457
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
6 deletions
Identify_vinandsn/main04.py
Identify_vinandsn/main04.py
View file @
e5086d6
...
@@ -138,8 +138,10 @@ def validate_vin(item):
...
@@ -138,8 +138,10 @@ def validate_vin(item):
def
extract_vin
(
string
):
def
extract_vin
(
string
):
string
=
re
.
sub
(
r"O"
,
"0"
,
string
)
string
=
re
.
sub
(
r"O"
,
"0"
,
string
)
string
=
re
.
sub
(
r"I"
,
"1"
,
string
)
string
=
re
.
sub
(
r"I"
,
"1"
,
string
)
# pattern = r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z]{17})"
pattern
=
r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z]{17})"
pattern
=
r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z\s\u4e00-\u9fa5]{17})"
# pattern = r"(?=.*[0-9A-HJ-NPR-Z])(?!(.*[IOQ]))([0-9A-HJ-NPR-Z\s\u4e00-\u9fa5]{17})"
# pattern = r"[0-9A-HJ-NPR-Z]{17}"
# pattern = r"^[A-HJ-NPR-Z\d]{17}$"
match
=
re
.
search
(
pattern
,
string
)
match
=
re
.
search
(
pattern
,
string
)
if
match
:
if
match
:
vin
=
match
.
group
()
vin
=
match
.
group
()
...
@@ -148,6 +150,21 @@ def extract_vin(string):
...
@@ -148,6 +150,21 @@ def extract_vin(string):
return
None
return
None
def
flip_image_90
(
image
):
# 逆时针旋转90度
print
(
"逆时针旋转90度"
)
# rotated_image = cv2.transpose(image)
# rotated_image = cv2.flip(rotated_image, 0)
rotated_image
=
image
.
rotate
(
90
)
return
rotated_image
def
flip_image_180
(
image
):
# 旋转180度
rotated_image
=
cv2
.
flip
(
image
,
-
1
)
return
rotated_image
# 下载图片数据
# 下载图片数据
for
index
,
row
in
enumerate
(
result
):
for
index
,
row
in
enumerate
(
result
):
print
(
row
)
print
(
row
)
...
@@ -189,7 +206,7 @@ for index, row in enumerate(result):
...
@@ -189,7 +206,7 @@ for index, row in enumerate(result):
result_list
=
flatten_list
(
result
)
result_list
=
flatten_list
(
result
)
print
(
"result_list"
,
result_list
)
print
(
"result_list"
,
result_list
)
with
open
(
"./log0
7
.txt"
,
"a+"
,
encoding
=
"utf-8"
)
as
file
:
with
open
(
"./log0
9
.txt"
,
"a+"
,
encoding
=
"utf-8"
)
as
file
:
if
result_list
is
not
None
:
if
result_list
is
not
None
:
file
.
write
(
path
+
"----"
+
str
(
result_list
)
+
"
\n
"
)
file
.
write
(
path
+
"----"
+
str
(
result_list
)
+
"
\n
"
)
else
:
else
:
...
@@ -209,7 +226,76 @@ for index, row in enumerate(result):
...
@@ -209,7 +226,76 @@ for index, row in enumerate(result):
print
(
vin_str
)
print
(
vin_str
)
# 定义要执行的SQL语句
# 定义要执行的SQL语句
SQL01
=
f
"""
SQL01
=
f
"""
INSERT INTO sys_vin_check_ocr_02 (order_id,file_id,db_vin,ocr_vin,create_time)
INSERT INTO sys_vin_check_ocr_06 (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
:
# 旋转90度宠重新识别
dst
=
flip_image_90
(
dst
)
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
(
"./log09.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_06 (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
:
dst
=
flip_image_90
(
dst
)
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
(
"./log09.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_06 (order_id,file_id,db_vin,ocr_vin,create_time)
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
VALUES ({row[1]},{row[0]},'{row[9]}','{vin_str}',sysdate())
"""
"""
# 执行SQL语句
# 执行SQL语句
...
@@ -219,13 +305,13 @@ for index, row in enumerate(result):
...
@@ -219,13 +305,13 @@ for index, row in enumerate(result):
else
:
else
:
# 定义要执行的SQL语句
# 定义要执行的SQL语句
SQL02
=
f
"""
SQL02
=
f
"""
INSERT INTO sys_vin_check_ocr_02
(order_id,file_id,db_vin,ocr_vin,create_time)
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())
VALUES ({row[1]},{row[0]},'{row[9]}',null,sysdate())
"""
"""
# 执行SQL语句
# 执行SQL语句
print
(
SQL02
)
print
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
conn_dev
.
commit
()
#
conn_dev.commit()
# # 关闭光标对象
# # 关闭光标对象
...
...
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