test_ocr_function.py
1.22 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
# -*- coding: utf-8 -*-
# @Author : Lyu Kui
# @Email : 9428.al@gmail.com
# @Create Date : 2022-07-22 13:10:47
# @Last Modified : 2022-09-08 19:03:24
# @Description :
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
import cv2
# from turnsole.ocr_engine import angle_detector
from turnsole.ocr_engine import object_detector
import matplotlib.pyplot as plt
if __name__ == "__main__":
base_dir = '/home/lk/MyProject/BMW/数据集/文件分类/身份证'
for (rootDir, dirNames, filenames) in os.walk(base_dir):
for filename in filenames:
if not filename.endswith('.jpg'):
continue
img_path = os.path.join(rootDir, filename)
print(img_path)
image = cv2.imread(img_path)
results = object_detector.process(image)
print(results)
for item in results:
xmin = item['location']['xmin']
ymin = item['location']['ymin']
xmax = item['location']['xmax']
ymax = item['location']['ymax']
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)
plt.imshow(image[...,::-1])
plt.show()