docstr: Translate boolean tensor to fine polygon indicating text bounding boxes
  
  Parameters
  ----------
  hmap : torch.tensor
      Probability heatmap tensor.
  segmentation : torch.tensor
      Segmentataion tensor.
  dest_width : TYPE
      target width of the output.
  dest_height : TYPE
      target width of the output.
  bbox_min_score : float, optional
      Minimum score for each detected bounding box to be considered as a
      valid text bounding box. The default is 0.2.
  bbox_min_size : int, optional
      Minimum size for each detected bounding box to be considered as a
      valid text bounding box. The default is 3.
  max_candidates : int, optional
      Maximum number of detected bounding boxes to be considered as 
      candidates for valid text bounding box. Setting it to 0 implies
      no maximum. The default is 0.
  
  Returns
  -------
  boxes_batch : list of lists
      Polygon bounding boxes of each text box.
  scores_batch : list of floats
      Confidence scores of each text box.
docstr_tok: ["Translate","boolean","tensor","to","fine","polygon","indicating","text","bounding","boxes","Parameters","--","--","--","--","--","hmap",":","torch.tensor","Probability","heatmap","tensor",".","segmentation",":","torch.tensor","Segmentataion","tensor",".","dest_width",":","TYPE","target","width","of","the","output",".","dest_height",":","TYPE","target","width","of","the","output",".","bbox_min_score",":","float",",","optional","Minimum","score","for","each","detected","bounding","box","to","be","considered","as","a","valid","text","bounding","box",".","The","default","is","0.2.","bbox_min_size",":","int",",","optional","Minimum","size","for","each","detected","bounding","box","to","be","considered","as","a","valid","text","bounding","box",".","The","default","is","3.","max_candidates",":","int",",","optional","Maximum","number","of","detected","bounding","boxes","to","be","considered","as","candidates","for","valid","text","bounding","box",".","Setting","it","to","0","implies","no","maximum",".","The","default","is","0",".","Returns","--","--","--","-","boxes_batch",":","list","of","lists","Polygon","bounding","boxes","of","each","text","box",".","scores_batch",":","list","of","floats","Confidence","scores","of","each","text","box","."]
code: def boxes_from_bitmap(
      self,
      hmap,
      segmentation,
      dest_width,
      dest_height,
      bbox_min_score=0.2,
      bbox_min_size=3,
      max_candidates=0,
  ):
      """
      Translate boolean tensor to fine polygon indicating text bounding boxes
  
      Parameters
      ----------
      hmap : torch.tensor
          Probability heatmap tensor.
      segmentation : torch.tensor
          Segmentataion tensor.
      dest_width : TYPE
          target width of the output.
      dest_height : TYPE
          target width of the output.
      bbox_min_score : float, optional
          Minimum score for each detected bounding box to be considered as a
          valid text bounding box. The default is 0.2.
      bbox_min_size : int, optional
          Minimum size for each detected bounding box to be considered as a
          valid text bounding box. The default is 3.
      max_candidates : int, optional
          Maximum number of detected bounding boxes to be considered as
          candidates for valid text bounding box. Setting it to 0 implies
          no maximum. The default is 0.
  
      Returns
      -------
      boxes_batch : list of lists
          Polygon bounding boxes of each text box.
      scores_batch : list of floats
          Confidence scores of each text box.
      """
      assert segmentation.size(0) == 1
      bitmap = segmentation.cpu().numpy()[0]  # The first channel
      hmap = hmap.cpu().detach().numpy()[0]
      height, width = bitmap.shape
      contours, _ = cv2.findContours(
          (bitmap * 255).astype(np.uint8),
          cv2.RETR_LIST,
          cv2.CHAIN_APPROX_SIMPLE,
      )
      if max_candidates > 0:
          num_contours = min(len(contours), max_candidates)
      else:
          num_contours = len(contours)
  
      boxes = np.zeros((num_contours, 4, 2), dtype=np.int16)
      scores = np.zeros((num_contours,), dtype=np.float32)
  
      for index in range(num_contours):
          contour = contours[index]
          points, sside = self.get_mini_boxes(contour)
          if sside < bbox_min_size:
              continue
  
          points = np.array(points)
          score = self.box_score_fast(hmap, points.reshape(-1, 2))
          if score < bbox_min_score:
              continue
  
          box = self.unclip(points).reshape(-1, 1, 2)
          box, sside = self.get_mini_boxes(box)
          if sside < bbox_min_size + 2:
              continue
  
          box = np.array(box)
          if not isinstance(dest_width, int):
              dest_width = dest_width.item()
              dest_height = dest_height.item()
  
          box[:, 0] = np.clip(
              np.round(box[:, 0] / width * dest_width), 0, dest_width
          )
          box[:, 1] = np.clip(
              np.round(box[:, 1] / height * dest_height), 0, dest_height
          )
          boxes[index, :, :] = box.astype(np.int16)
          scores[index] = score
  
      return boxes.tolist(), scores
  
imports: import os
  import math
  import yaml
  from shapely.geometry import Polygon
  import PIL.Image
  import numpy
  import cv2
  import pyclipper
  import torch
  from .model.constructor import Configurable
label_desc: Use image node_id 15 for calling the DBNet obj's underlying member method code with example usage: obj.boxes_from_bitmap(hmap, segmentation, dest_width, dest_height, bbox_min_score, bbox_min_size, max_candidates) and returns: boxes,  scores