X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/blobdiff_plain/a1bef368cff17b0f69f0b138fac329f3769dbe83..a594457d7a30ecb0ec09d2193f9ea789d1430e46:/python/gst-test-perspective.py?ds=inline diff --git a/python/gst-test-perspective.py b/python/gst-test-perspective.py index 9a74823..1b094c2 100755 --- a/python/gst-test-perspective.py +++ b/python/gst-test-perspective.py @@ -1,9 +1,10 @@ #!/usr/bin/env python -# test program for the "perspective" geometric tranform element +# test program for the "perspective" geometric transform element 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")