main06.py
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)