class_docstr: The basic structure of a flow based motion estimator
  To implement your own flow tracker, extend the followting methods:
  
  compuate_flow(): given preprocessed information, compute optical flow map
  prepare_frame(): for preprocessing, the results will be stored and provided to next frame's inference
class_docstr_tok: ["The","basic","structure","of","a","flow","based","motion","estimator","To","implement","your","own","flow","tracker",",","extend","the","followting","methods",":","compuate_flow","(",")",":","given","preprocessed","information",",","compute","optical","flow","map","prepare_frame","(",")",":","for","preprocessing",",","the","results","will","be","stored","and","provided","to","next","frame","'s","inference"]
docstr: Use the computed denseflow map to estimate the movement of the object bounding box
  then warp the boxes to their new locations.
  
  Parameters
  ----------
  image_shape: tuple
  bboxes: numpy.ndarray shape: (n, 4)
  flow_map: numpy.ndarray shape: (h, w, 2)
  
  Returns: predicted new locations of the boxes, numpy.ndarray shape: (n, 4)
  -------
docstr_tok: ["Use","the","computed","denseflow","map","to","estimate","the","movement","of","the","object","bounding","box","then","warp","the","boxes","to","their","new","locations",".","Parameters","--","--","--","--","--","image_shape",":","tuple","bboxes",":","numpy.ndarray","shape",":","(","n",",","4",")","flow_map",":","numpy.ndarray","shape",":","(","h",",","w",",","2",")","Returns",":","predicted","new","locations","of","the","boxes",",","numpy.ndarray","shape",":","(","n",",","4",")","--","--","--","-"]
code: def _warp_bbox(
      cls, image_shape: tuple, bboxes: np.ndarray, flow_map: np.ndarray
  ):
      """
      Use the computed denseflow map to estimate the movement of the object bounding box
      then warp the boxes to their new locations.
  
      Parameters
      ----------
      image_shape: tuple
      bboxes: numpy.ndarray shape: (n, 4)
      flow_map: numpy.ndarray shape: (h, w, 2)
  
      Returns: predicted new locations of the boxes, numpy.ndarray shape: (n, 4)
      -------
  
      """
      # pylint: disable=logging-format-interpolation,bare-except
      flow_shape = flow_map.shape
  
      flow_h, flow_w, _ = flow_shape
  
      t0 = time.time()
      image_h = image_shape[0]
      image_w = image_shape[1]
  
      image2flow_ratio_h = image_h / flow_h
      image2flow_ratio_w = image_w / flow_w
  
      logging.info(
          "ratio: {}x{}".format(image2flow_ratio_w, image2flow_ratio_h)
      )
  
      # Remap the delta to image coordinate space
      flow_map[..., 0] *= image2flow_ratio_w
      flow_map[..., 1] *= image2flow_ratio_h
  
      flow_map_bboxes = bboxes.copy()
      flow_map_bboxes[:, 0] /= image2flow_ratio_w
      flow_map_bboxes[:, 2] /= image2flow_ratio_w
      flow_map_bboxes[:, 1] /= image2flow_ratio_h
      flow_map_bboxes[:, 3] /= image2flow_ratio_h
      warped_bboxes = []
  
      for flow_bbox, raw_bbox in zip(flow_map_bboxes, bboxes):
          x0, y0, x1, y1 = (
              int(flow_bbox[0]),
              int(flow_bbox[1]),
              int(flow_bbox[2]),
              int(flow_bbox[3]),
          )
  
          delta_x = flow_map[
              y0 : max(y1, y0 + 1), x0 : max(x1, x0 + 1), 0
          ]
          delta_y = flow_map[
              y0 : max(y1, y0 + 1), x0 : max(x1, x0 + 1), 1
          ]
  
          dx = np.mean(delta_x)
          dy = np.mean(delta_y)
  
          if np.isnan(dx) or np.isnan(dy):
              warped_bboxes.append(raw_bbox)
          else:
              warped_bboxes.append(
                  [
                      raw_bbox[0] + dx,
                      raw_bbox[1] + dy,
                      raw_bbox[2] + dx,
                      raw_bbox[3] + dy,
                  ]
              )
      logging.info(
          "bbox warping runtime cost {}".format(time.time() - t0)
      )
  
      return np.array(warped_bboxes)
  
imports: import time
  import logging
  from abc import ABC, abstractmethod
  import numpy
label_desc: Use image node_id 5 for calling the BaseFlowMotionEstimator obj's underlying member method code with example usage: obj._warp_bbox(cls, image_shape, bboxes, flow_map) and returns: np