class_docstr: The MMOCR Text Detection Local Visualizer.
  
  Args:
      name (str): Name of the instance. Defaults to 'visualizer'.
      image (np.ndarray, optional): the origin image to draw. The format
          should be RGB. Defaults to None.
      vis_backends (list, optional): Visual backend config list.
          Default to None.
      save_dir (str, optional): Save file dir for all storage backends.
          If it is None, the backend storage will not save any data.
      fig_save_cfg (dict): Keyword parameters of figure for saving.
          Defaults to empty dict.
      fig_show_cfg (dict): Keyword parameters of figure for showing.
          Defaults to empty dict.
      is_openset (bool, optional): Whether the visualizer is used in
          OpenSet. Defaults to False.
class_docstr_tok: ["The","MMOCR","Text","Detection","Local","Visualizer",".","Args",":","name","(","str",")",":","Name","of","the","instance",".","Defaults","to","'visualizer","'",".","image","(","np.ndarray",",","optional",")",":","the","origin","image","to","draw",".","The","format","should","be","RGB",".","Defaults","to","None",".","vis_backends","(","list",",","optional",")",":","Visual","backend","config","list",".","Default","to","None",".","save_dir","(","str",",","optional",")",":","Save","file","dir","for","all","storage","backends",".","If","it","is","None",",","the","backend","storage","will","not","save","any","data",".","fig_save_cfg","(","dict",")",":","Keyword","parameters","of","figure","for","saving",".","Defaults","to","empty","dict",".","fig_show_cfg","(","dict",")",":","Keyword","parameters","of","figure","for","showing",".","Defaults","to","empty","dict",".","is_openset","(","bool",",","optional",")",":","Whether","the","visualizer","is","used","in","OpenSet",".","Defaults","to","False","."]
docstr: Draw datasample and save to all backends.
  
  - If GT and prediction are plotted at the same time, they are
  displayed in a stitched image where the left image is the
  ground truth and the right image is the prediction.
  - If ``show`` is True, all storage backends are ignored, and
  the images will be displayed in a local window.
  - If ``out_file`` is specified, the drawn image will be
  saved to ``out_file``. This is usually used when the display
  is not available.
  
  Args:
      name (str): The image identifier.
      image (np.ndarray): The image to draw.
      data_sample (:obj:`KIEDataSample`, optional):
          KIEDataSample which contains gt and prediction. Defaults
              to None.
      draw_gt (bool): Whether to draw GT KIEDataSample.
          Defaults to True.
      draw_pred (bool): Whether to draw Predicted KIEDataSample.
          Defaults to True.
      show (bool): Whether to display the drawn image. Default to False.
      wait_time (float): The interval of show (s). Defaults to 0.
      pred_score_thr (float): The threshold to visualize the bboxes
          and masks. Defaults to 0.3.
      out_file (str): Path to output file. Defaults to None.
      step (int): Global step value to record. Defaults to 0.
docstr_tok: ["Draw","datasample","and","save","to","all","backends",".","-","If","GT","and","prediction","are","plotted","at","the","same","time",",","they","are","displayed","in","a","stitched","image","where","the","left","image","is","the","ground","truth","and","the","right","image","is","the","prediction",".","-","If","``","show","``","is","True",",","all","storage","backends","are","ignored",",","and","the","images","will","be","displayed","in","a","local","window",".","-","If","``","out_file","``","is","specified",",","the","drawn","image","will","be","saved","to","``","out_file","``",".","This","is","usually","used","when","the","display","is","not","available",".","Args",":","name","(","str",")",":","The","image","identifier",".","image","(","np.ndarray",")",":","The","image","to","draw",".","data_sample","(",":","obj",":","`","KIEDataSample","`",",","optional",")",":","KIEDataSample","which","contains","gt","and","prediction",".","Defaults","to","None",".","draw_gt","(","bool",")",":","Whether","to","draw","GT","KIEDataSample",".","Defaults","to","True",".","draw_pred","(","bool",")",":","Whether","to","draw","Predicted","KIEDataSample",".","Defaults","to","True",".","show","(","bool",")",":","Whether","to","display","the","drawn","image",".","Default","to","False",".","wait_time","(","float",")",":","The","interval","of","show","(","s",")",".","Defaults","to","0.","pred_score_thr","(","float",")",":","The","threshold","to","visualize","the","bboxes","and","masks",".","Defaults","to","0.3.","out_file","(","str",")",":","Path","to","output","file",".","Defaults","to","None",".","step","(","int",")",":","Global","step","value","to","record",".","Defaults","to","0","."]
code: def add_datasample(
      self,
      name: str,
      image: np.ndarray,
      data_sample: Optional["KIEDataSample"] = None,
      draw_gt: bool = True,
      draw_pred: bool = True,
      show: bool = False,
      wait_time: int = 0,
      pred_score_thr: float = None,
      out_file: Optional[str] = None,
      step: int = 0,
  ) -> None:
      """Draw datasample and save to all backends.
  
      - If GT and prediction are plotted at the same time, they are
      displayed in a stitched image where the left image is the
      ground truth and the right image is the prediction.
      - If ``show`` is True, all storage backends are ignored, and
      the images will be displayed in a local window.
      - If ``out_file`` is specified, the drawn image will be
      saved to ``out_file``. This is usually used when the display
      is not available.
  
      Args:
          name (str): The image identifier.
          image (np.ndarray): The image to draw.
          data_sample (:obj:`KIEDataSample`, optional):
              KIEDataSample which contains gt and prediction. Defaults
                  to None.
          draw_gt (bool): Whether to draw GT KIEDataSample.
              Defaults to True.
          draw_pred (bool): Whether to draw Predicted KIEDataSample.
              Defaults to True.
          show (bool): Whether to display the drawn image. Default to False.
          wait_time (float): The interval of show (s). Defaults to 0.
          pred_score_thr (float): The threshold to visualize the bboxes
              and masks. Defaults to 0.3.
          out_file (str): Path to output file. Defaults to None.
          step (int): Global step value to record. Defaults to 0.
      """
      cat_images = list()
  
      if draw_gt:
          gt_bboxes = data_sample.gt_instances.bboxes
          gt_labels = data_sample.gt_instances.labels
          gt_texts = data_sample.gt_instances.texts
          gt_polygons = data_sample.gt_instances.get("polygons", None)
          gt_edge_labels = data_sample.gt_instances.get(
              "edge_labels", None
          )
          gt_img_data = self._draw_instances(
              image,
              gt_labels,
              gt_bboxes,
              gt_polygons,
              gt_edge_labels,
              gt_texts,
              self.dataset_meta["category"],
              self.is_openset,
              "g",
          )
          cat_images.append(gt_img_data)
      if draw_pred:
          gt_bboxes = data_sample.gt_instances.bboxes
          pred_labels = data_sample.pred_instances.labels
          gt_texts = data_sample.gt_instances.texts
          gt_polygons = data_sample.gt_instances.get("polygons", None)
          pred_edge_labels = data_sample.pred_instances.get(
              "edge_labels", None
          )
          pred_img_data = self._draw_instances(
              image,
              pred_labels,
              gt_bboxes,
              gt_polygons,
              pred_edge_labels,
              gt_texts,
              self.dataset_meta["category"],
              self.is_openset,
              "r",
          )
          cat_images.append(pred_img_data)
  
      cat_images = self._cat_image(cat_images, axis=0)
      if cat_images is None:
          cat_images = image
  
      if show:
          self.show(cat_images, win_name=name, wait_time=wait_time)
      else:
          self.add_image(name, cat_images, step)
  
      if out_file is not None:
          mmcv.imwrite(cat_images[..., ::-1], out_file)
  
      self.set_image(cat_images)
      return self.get_image()
  
file_path: mmocr/mmocr/visualization/kie_visualizer.py
imports: import warnings
  from typing import Dict, List, Optional, Sequence, Union
  import mmcv
  import numpy
  import torch
  from matplotlib.collections import PatchCollection
  from matplotlib.patches import FancyArrow
  from mmengine.visualization import Visualizer
  from mmengine.visualization.utils import check_type, check_type_and_length, color_val_matplotlib, tensor2ndarray, value2list
  from mmocr.registry import VISUALIZERS
  from mmocr.structures import KIEDataSample
  from .base_visualizer import BaseLocalVisualizer
label_desc: Use image node_id 4 for calling the KIELocalVisualizer obj's underlying member method code with example usage: obj.add_datasample(name, image, data_sample, draw_gt, draw_pred, show, wait_time, pred_score_thr, out_file, step) and returns: self