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 ed774243
authored
Jan 26, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化OCR检测逻辑
1 parent
d564e868
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
1 deletions
Identify_vinandsn/main04.py
Identify_vinandsn/main06.py
Identify_vinandsn/main04.py
View file @
ed77424
...
@@ -157,6 +157,15 @@ def extract_vin(string):
...
@@ -157,6 +157,15 @@ def extract_vin(string):
return
None
return
None
def
flip_image_45
(
image
):
# 逆时针旋转45度
print
(
"逆时针旋转45度"
)
# rotated_image = cv2.transpose(image)
# rotated_image = cv2.flip(rotated_image, 0)
rotated_image
=
image
.
rotate
(
45
)
return
rotated_image
def
flip_image_90
(
image
):
def
flip_image_90
(
image
):
# 逆时针旋转90度
# 逆时针旋转90度
print
(
"逆时针旋转90度"
)
print
(
"逆时针旋转90度"
)
...
@@ -254,7 +263,41 @@ for index, row in enumerate(result):
...
@@ -254,7 +263,41 @@ for index, row in enumerate(result):
conn_dev
.
commit
()
conn_dev
.
commit
()
else
:
else
:
# 旋转90度宠重新识别
# 旋转90度宠重新识别
dst
=
flip_image_90
(
dst
)
dst
=
flip_image_45
(
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
(
"./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
:
dst
=
flip_image_45
(
dst
)
result
=
ocr
.
ocr
(
np
.
asarray
(
dst
),
cls
=
True
)
result
=
ocr
.
ocr
(
np
.
asarray
(
dst
),
cls
=
True
)
# result = ocr.ocr(image_path.replace("train", "validation"), cls=True)
# result = ocr.ocr(image_path.replace("train", "validation"), cls=True)
for
line
in
result
:
for
line
in
result
:
...
...
Identify_vinandsn/main06.py
0 → 100644
View file @
ed77424
from
modelscope.pipelines
import
pipeline
from
modelscope.utils.constant
import
Tasks
import
cv2
import
os
import
pymysql
os
.
environ
[
"CUDA_VISIBLE_DEVICES"
]
=
"1"
os
.
environ
[
"HF_DATASETS_CACHE"
]
=
"G:
\
huggingface"
os
.
environ
[
"HF_HOME"
]
=
"G:
\
huggingface"
os
.
environ
[
"HUGGINGFACE_HUB_CACHE"
]
=
"G:
\
huggingface"
os
.
environ
[
"TRANSFORMERS_CACHE"
]
=
"G:
\
huggingface"
os
.
environ
[
"MODELSCOPE_CACHE"
]
=
"G:
\
modelscope"
os
.
environ
[
"MODELSCOPE_MODULES_CACHE"
]
=
"G:
\
modelscope"
# 连接database
conn_dev
=
pymysql
.
connect
(
host
=
"192.168.3.227"
,
port
=
3306
,
user
=
"dev_user"
,
password
=
"df234fl"
,
database
=
"glsx_car_service"
,
charset
=
"utf8"
,
)
# 得到一个可以执行SQL语句的光标对象
cursor_dev
=
conn_dev
.
cursor
()
# 定义要执行的SQL语句
SQL
=
"""
select * from sys_order_file_ocr sofo limit 1000
"""
# 执行SQL语句
cursor_dev
.
execute
(
SQL
)
# 获取查询结果
result
=
cursor_dev
.
fetchall
()
# ocr_recognition = pipeline(
# Tasks.ocr_recognition, model="damo/cv_crnn_ocr-recognition-general_damo"
# )
# ocr_detection = pipeline(
# Tasks.ocr_detection, model="damo/cv_resnet18_ocr-detection-db-line-level_damo"
# )
ocr_recognition
=
pipeline
(
Tasks
.
ocr_recognition
,
model
=
'damo/cv_convnextTiny_ocr-recognition-general_damo'
)
# 下载图片数据
for
index
,
row
in
enumerate
(
result
):
print
(
row
)
### 使用url
# img_url = "http://duguang-labelling.oss-cn-shanghai.aliyuncs.com/mass_img_tmp_20220922/ocr_recognition.jpg"
img_url
=
row
[
4
]
result
=
ocr_recognition
(
img_url
)
print
(
result
)
### 使用图像文件
### 请准备好名为'ocr_recognition.jpg'的图像文件
# img_path = 'ocr_recognition.jpg'
# img = cv2.imread(img_path)
# result = ocr_recognition(img)
# print(result)
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