From 7bdb0839fbadd5c43133b7e14a49d41d3dd84e44 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 9 Oct 2014 11:00:07 +0200 Subject: [PATCH] Add a test program for the perspective element --- python/gst-test-perspective.py | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 python/gst-test-perspective.py diff --git a/python/gst-test-perspective.py b/python/gst-test-perspective.py new file mode 100755 index 0000000..b51591a --- /dev/null +++ b/python/gst-test-perspective.py @@ -0,0 +1,73 @@ +#!/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() -- 2.1.4