import cv2
import numpy as np
+from math import cos, sin, radians
import gi
gi.require_version('Gst', '1.0')
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)
print perspective.get_property("matrix")
- M = calc_matrix()
+ M = calc_rotation_matrix()
perspective.set_property("matrix", M)
print perspective.get_property("matrix")