import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
from os.path import join
from paddleocr import PaddleOCR, draw_ocr
import os
from PIL import Image
path = r"D:\BUFFER\Pycharm\RecognitionOCR\images\OCR"
determination = "RecognitionOCR/images/rudeOCR"
ocr = PaddleOCR(use_angle_cls=True, lang="en") # need to run only once to download and load model into memory
for filename in os.listdir(path): # listdir的参数是文件夹的路径
filenames = path + '\\' + filename
img_orig = cv2.imread(filenames, 1)
# print(filenames)
image_RGB = cv2.cvtColor(img_orig, cv2.COLOR_BGR2RGB)
ROI = image_RGB[800:950, 1160:1400]
img = ROI.copy()
# cv2.imshow("roi", img)
# cv2.waitKey()
result = ocr.ocr(img, cls=True)
# 显示结果
# for line in result:
# print(line)
# image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
print(txts)
scores = [line[1][1] for line in result]
im_show = draw_ocr(img, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
plt.imshow(im_show)
plt.show()
# cv2.imwrite('images/rudeOCR/' + filename,img)
# cv2.imwrite('images/rcnnROI/' + fileName, ROI)