3 # test program for the "perspective" geometric tranform element
9 gi.require_version('Gst', '1.0')
10 from gi.repository import Gst
13 from gi.repository import GObject
14 GObject.threads_init()
20 width, height = 800, 480
21 corners = np.array([(0, 0), (width, 0), (width, height), (0, height)], dtype=np.float32)
22 target = np.array([(top_x_shift, 0), (width - top_x_shift, 0), (width, height), (0, height)], dtype=np.float32)
24 mat = cv2.getPerspectiveTransform(corners, target)
25 ret, inv_mat = cv2.invert(mat)
27 return inv_mat.flatten()
32 pipeline = Gst.ElementFactory.make('pipeline', None)
34 videosrc = Gst.ElementFactory.make('videotestsrc', None)
35 pipeline.add(videosrc)
37 # Test the perspective element
38 perspective = Gst.ElementFactory.make("perspective", None)
39 pipeline.add(perspective)
41 print perspective.get_property("matrix")
44 perspective.set_property("matrix", M)
45 print perspective.get_property("matrix")
48 perspective.set_property("matrix", [0])
49 print perspective.get_property("matrix")
51 videoconvert = Gst.ElementFactory.make("autovideoconvert", None)
52 pipeline.add(videoconvert)
54 videosink = Gst.ElementFactory.make("autovideosink", None)
55 pipeline.add(videosink)
57 caps = Gst.caps_from_string(
58 "video/x-raw,format=\"AYUV\",width=800,height=480")
60 videosrc.link_filtered(perspective, caps)
61 perspective.link(videoconvert)
62 videoconvert.link(videosink)
64 pipeline.set_state(Gst.State.PLAYING)
66 loop = GObject.MainLoop()
70 if __name__ == '__main__':