Download detect_with_paddle.py from senel/test: direct link, hf CLI and curl.
- Browser
- Download file 703 Bytes
-
https://huggingface.co/spaces/senel/test/resolve/main/detect_with_paddle.py
- Command line
-
hf download hf://spaces/senel/test/detect_with_paddle.py
-
curl -L -o detect_with_paddle.py https://huggingface.co/spaces/senel/test/resolve/main/detect_with_paddle.py
703 Bytes
| from paddleocr import PaddleOCR | |
| import cv2 | |
| import os | |
| current_directory = os.getcwd() | |
| model = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=True, det_model_dir=f"{current_directory}/.paddleocr/whl/det/en/en_PP-OCRv3_det_infer", rec_model_dir=f"{current_directory}/.paddleocr/whl/rec/en/en_PP-OCRv4_rec_infer", cls_model_dir=f"{current_directory}/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer") | |
| # Run OCR on the image | |
| def detect_paddle_OCR(image): | |
| result = model.ocr(image, cls=True) | |
| text_list= [] | |
| for idx in range(len(result)): | |
| res = result[idx] | |
| for line in res: | |
| line_text = line[1][0] | |
| text_list.append(line_text) | |
| return text_list |