Example #1
0
def rotateNEstimateImage():
    """
    Example of image rotation.
    """
    nonRotatedImage = VLImage.load(filename=EXAMPLE_O)
    faceEngine = VLFaceEngine()
    orientationModeEstimator = faceEngine.createOrientationModeEstimator()
    #: rotate & estimate | not rotated
    image = VLImage.rotate(nonRotatedImage, RotationAngle.ANGLE_0)
    pprint.pprint(orientationModeEstimator.estimate(image))
    #: rotate & estimate | left
    image = VLImage.rotate(nonRotatedImage, RotationAngle.ANGLE_90)
    pprint.pprint(orientationModeEstimator.estimate(image))
    #: rotate & estimate | right
    image = VLImage.rotate(nonRotatedImage, RotationAngle.ANGLE_270)
    pprint.pprint(orientationModeEstimator.estimate(image))
    #: rotate & estimate | upside down
    image = VLImage.rotate(nonRotatedImage, RotationAngle.ANGLE_180)
    pprint.pprint(orientationModeEstimator.estimate(image))
Example #2
0
async def asyncRotateNEstimateImage():
    """
    Async example of image rotation.
    """
    nonRotatedImage = VLImage.load(filename=EXAMPLE_O)
    faceEngine = VLFaceEngine()
    orientationModeEstimator = faceEngine.createOrientationModeEstimator()
    #: rotate & estimate | not rotated
    image = VLImage.rotate(nonRotatedImage, RotationAngle.ANGLE_0)
    orientation = await orientationModeEstimator.estimate(image,
                                                          asyncEstimate=True)
    pprint.pprint(orientation)
    task1 = orientationModeEstimator.estimate(image, asyncEstimate=True)
    task2 = orientationModeEstimator.estimate(image, asyncEstimate=True)
    for task in (task1, task2):
        pprint.pprint(task.get())
Example #3
0
    def test_image_rotation(self):
        """
        Test image rotation: 0, 90, 180 and 270 degrees
        """
        testData = [
            (RotationAngle.ANGLE_0, OrientationType.NORMAL, ROTATED0),
            (RotationAngle.ANGLE_90, OrientationType.LEFT, ROTATED90),
            (RotationAngle.ANGLE_180, OrientationType.UPSIDE_DOWN, ROTATED180),
            (RotationAngle.ANGLE_270, OrientationType.RIGHT, ROTATED270),
        ]

        for rotationAngle, expectedOrientationMode, expectedImageFileName in testData:
            with self.subTest(rotationAngle=rotationAngle):
                rotatedImage = VLImage.rotate(self.image, rotationAngle)
                orientationMode = self.orientationModeEstimator.estimate(
                    rotatedImage)
                assert orientationMode == expectedOrientationMode
                assert (VLImage.load(filename=expectedImageFileName).asPillow(
                ).tobytes() == rotatedImage.asPillow().tobytes())