def __init__(self, group_size: int, moving_foreground: MovingForegroundMixin) -> None: Stage.__init__(self) MovingForegroundMixin.__init__(self) self._group_size = group_size self._moving_foreground = moving_foreground
def __init__(self, kernel_size: int, preprocessed_frame: PreprocessedFrameMixin): PreprocessedFrameMixin.__init__(self) Stage.__init__(self) self._kernel_size = kernel_size self._preprocessed_frame = preprocessed_frame
def __init__(self, min_size: int, baboons: BaboonsMixin) -> None: Stage.__init__(self) BaboonsMixin.__init__(self) self._min_size = min_size self._baboons = baboons
def __init__(self, baboons: BaboonsMixin, frame: FrameMixin) -> None: Stage.__init__(self) self._baboons = baboons self._frame = frame self._file = None self.__enter__()
def __init__( self, shifted_history_frames: ShiftedHistoryFramesMixin, quantized_frames: QuantizedFramesMixin, ) -> None: Stage.__init__(self) GroupShiftedHistoryFramesMixin.__init__(self) self._shifted_history_frames = shifted_history_frames self._quantized_frames = quantized_frames
def __init__( self, shifted_history_frames: ShiftedHistoryFramesMixin, quantized_frames: QuantizedFramesMixin, ) -> None: Stage.__init__(self) HistoryOfDissimilarityMixin.__init__(self) self._shifted_history_frames = shifted_history_frames self._quantized_frames = quantized_frames
def __init__( self, moving_foreground: MovingForegroundMixin, ) -> None: BlobImageMixin.__init__(self) BaboonsMixin.__init__(self) self._moving_foregrouned = moving_foreground Stage.__init__(self)
def __init__(self, history_frame_count: int, preprocessed_frame: PreprocessedFrameMixin): self._history_frame_popped_subject = Subject() self.history_frame_popped = self._history_frame_popped_subject HistoryFramesMixin.__init__(self, history_frame_count, self.history_frame_popped) Stage.__init__(self) self._history_frame_count = history_frame_count self._preprocessed_frame = preprocessed_frame
def __init__(self, video_path: str): FrameMixin.__init__(self) CaptureMixin.__init__(self) Stage.__init__(self) self._capture = cv2.VideoCapture(video_path) self.frame_width = int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH)) self.frame_height = int(self._capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) self.fps = self._capture.get(cv2.CAP_PROP_FPS) self.frame_count = self._capture.get(cv2.CAP_PROP_FRAME_COUNT) self._frame_number = 1
def test_stage_order_1(self): data = [1, 2, 3, 4, 5, 6] non_pipeline = list(map(self.func_add_ten, map(self.func_double, data))) res = pipeline([ Stage(self.func_double, n_workers=2), Stage(self.func_add_ten, n_workers=2), ], initial_data=data) res.join() self.assertEqual(non_pipeline, [12, 14, 16, 18, 20, 22]) self.assertEqual(res.values, non_pipeline)
def __init__( self, moving_foreground: MovingForegroundMixin, shifted_masks: ShiftedMasksMixin, frame: FrameMixin, ) -> None: Stage.__init__(self) MovingForegroundMixin.__init__(self) self._moving_foreground = moving_foreground self._shifted_masks = shifted_masks self._frame = frame
def test_stage_order_2(self): # reverses function order from test_stage_order_1 data = [1, 2, 3, 4, 5, 6] non_pipeline = list(map(self.func_double, map(self.func_add_ten, data))) res = pipeline([ Stage(self.func_add_ten, n_workers=2), Stage(self.func_double, n_workers=2), ], initial_data=data) res.join() self.assertEqual(non_pipeline, [22, 24, 26, 28, 30, 32]) self.assertEqual(res.values, non_pipeline)
def test_async_unordered(self): data = [1, 2, 3, 4, 5, 6] non_pipeline = list(map(self.func_double, map(self.func_add_ten, data))) res = pipeline([ Stage(randomize_pause(self.func_add_ten), n_workers=10), Stage(randomize_pause(self.func_double), n_workers=10), ], initial_data=data) res.join() values = res.values self.assertNotEqual(values, non_pipeline) for x in values: self.assertIn(x, non_pipeline)
def __init__( self, preprocessed_frame: PreprocessedFrameMixin, unioned_frames: UnionedFramesMixin, weights: WeightsMixin, history_frames: int, ) -> None: Stage.__init__(self) ForegroundMixin.__init__(self) self._preprocessed_frame = preprocessed_frame self._unioned_frames = unioned_frames self._weights = weights self._history_frames = history_frames
def __init__( self, required_motion_observations: int, required_no_motion_observations: int, moving_foreground: MovingForegroundMixin, ) -> None: Stage.__init__(self) MovingForegroundMixin.__init__(self) self._result = None self._motion_observations = None self._no_motion_observations = None self._required_motion_observations = required_motion_observations self._required_no_motion_observations = required_no_motion_observations self._moving_foreground = moving_foreground
def __init__( self, erode_kernel_size: int, dilate_kernel_size: int, combine_kernel_size: int, moving_foreground: MovingForegroundMixin, ) -> None: Stage.__init__(self) MovingForegroundMixin.__init__(self) self._erode_kernel_size = erode_kernel_size self._dilate_kernel_size = dilate_kernel_size self._combine_kernel_size = combine_kernel_size self._moving_foreground = moving_foreground
def __init__( self, history_of_dissimilarity: HistoryOfDissimilarityMixin, foreground: ForegroundMixin, weights: WeightsMixin, frame_mixin: FrameMixin, history_frames: int, ) -> None: Stage.__init__(self) MovingForegroundMixin.__init__(self) self._history_of_dissimilarity = history_of_dissimilarity self._foreground = foreground self._weights = weights self._frame = frame_mixin self._history_frames = history_frames
def __init__( self, blob_det_params: Dict[str, any], moving_foreground: MovingForegroundMixin, ) -> None: BlobImageMixin.__init__(self) BaboonsMixin.__init__(self) self._blob_det_params = cv2.SimpleBlobDetector_Params() for key in blob_det_params: setattr(self._blob_det_params, key, blob_det_params[key]) self._moving_foregrouned = moving_foreground # Create a detector with the parameters self._detector = cv2.SimpleBlobDetector_create(self._blob_det_params) Stage.__init__(self)
def test_partition(self): res = pipeline([ Stage(self.func_double), Reduce(partition(size=3), initial_value=None), ], initial_data=range(5)).join() values = res.values self.assertEqual( values, [[[0, 2, 6], [4, 8]], [[0, 2, 6], [4, 8]], [[0, 2, 6], [4, 8]]])
def test_reduce(self): data = [1, 2, 3, 4, 5, 6] non_pipeline = reduce(self.func_total, map(self.func_double, data)) res = pipeline([ Stage(self.func_double, n_workers=2), Reduce(self.func_total, initial_value=0), ], initial_data=data).join() values = res.values self.assertNotEqual(values, non_pipeline)
def __init__( self, dist_threshold: int, same_region_threshold: float, baboons: BaboonsMixin, frame: FrameMixin, ) -> None: Stage.__init__(self) BaboonsMixin.__init__(self) self._dist_threshold = dist_threshold self._same_region_threshold = same_region_threshold self._baboons = baboons self._frame = frame self._counter = 0 self._all_baboons = {} self._create_directory()
def test_filter(self): data = range(15) non_pipeline = list( filter(self.func_evens, map(self.func_double, data))) data = range(15) res = pipeline([ Stage(self.func_double), Filter(self.func_evens), ], initial_data=data).join() values = res.values self.assertEqual(sorted(values), non_pipeline)
def __init__(self, dependent: any, capture: CaptureMixin): Stage.__init__(self) scale = 0.85 width = os.getenv("WIDTH") height = os.getenv("HEIGHT") if not width or not height: if os.environ.get("DISPLAY", "") == "": width = 0 height = 0 else: root = tk.Tk() width = root.winfo_screenwidth() height = root.winfo_screenheight() width = int(width) height = int(height) width_scale = width / capture.frame_width height_scale = height / capture.frame_height if width_scale < height_scale: height = capture.frame_height * width_scale else: width = capture.frame_width * height_scale width = int(width * scale) height = int(height * scale) self.im_size = (width, height) self._dependent = dependent self._frame_attributes = None
def integerify(x): try: return int(x) except: return None def triple(x): try: return 3 * x except: return None if __name__ == "__main__": integerify_stage = Stage(integerify, n_workers=2) triple_stage = Stage(triple, n_workers=2) print(pipeline([integerify_stage, triple_stage], sys.stdin).join().values) p = pipeline([integerify_stage, triple_stage], sys.stdin) for x in p.out_q: print(x) p = pipeline([integerify_stage, triple_stage], sys.stdin) while 1: sys.stdin.flush() p = pipeline([integerify_stage, triple_stage], sys.stdin) if p.out_q: print(p.out_q.get()) gevent.sleep(0)
def framework(environ, start_response): """ framework handles gluing together functions that handle WebOb request and response objects. This is just a slightly messy example of how stage functions could be layered to build a web framework. None of the actual stage implementations are complete. """ settings = Settings() @expand_args def attach_settings(request, response): request.settings = settings return request, response @expand_args def get_cookies_user(request, response): if not hasattr(request, 'user') or request.user is None: if 'user' in request.cookies: request.user = User(request.cookies['user']) if not hasattr(request, 'user'): request.user = None return request, response @expand_args def get_basicauth_user(request, response): if not hasattr(request, 'user') or request.user is None: if request.authorization: scheme, credential = request.authorization if scheme == 'Basic': credential = credential.encode('utf-8') login, password = b64decode(credential).decode( 'utf-8').split(':') if (login, password) in settings.basicauth_credentials: request.user = User(login) response.set_cookie('user', login) if not hasattr(request, 'user'): request.user = None return request, response @expand_args def dispatch(request, response): for exp, view_func in settings.urls: if re.match(exp, request.path_url): # TODO: parse arguments return view_func(request, response) raise exc.HTTPNotFound @expand_args def controller(request, response, **kwargs): return request, response @expand_args def render(request, response): if hasattr(response, 'jinja2_template') and hasattr( response, 'context'): response.text = response.jinja2_template.render(**response.context) return request, response request = Request(environ) response = Response() framework_pipeline = pipeline([ Stage(attach_settings), Stage(get_cookies_user), Stage(get_basicauth_user), Stage(dispatch), Stage(controller), Stage(render) ], initial_data=[(request, response)]) framework_pipeline.join() request, response = framework_pipeline.values[0] return response(environ, start_response)
def __init__(self, quantized_frames: QuantizedFramesMixin) -> None: Stage.__init__(self) WeightsMixin.__init__(self) self._quantized_frames = quantized_frames
def __init__(self, intersected_frames: IntersectedFramesMixin) -> None: Stage.__init__(self) UnionedFramesMixin.__init__(self) self._intersected_frames = intersected_frames
def __init__(self) -> None: Stage.__init__(self)
def __init__(self, frame: FrameMixin, baboons: BaboonsMixin) -> None: Stage.__init__(self) self._frame = frame self._baboons = baboons self.region_frame: Frame = None
def __init__(self, capture: CaptureMixin, frame: FrameMixin) -> None: Stage.__init__(self) self._frame_count = int(capture.frame_count) self._progress = None self._frame = frame