Skip to content

πŸ“„ Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Remove duplicate code

SWHLd2d0333a1623
diff --git a/ocrweb/task.py b/ocrweb/task.py
index be0bf5e..dbc716d 100644
--- a/ocrweb/task.py
+++ b/ocrweb/task.py
@@ -5,7 +5,6 @@ import base64
import copy
import json
from functools import reduce
-from pathlib import Path
import cv2
import numpy as np
@@ -56,27 +55,11 @@ def img_to_base64(img):
return img_str
-def check_and_read_gif(img_path):
- if Path(img_path).name[-3:] in ['gif', 'GIF']:
- gif = cv2.VideoCapture(img_path)
- ret, frame = gif.read()
- if not ret:
- print("Cannot read {}. This gif image maybe corrupted.")
- return None, False
- if len(frame.shape) == 2 or frame.shape[-1] == 1:
- frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
- imgvalue = frame[:, :, ::-1]
- return imgvalue, True
- return None, False
-
-
def draw_text_det_res(dt_boxes, raw_im):
src_im = copy.deepcopy(raw_im)
for i, box in enumerate(dt_boxes):
box = np.array(box).astype(np.int32).reshape(-1, 2)
- cv2.polylines(src_im, [box], True,
- color=(0, 0, 255),
- thickness=1)
+ cv2.polylines(src_im, [box], True, color=(0, 0, 255), thickness=1)
cv2.putText(src_im, str(i), (int(box[0][0]), int(box[0][1])),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 2)
return src_im
diff --git a/ocrweb_multi/rapidocr/main.py b/ocrweb_multi/rapidocr/main.py
index 01d3069..d88f8e7 100644
--- a/ocrweb_multi/rapidocr/main.py
+++ b/ocrweb_multi/rapidocr/main.py
@@ -27,7 +27,7 @@ def detect_recognize(image, lang='ch', detect=True, classify=True):
def check_and_read_gif(img_path):
- if Path(img_path).name[-3:] in ['gif', 'GIF']:
+ if Path(img_path).suffix.lower() == 'gif':
gif = cv2.VideoCapture(img_path)
ret, frame = gif.read()
if not ret: