From 0e4422e16034ba37df1d4d0e9b659b3db26dc9bd Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Mon, 18 Dec 2017 13:53:33 +0100 Subject: [PATCH] gst-test-perspective.py: add an example about a rotation transform --- python/gst-test-perspective.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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") -- 2.1.4