def capture_image(self, call_back=None, section_offset=0): if call_back: self.video_processor.subscribe( ImageCapture(self.encoder.sections, section_offset), call_back) else: self.video_processor.subscribe( ImageCapture(self.encoder.sections, section_offset))
def test_complete_should_be_false_before_all_sections_have_been_captured(self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) [image_capture.handle(frame=frame, section=section) for section in range(4)] self.assertFalse(image_capture.complete)
def test_handle_should_return_false_given_all_sections_have_been_captured(self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) results = [image_capture.handle(frame=frame, section=section) for section in range(5)] self.assertEquals(5, len(results)) self.assertTrue(results[3]) self.assertFalse(results[4])
def test_handle_can_handle_erronous_keywords(self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) [image_capture.handle(frame=frame, section=section, kitten='bohahaha') for section in range(5)] self.assertTrue(image_capture.complete)
def test_status_should_return_amount_complete(self): sections = 10 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) for idx in range(sections): self.assertEquals(idx / float(sections), image_capture.status) image_capture.handle(frame=frame, section=idx, kitten='bohahaha') self.assertEquals(1.0, image_capture.status)
def test_handle_should_store_the_slice_at_the_given_index(self): sections = 200 frame = np.ones((100, 130, 3), dtype='uint8') * 128 frame[:, -1] = (255, 0, 0) expected = np.zeros((100, sections, 3), dtype='uint8') expected[:, 20] = (255, 0, 0) image_capture = ImageCapture(sections) image_capture.handle(frame=frame, section=20) self.assertTrue((image_capture.image == expected).all())
def test_handle_given_a_frame_should_store_the_right_edge(self): sections = 200 frame = np.ones((100, 130, 3), dtype='uint8') * 128 frame[:, -1] = (255, 0, 0) expected = np.zeros((100, sections, 3), dtype='uint8') expected[:, 0] = (255, 0, 0) image_capture = ImageCapture(sections) image_capture.handle(frame=frame) self.assertTrue((image_capture.image[0] == expected[0]).all())
def test_complete_should_be_false_before_all_sections_have_been_captured( self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) [ image_capture.handle(frame=frame, section=section) for section in range(4) ] self.assertFalse(image_capture.complete)
def test_handle_should_return_false_given_all_sections_have_been_captured( self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) results = [ image_capture.handle(frame=frame, section=section) for section in range(5) ] self.assertEquals(5, len(results)) self.assertTrue(results[3]) self.assertFalse(results[4])
def test_handle_can_handle_erronous_keywords(self): sections = 5 frame = np.ones((100, 130, 3), dtype='uint8') * 128 image_capture = ImageCapture(sections) [ image_capture.handle(frame=frame, section=section, kitten='bohahaha') for section in range(5) ] self.assertTrue(image_capture.complete)
def test_handle_should_return_expected_image_when_offset_provided_and_would_be_out_of_bounds(self): sections = 200 frame = np.ones((100, 130, 3), dtype='uint8') * 128 frame2 = frame.copy() frame[:, -1] = (255, 0, 0) frame2[:, -1] = (0, 0, 255) expected = np.zeros((100, sections, 3), dtype='uint8') expected[:, 199] = (255, 0, 0) expected[:, 0] = (0, 0, 255) image_capture = ImageCapture(sections, section_offset = 199) image_capture.handle(frame=frame, section=0) image_capture.handle(frame=frame2, section=1) self.assertTrue((image_capture.image == expected).all())
def test_handle_should_return_expected_image_when_called_multiple_times(self): sections = 200 frame = np.ones((100, 130, 3), dtype='uint8') * 128 frame2 = frame.copy() frame[:, -1] = (255, 0, 0) frame2[:, -1] = (0, 0, 255) expected = np.zeros((100, sections, 3), dtype='uint8') expected[:, 0] = (255, 0, 0) expected[:, 1] = (0, 0, 255) image_capture = ImageCapture(sections) image_capture.handle(frame=frame, section=0) image_capture.handle(frame=frame2, section=1) self.assertTrue((image_capture.image == expected).all())
def test_handle_should_return_expected_image_when_offset_provided(self): sections = 200 frame = np.ones((100, 130, 3), dtype='uint8') * 128 frame2 = frame.copy() frame[:, -1] = (255, 0, 0) frame2[:, -1] = (0, 0, 255) expected = np.zeros((100, sections, 3), dtype='uint8') expected[:, 100] = (255, 0, 0) expected[:, 101] = (0, 0, 255) image_capture = ImageCapture(sections, section_offset=100) image_capture.handle(frame=frame, section=0) image_capture.handle(frame=frame2, section=1) self.assertTrue((image_capture.image == expected).all())