X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/blobdiff_plain/49dc6e41e256a942d4f76fadd35399a7b2e39008..87e464c0b3660c7dcf381c52a9b7449911219290:/python/gst-test-perspective.py?ds=inline 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")