Skip to content

Commit d28cb46

Browse files
authored
skip unnecessary method calls (#14900)
* skip unnecessary method calls in PaddleOCR.ocr pre-check meaningless args for PaddleOCR.ocr * style: make CI happy
1 parent 17525c5 commit d28cb46

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

paddleocr.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ def ocr(
732732
- For PDF files, if the input is a list of images and the page_num is specified, only the first page_num images will be processed.
733733
- The preprocess_image function is used to preprocess the input image by applying alpha color replacement, inversion, and binarization if specified.
734734
"""
735+
assert (
736+
det or rec or cls
737+
), "det and rec and cls can not be False at the same time"
735738
assert isinstance(img, (np.ndarray, list, str, bytes))
736739
if isinstance(img, list) and det == True:
737740
logger.error("When input a list of images, det must be false")
@@ -781,7 +784,7 @@ def preprocess_image(_image):
781784
tmp_res = [box.tolist() for box in dt_boxes]
782785
ocr_res.append(tmp_res)
783786
return ocr_res
784-
else:
787+
elif rec or cls:
785788
ocr_res = []
786789
cls_res = []
787790
for img in imgs:
@@ -792,11 +795,15 @@ def preprocess_image(_image):
792795
img, cls_res_tmp, elapse = self.text_classifier(img)
793796
if not rec:
794797
cls_res.append(cls_res_tmp)
798+
continue
795799
rec_res, elapse = self.text_recognizer(img)
796800
ocr_res.append(rec_res)
797801
if not rec:
798802
return cls_res
799803
return ocr_res
804+
else:
805+
logger.error("det and rec and cls can not be False at the same time")
806+
exit(0)
800807

801808

802809
class PPStructure(StructureSystem):

0 commit comments

Comments
 (0)