From: Antonio Ospite Date: Mon, 18 Dec 2017 12:53:33 +0000 (+0100) Subject: gst-test-perspective.py: add an example about a rotation transform X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/commitdiff_plain/0e4422e16034ba37df1d4d0e9b659b3db26dc9bd gst-test-perspective.py: add an example about a rotation transform --- diff --git a/python/gst-test-perspective.py b/python/gst-test-perspective.py index 6ddf5b0..1b094c2 100755 --- a/python/gst-test-perspective.py +++ b/python/gst-test-perspective.py @@ -4,6 +4,7 @@ import cv2 import numpy as np +from math import cos, sin, radians import gi gi.require_version('Gst', '1.0') @@ -27,6 +28,24 @@ def calc_matrix(): return inv_mat.flatten() +def calc_rotation_matrix(): + width, height = 800, 480 + + pivot = (width / 2, height / 2) + angle = 10 + theta = radians(angle) + + # The dimensions of the bounding box of the rotated rectangle + W = width * abs(cos(theta)) + height * abs(sin(theta)) + H = width * abs(sin(theta)) + height * abs(cos(theta)) + + scale_factor = 1 / min(width / W, height / H) + + mat = cv2.getRotationMatrix2D(pivot, angle, scale_factor) + mat = np.vstack([mat, [0, 0, 1]]) + + return mat.flatten() + def main(): pipeline = Gst.ElementFactory.make('pipeline', None) @@ -40,7 +59,7 @@ def main(): print perspective.get_property("matrix") - M = calc_matrix() + M = calc_rotation_matrix() perspective.set_property("matrix", M) print perspective.get_property("matrix")