It is a Python code to control camera
We need install python-gst0.10 ,
run:
sudo apt-get install python-gst0.10
Next ,Coding for Python,save code file as name : udoo_camera.py
Next, Run It:
sudo python udoo_camera.py
import sys, os import pygtk, gtk, gobject import pygst pygst.require("0.10") import gst import time class GTK_Main: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_title("UDOO-Camera") window.set_default_size(560, 480) window.connect("destroy", gtk.main_quit, "WM destroy") vbox = gtk.VBox() window.add(vbox) self.movie_window = gtk.DrawingArea() vbox.add(self.movie_window) hbox = gtk.HBox() vbox.pack_start(hbox, False) hbox.set_border_width(10) hbox.pack_start(gtk.Label()) self.button = gtk.Button("snapshot") self.button.connect("clicked", self.camera_snapshot) hbox.pack_start(self.button, False) self.button2 = gtk.Button("Quit") self.button2.connect("clicked", self.exit) hbox.pack_start(self.button2, False) hbox.add(gtk.Label()) window.show_all() self.player = gst.parse_launch ("mfw_v4lsrc ! mfw_v4lsink") bus = self.player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() bus.connect("sync-message::element", self.on_sync_message) self.player.set_state(gst.STATE_PLAYING) def camera_snapshot(self, w): image= self.movie_window.window.get_image(0, 0, 560, 480) print "Snapshot: "+str(time.time()) def exit(self, widget, data=None): gtk.main_quit() def on_sync_message(self, bus, message): if message.structure is None: return message_name = message.structure.get_name() if message_name == "prepare-xwindow-id": # Assign the viewport imagesink = message.src imagesink.set_property("force-aspect-ratio", True) imagesink.set_xwindow_id(self.movie_window.window.xid) GTK_Main() gtk.gdk.threads_init() gtk.main()
没有评论:
发表评论