--- /dev/null
+#!/usr/bin/env python
+
+# test program for the "perspective" geometric tranform element
+
+import cv
+
+import gi
+gi.require_version('Gst', '1.0')
+from gi.repository import Gst
+Gst.init(None)
+
+from gi.repository import GObject
+GObject.threads_init()
+
+
+def calc_matrix():
+ top_x_shift = 200
+
+ width, height = 800, 480
+ corners = [(0, 0), (width, 0), (width, height), (0, height)]
+ target = [(top_x_shift, 0), (width - top_x_shift, 0), (width, height), (0, height)]
+
+ mat = cv.CreateMat(3, 3, cv.CV_64F)
+ cv.GetPerspectiveTransform(corners, target, mat)
+
+ inv_mat = cv.CreateMat(3, 3, cv.CV_64F)
+ cv.Invert(mat, inv_mat)
+
+ matrix = [inv_mat[j, i] for j in range(mat.rows) for i in range(mat.cols)]
+ return matrix
+
+
+def main():
+ pipeline = Gst.ElementFactory.make('pipeline', None)
+
+ videosrc = Gst.ElementFactory.make('videotestsrc', None)
+ pipeline.add(videosrc)
+
+ # Test the perspective element
+ perspective = Gst.ElementFactory.make("perspective", None)
+ pipeline.add(perspective)
+
+ print perspective.get_property("matrix")
+
+ M = calc_matrix()
+ perspective.set_property("matrix", M)
+ print perspective.get_property("matrix")
+
+ # This should fail!
+ perspective.set_property("matrix", [0])
+ print perspective.get_property("matrix")
+
+ videoconvert = Gst.ElementFactory.make("autovideoconvert", None)
+ pipeline.add(videoconvert)
+
+ videosink = Gst.ElementFactory.make("autovideosink", None)
+ pipeline.add(videosink)
+
+ caps = Gst.caps_from_string(
+ "video/x-raw,format=\"AYUV\",width=800,height=480")
+
+ videosrc.link_filtered(perspective, caps)
+ perspective.link(videoconvert)
+ videoconvert.link(videosink)
+
+ pipeline.set_state(Gst.State.PLAYING)
+
+ loop = GObject.MainLoop()
+ loop.run()
+
+
+if __name__ == '__main__':
+ main()