def test_return_type(self, img, pipeline_): r = pipeline_.run(img) assert isinstance(r, tuple) assert len(r) == 2 out, ctx = r assert is_image(out) assert isinstance(ctx, PipelineContext)
def _raise_if_invalid_img(img: Image, returned_from: Optional[str] = None): if not utils.is_image(img): message = 'Invalid image' if returned_from is not None: message += f' returned from "{returned_from}"' message += f': {img}' raise BadImageError(message)
def __init__(self, original_img: Image): if not is_image(original_img): raise ValueError('Invalid original image') self.original_img = original_img.copy() self.original_img.flags.writeable = False self._scopes = list() self.info = dict()
def img2QImage(img: np.ndarray) -> QImage: if not is_image(img): raise ValueError('Invalid image') # Using straight numpy here just so we don't have a direct dependency on opencv if img.ndim == 2: img = np.repeat(img[..., None], 3, axis=2) else: img = img[..., ::-1].copy( ) # QImage doesn't accept a memoryview. So we make a copy height, width, _ = img.shape bytes_per_line = 3 * width qimg = QImage(img.data, width, height, bytes_per_line, QImage.Format_RGB888) return qimg
def test_is_image_valid(img): assert is_image(img)
def test_is_image_random_object(): assert not is_image(object())
def test_is_image_none(): assert not is_image(None)
def test_is_image_invalid(img): assert not is_image(img)