3 # test program for the "perspective" geometric tranform element
8 gi.require_version('Gst', '1.0')
9 from gi.repository import Gst
12 from gi.repository import GObject
13 GObject.threads_init()
19 width, height = 800, 480
20 corners = [(0, 0), (width, 0), (width, height), (0, height)]
21 target = [(top_x_shift, 0), (width - top_x_shift, 0), (width, height), (0, height)]
23 mat = cv.CreateMat(3, 3, cv.CV_64F)
24 cv.GetPerspectiveTransform(corners, target, mat)
26 inv_mat = cv.CreateMat(3, 3, cv.CV_64F)
27 cv.Invert(mat, inv_mat)
29 matrix = [inv_mat[j, i] for j in range(mat.rows) for i in range(mat.cols)]
34 pipeline = Gst.ElementFactory.make('pipeline', None)
36 videosrc = Gst.ElementFactory.make('videotestsrc', None)
37 pipeline.add(videosrc)
39 # Test the perspective element
40 perspective = Gst.ElementFactory.make("perspective", None)
41 pipeline.add(perspective)
43 print perspective.get_property("matrix")
46 perspective.set_property("matrix", M)
47 print perspective.get_property("matrix")
50 perspective.set_property("matrix", [0])
51 print perspective.get_property("matrix")
53 videoconvert = Gst.ElementFactory.make("autovideoconvert", None)
54 pipeline.add(videoconvert)
56 videosink = Gst.ElementFactory.make("autovideosink", None)
57 pipeline.add(videosink)
59 caps = Gst.caps_from_string(
60 "video/x-raw,format=\"AYUV\",width=800,height=480")
62 videosrc.link_filtered(perspective, caps)
63 perspective.link(videoconvert)
64 videoconvert.link(videosink)
66 pipeline.set_state(Gst.State.PLAYING)
68 loop = GObject.MainLoop()
72 if __name__ == '__main__':