Рет қаралды 106
import time,cv2
from paddleocr import PaddleOCR,draw_ocr
import paddle
#paddle.device.is_compiled_with_cuda()
paddle.utils.run_check()
ocr = PaddleOCR(use_gpu=True, use_angle_cls=False, rec_model="ch_PP-OCRv2_rec_infer_opt.nb",drop_score=0.8,\
warmup=False,show_log=False,use_onnx=False, lang='en') # need to run only once to download and load model into memory
#img_path = 'img_12.jpg'
#img_path = '100.jfif'
img_path = '1.png'
img_path=cv2.imread(img_path)
##height, width, channels = img_path.shape
##croppedImage = img_path[int(height/1.4):int(height), 0:width]
##cv2.imwrite('crop.jpg',croppedImage)
#quit()
while True:
start_time = time.time()
result = ocr.ocr(img_path, cls=True)
#result_clean=(result[0][0][1][0]).rstrip('".')
#print(result_clean)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line[1][0])
print("--- %s seconds --" % (time.time() - start_time)) #-- 7.761305570602417 seconds ---
#--- 0.15680623054504395 seconds --- gpu gtx 3050
cuda 11.7 cudnn 8.9.7
#developer.nvidia.com/rdp/cudn...
#docs.nvidia.com/deeplearning/...
#library issue - stackoverflow.com/questions/7...
#github.com/PaddlePaddle/Paddl...
#pypi.org/project/paddlepaddle...