docstr: OCR with PaddleOCR
  args：
      img: img for OCR, support ndarray, img_path and list or ndarray
      det: use text detection or not. If False, only rec will be exec. Default is True
      rec: use text recognition or not. If False, only det will be exec. Default is True
      cls: use angle classifier or not. Default is True. If True, the text with rotation of 180 degrees can be recognized. If no text is rotated by 180 degrees, use cls=False to get better performance. Text with rotation of 90 or 270 degrees can be recognized even if cls=False.
      bin: binarize image to black and white. Default is False.
      inv: invert image colors. Default is False.
      alpha_color: set RGB color Tuple for transparent parts replacement. Default is pure white.
docstr_tok: ["OCR","with","PaddleOCR","args\uff1a","img",":","img","for","OCR",",","support","ndarray",",","img_path","and","list","or","ndarray","det",":","use","text","detection","or","not",".","If","False",",","only","rec","will","be","exec",".","Default","is","True","rec",":","use","text","recognition","or","not",".","If","False",",","only","det","will","be","exec",".","Default","is","True","cls",":","use","angle","classifier","or","not",".","Default","is","True",".","If","True",",","the","text","with","rotation","of","180","degrees","can","be","recognized",".","If","no","text","is","rotated","by","180","degrees",",","use","cls=False","to","get","better","performance",".","Text","with","rotation","of","90","or","270","degrees","can","be","recognized","even","if","cls=False",".","bin",":","binarize","image","to","black","and","white",".","Default","is","False",".","inv",":","invert","image","colors",".","Default","is","False",".","alpha_color",":","set","RGB","color","Tuple","for","transparent","parts","replacement",".","Default","is","pure","white","."]
code: def ocr(
      self,
      img,
      det=True,
      rec=True,
      cls=True,
      bin=False,
      inv=False,
      alpha_color=(255, 255, 255),
  ):
      """
      OCR with PaddleOCR
      args：
          img: img for OCR, support ndarray, img_path and list or ndarray
          det: use text detection or not. If False, only rec will be exec. Default is True
          rec: use text recognition or not. If False, only det will be exec. Default is True
          cls: use angle classifier or not. Default is True. If True, the text with rotation of 180 degrees can be recognized. If no text is rotated by 180 degrees, use cls=False to get better performance. Text with rotation of 90 or 270 degrees can be recognized even if cls=False.
          bin: binarize image to black and white. Default is False.
          inv: invert image colors. Default is False.
          alpha_color: set RGB color Tuple for transparent parts replacement. Default is pure white.
      """
      assert isinstance(img, (np.ndarray, list, str, bytes))
      if isinstance(img, list) and det == True:
          logger.error("When input a list of images, det must be false")
          exit(0)
      if cls == True and self.use_angle_cls == False:
          logger.warning(
              "Since the angle classifier is not initialized, it will not be used during the forward process"
          )
  
      img = check_img(img)
      # for infer pdf file
      if isinstance(img, list):
          if self.page_num > len(img) or self.page_num == 0:
              self.page_num = len(img)
          imgs = img[: self.page_num]
      else:
          imgs = [img]
  
      def preprocess_image(_image):
          _image = alpha_to_color(_image, alpha_color)
          if inv:
              _image = cv2.bitwise_not(_image)
          if bin:
              _image = binarize_img(_image)
          return _image
  
      if det and rec:
          ocr_res = []
          for idx, img in enumerate(imgs):
              img = preprocess_image(img)
              dt_boxes, rec_res, _ = self.__call__(img, cls)
              if not dt_boxes and not rec_res:
                  ocr_res.append(None)
                  continue
              tmp_res = [
                  [box.tolist(), res]
                  for box, res in zip(dt_boxes, rec_res)
              ]
              ocr_res.append(tmp_res)
          return ocr_res
      elif det and not rec:
          ocr_res = []
          for idx, img in enumerate(imgs):
              img = preprocess_image(img)
              dt_boxes, elapse = self.text_detector(img)
              if not dt_boxes:
                  ocr_res.append(None)
                  continue
              tmp_res = [box.tolist() for box in dt_boxes]
              ocr_res.append(tmp_res)
          return ocr_res
      else:
          ocr_res = []
          cls_res = []
          for idx, img in enumerate(imgs):
              if not isinstance(img, list):
                  img = preprocess_image(img)
                  img = [img]
              if self.use_angle_cls and cls:
                  img, cls_res_tmp, elapse = self.text_classifier(img)
                  if not rec:
                      cls_res.append(cls_res_tmp)
              rec_res, elapse = self.text_recognizer(img)
              ocr_res.append(rec_res)
          if not rec:
              return cls_res
          return ocr_res
  
imports: import os
  import sys
  import importlib
  import paddle
  import cv2
  import logging
  import numpy
  from pathlib import Path
  import base64
  from io import BytesIO
  from PIL import Image
  from ppocr.utils.logging import get_logger
  from tools.infer import predict_system
  from ppocr.utils.utility import check_and_read, get_image_file_list, alpha_to_color, binarize_img
  from ppocr.utils.network import maybe_download, download_with_progressbar, is_link, confirm_model_dir_url
  from tools.infer.utility import draw_ocr, str2bool, check_gpu
  from ppstructure.utility import init_args, draw_structure_result
  from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel
label_desc: Use image node_id 2 for calling the PaddleOCR obj's underlying member method code with example usage: obj.ocr(img, det, rec, cls, bin, inv, alpha_color) and returns: _image, ocr_res, ocr_res, ocr_res, cls_res