def test_transform_set_select_merge_fade_rejected(self): with deepstar_path(): with mock.patch.dict(os.environ, {'DEBUG_LEVEL': '0'}): route_handler = VideoCommandLineRouteHandler() video_0001 = os.path.dirname(os.path.realpath(__file__)) + '/../../support/video_0001.mp4' # noqa route_handler.insert_file(video_0001) route_handler.select_extract([1]) route_handler = FrameSetCommandLineRouteHandler() route_handler.select_extract([1], 'transform_set', {}) route_handler.select_extract([1], 'transform_set', {}) transform_model = TransformModel() transform_model.update(1, rejected=1) transform_model.update(10, rejected=1) FadeTransformSetSelectMergePlugin().transform_set_select_merge([1, 2], {'frame-count': '2'}) # noqa # db result = TransformSetModel().select(3) self.assertEqual(result, (3, 'fade', None, None)) result = TransformModel().list(3) self.assertEqual(len(result), 6) self.assertEqual(result[0], (11, 3, 2, None, 0)) self.assertEqual(result[1], (12, 3, 3, None, 0)) self.assertEqual(result[2], (13, 3, None, None, 0)) self.assertEqual(result[3], (14, 3, None, None, 0)) self.assertEqual(result[4], (15, 3, 3, None, 0)) self.assertEqual(result[5], (16, 3, 4, None, 0)) # files p1 = TransformSetSubDir.path(3) # transforms self.assertIsInstance(cv2.imread(TransformFile.path(p1, 11, 'jpg')), np.ndarray) # noqa self.assertIsInstance(cv2.imread(TransformFile.path(p1, 12, 'jpg')), np.ndarray) # noqa self.assertIsInstance(cv2.imread(TransformFile.path(p1, 13, 'jpg')), np.ndarray) # noqa self.assertIsInstance(cv2.imread(TransformFile.path(p1, 14, 'jpg')), np.ndarray) # noqa self.assertIsInstance(cv2.imread(TransformFile.path(p1, 15, 'jpg')), np.ndarray) # noqa self.assertIsInstance(cv2.imread(TransformFile.path(p1, 16, 'jpg')), np.ndarray) # noqa
def transform_set_select_curate(self, transform_set_id, opts): """ This method automatically curates a transform set and rejects transforms with width or height less than 'min-size'. :param int transform_set_id: The transform set ID. :param dict opts: The dict of options. :raises: ValueError :rtype: None """ if 'min-size' not in opts: raise ValueError( 'The min-size option is required but was not supplied') min_length = int(opts['min-size']) transform_model = TransformModel() length = 100 offset = 0 p1 = TransformSetSubDir.path(transform_set_id) while True: transforms = transform_model.list(transform_set_id, length=length, offset=offset) if not transforms: break for transform in transforms: p2 = TransformFile.path(p1, transform[0], 'jpg') debug(f'Curating transform with ID {transform[0]:08d} at {p2}', 4) h, w = cv2.imread(p2).shape[:2] if h < min_length or w < min_length: transform_model.update(transform[0], rejected=1) debug(f'Transform with ID {transform[0]:08d} rejected', 4) offset += length
def put(self, transform_set_id, transform_id): transform_model = TransformModel() result = transform_model.update( transform_id, rejected=request.get_json()['rejected']) if result is False: abort(404) result = transform_model.select(transform_id) if result is None: abort(404) return jsonify(result)
def test_update(self): with deepstar_path(): FrameSetModel().insert(None) FrameModel().insert(1, 0) TransformSetModel().insert('test', 1) transform_model = TransformModel() transform_model.insert(1, 1, 'test1', 0) result = transform_model.select(1) self.assertEqual(result, (1, 1, 1, 'test1', 0)) result = transform_model.update(1, 'test2', 1) self.assertTrue(result) result = transform_model.select(1) self.assertEqual(result, (1, 1, 1, 'test2', 1))