# Path: video_processing/stream_processor.py
# class Frame(collections.namedtuple('FrameSet', ['index', 'data'])):
# class StreamSet(collections.namedtuple('StreamSet', ['frame_rate_hz',
#                                                      'stream_headers'])):
# class ProcessorBase(object):
#   def __new__(cls, index=0, data=None):
#   def __new__(cls, frame_rate_hz=-1):
#   def __init__(self, configuration):
#   def open(self, stream_set):
#   def process(self, frame_set):
#   def close(self):


from video_processing import stream_processor
import cv2
    self._bbox_stream_name = configuration.get('bounding_box_stream_name',
                                               'object_bounding_boxes')
    self._object_image_output_directory = configuration.get(
        'object_image_output_directory', None)
    self._image_width = 0
    self._image_height = 0

  def open(self, stream_set):
    headers = stream_set.stream_headers[self._video_stream_name].header_data
    self._image_width = headers.image_width
    self._image_height = headers.image_height
    self._background_subtractor = cv2.bgsegm.createBackgroundSubtractorMOG()
    stream_set.stream_headers[
        self._bbox_stream_name] = stream_processor.StreamHeader(
            frame_data_type=list, header_data=[])
    return stream_set

  def process(self, frame_set):
    if frame_set.get(self._video_stream_name, False):
      frame_index = frame_set[self._video_stream_name].index
      video_frame = frame_set[self._video_stream_name].data
      foreground_mask = self._background_subtractor.apply(video_frame)
      contours, _ = cv2.findContours(foreground_mask,
                                        cv2.RETR_EXTERNAL,
                                        cv2.CHAIN_APPROX_SIMPLE)
      if contours:
        # TODO(tomwalters): Add more logic to merge bounding boxes that overlap.
        frame_data = []
        for contour in contours:
          frame_data.append(cv2.boundingRect(contour))

# Path: video_processing/stream_processor.py
# class Frame(collections.namedtuple('FrameSet', ['index', 'data'])):
# class StreamSet(collections.namedtuple('StreamSet', ['frame_rate_hz',
#                                                      'stream_headers'])):
# class ProcessorBase(object):
#   def __new__(cls, index=0, data=None):
#   def __new__(cls, frame_rate_hz=-1):
#   def __init__(self, configuration):
#   def open(self, stream_set):
#   def process(self, frame_set):
#   def close(self):


# Path: video_processing/processors/foreground_object_tracker.py
from video_processing import stream_processor
import cv2

    self._bbox_stream_name = configuration.get('bounding_box_stream_name',
                                               'object_bounding_boxes')
    self._object_image_output_directory = configuration.get(
        'object_image_output_directory', None)
    self._image_width = 0
    self._image_height = 0

  def open(self, stream_set):
    headers = stream_set.stream_headers[self._video_stream_name].header_data
    self._image_width = headers.image_width
    self._image_height = headers.image_height
    self._background_subtractor = cv2.bgsegm.createBackgroundSubtractorMOG()
    stream_set.stream_headers[
        self._bbox_stream_name] = stream_processor.StreamHeader(
            frame_data_type=list, header_data=[])
    return stream_set

  def process(self, frame_set):
    if frame_set.get(self._video_stream_name, False):
      frame_index = frame_set[self._video_stream_name].index
      video_frame = frame_set[self._video_stream_name].data
      foreground_mask = self._background_subtractor.apply(video_frame)
      contours, _ = cv2.findContours(foreground_mask,
                                        cv2.RETR_EXTERNAL,
                                        cv2.CHAIN_APPROX_SIMPLE)
      if contours:
        # TODO(tomwalters): Add more logic to merge bounding boxes that overlap.
        frame_data = []
        for contour in contours:
          frame_data.append(cv2.boundingRect(contour))

          frame_set[self._bbox_stream_name] = stream_processor.Frame(