class_docstr: Prepare document data for Document Classification.
  OCR (Optical character recognition) is applied to get the document texts and bounding boxes.
  Both texts and images will be processed.
class_docstr_tok: ["Prepare","document","data","for","Document","Classification",".","OCR","(","Optical","character","recognition",")","is","applied","to","get","the","document","texts","and","bounding","boxes",".","Both","texts","and","images","will","be","processed","."]
docstr: Apply OCR on document images to ecognize and “read” the text embedded in document images.
  Specifically, Python-tesseract, a wrapper for Google's Tesseract-OCR Engine, will be used.
  
  Parameters
  ----------
  doc_image
      The document image.
  
  Returns
  -------
  A dictionary with recognized text and corresponding bounding boxes.
docstr_tok: ["Apply","OCR","on","document","images","to","ecognize","and","\u201c","read","\u201d","the","text","embedded","in","document","images",".","Specifically",",","Python-tesseract",",","a","wrapper","for","Google","'s","Tesseract-OCR","Engine",",","will","be","used",".","Parameters","--","--","--","--","--","doc_image","The","document","image",".","Returns","--","--","--","-","A","dictionary","with","recognized","text","and","corresponding","bounding","boxes","."]
code: def apply_ocr(self, doc_image):
      """
      Apply OCR on document images to ecognize and “read” the text embedded in document images.
      Specifically, Python-tesseract, a wrapper for Google's Tesseract-OCR Engine, will be used.
  
      Parameters
      ----------
      doc_image
          The document image.
  
      Returns
      -------
      A dictionary with recognized text and corresponding bounding boxes.
      """
      results = {}
      width, height = doc_image.size
      # apply ocr to the document image.
      ocr_df = pytesseract.image_to_data(
          doc_image, output_type="data.frame"
      )
      float_cols = ocr_df.select_dtypes("float").columns
      ocr_df = ocr_df.dropna().reset_index(drop=True)
      ocr_df[float_cols] = ocr_df[float_cols].round(0).astype(int)
      ocr_df = ocr_df.replace(r"^\s*$", np.nan, regex=True)
      ocr_df = ocr_df.dropna().reset_index(drop=True)
  
      # get the words and actual (unnormalized) bounding boxes.
      words = list(ocr_df.text)
      words = [str(w) for w in words]
      coordinates = ocr_df[["left", "top", "width", "height"]]
      actual_boxes = []
      for idx, row in coordinates.iterrows():
          # the row comes in (left, top, width, height) format.
          x, y, w, h = tuple(row)
          # we turn it into (left, top, left+width, top+height) to get the actual box.
          actual_box = [x, y, x + w, y + h]
          actual_boxes.append(actual_box)
  
      # normalize the bounding boxes.
      boxes = []
      for box in actual_boxes:
          boxes.append(self.normalize_box(box, width, height))
  
      assert len(words) == len(boxes)
  
      results["words"] = words
      results[BBOX] = boxes
      return results
  
imports: import logging
  import os
  import warnings
  from io import BytesIO
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import PIL
  import pytesseract
  import torch
  from nptyping import NDArray
  from PIL import ImageFile
  from torch import nn
  from torchvision import transforms
  from ..constants import AUTOMM, BBOX, DOCUMENT_PDF
  from .collator import PadCollator, StackCollator
  from .utils import construct_image_processor, image_mean_std
label_desc: Use image node_id 4 for calling the DocumentProcessor obj's underlying member method code with example usage: obj.apply_ocr(doc_image) and returns: results