FlaPer87 - import freedom; print everything

  • galería de imagenes
  • presentaciones
  • proyectos
  • copyright
  • contacto
  • acerca de...
Home

Google Adsense

Navigation

  • Recent posts

User login

  • Request new password

Python

Communicating with our application using python and dbus

Submitted by flaper87 on Wed, 06/04/2008 - 10:32.

Hi!!

I've been programming the httpServer and the dbusServer for mouseTrap and I wanted to share how simple is communicate with our applications using dbus and its python bindings.

The piece of code we are interested in is this:

import dbus
import gobject
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop

main_loop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=main_loop)

DBUS_NAME = "org.myApp"
DBUS_PATH = "/org/myApp"

class myAppdBus(dbus.service.Object):
    """
    Our dbus Class
    """

    def __init__( self ):
        """
        Starting the dbus service.
        """
        global bus
        bus_name = dbus.service.BusName(DBUS_NAME, bus=bus)
        dbus.service.Object.__init__(self, bus_name, DBUS_PATH)

    @dbus.service.method(DBUS_NAME)
    def do( self ):
        """
        Function to execute using dbus service
        """
        print "do function has been called using dbus service"


class myApp:

    def __init__(self):
        self.loop = gobject.MainLoop()
        d = myAppdBus()

    def start(self):
        self.loop.run()


if __name__ == '__main__':
    app = myApp()
    app.start()

It is a simple script with 2 classes. The main class called myApp will call the dbus class (myAppdBus) and will start the applications main loop. The second class (myAppdBus) is the dbus class, it starts the service and register the methods that can be called using dbus.

The script can be executed like this (in my case the name of the script is dbus_script.py):


$ python dbus_script.py

After running the script it is possible to execute the do function like this:


$ dbus-send --reply-timeout=30000 --print-reply --dest=org.myApp /org/myApp org.myApp.do

This last command will show us the information related to the call we just executed. The output is something like:

flaper87@r4-p17:~$ dbus-send --reply-timeout=30000 --print-reply --dest=org.myApp
/org/myApp org.myApp.do
method return sender=:1.6 -> dest=:1.7 reply_serial=2

Ass you can the classes are really simple and show an easy way to communicate with our applications using dbus. There are a lot of options a tweaks that can be implemented so it's all in you hands now.

Good Luck.

P.S: Quick post, isn't it? :P

  • communicating
  • dbus
  • English
  • mouseTrap
  • Python
  • Python
  • service
  • Add new comment

Comenzando con OpenCV

Submitted by flaper87 on Fri, 05/30/2008 - 04:18.

OpenCv (Open Source Computer Vision Library) es una librería de funciones principalmente orientadas al procesamiento de imágenes en tiempo real.

En este post colocare un ejemplo de como utilizar OpenCV para realizar una simple captura y mostrarla en un frame.

import sys
from opencv import cv,highgui

if __name__ == '__main__':
    #Iniciamos la captura del device 0. Ej: /dev/video
    capture = highgui.cvCreateCameraCapture (0)

    # Revisamos que este Capturando.
    if not capture:
        print "Error Abriendo el device /dev/video0"
        sys.exit (1)

    # Creamos las ventanas necesarias.
    highgui.cvNamedWindow ("Ejemplo OpenCV", highgui.CV_WINDOW_AUTOSIZE)

    while 1:
        # Loop Infinito.

        # 1. Capturamos la imagen actual
        frame = highgui.cvQueryFrame (capture)

        # 1.1 Si no hay captura salimos.
        if frame is None:
            break

        # 2. Mostramos la imagen
        highgui.cvShowImage ("Ejemplo OpenCV", frame)

        # 3. Manejar Eventos. Esta función debe ser llamada periódicamente,
        # por eso esta dentro del loop
        c = highgui.cvWaitKey (10)

        #Revisamos si alguna tecla de nuestro interés fue presionada
        if c == '\x1b':
            # Esc fue presionado, Salimos.
            break

    cvDestroyWindow( "Ejemplo OpenCV" );

Como pueden apreciar los pasos son muy simples:

  1. Nos conectamos al device
  2. Comenzamos a capturar
  3. Mostramos la captura
  4. Capturamos teclas.
  5. Procesamos las capturas

Espero que les sirva como una pequeña introducción a opencv + python, seguire publicando otras formulas secretas :P para explicar pocas de las infinidades de cosas que se pueden hacer con esta combinacion :D

Feliz Día a todos!!

  • camaras
  • GNU/Linux
  • imagenes
  • opencv
  • opencv
  • procesamiento
  • Python
  • Python
  • 3 comments
Syndicate content

Search

  • a11y-en
  • a11y-es
  • Anuncios
  • ArchLinux
  • curiosidades
  • Debian
  • Docbook
  • Drupal
  • English
  • Enlightenment
  • Español
  • Eventos
  • GNU/Linux
  • Italiano
  • Latex
  • mouseTrap
  • opencv
  • Poesias
  • Python
  • Reflexiones
  • Subversion
  • Tiflotecnología
  • Ubuntu
  • Uncategorized
  • Web
  • wordpress

Twitter Updates

Twitter Logo

    follow me on Twitter



    • galería de imagenes
    • presentaciones
    • proyectos
    • copyright
    • contacto
    • acerca de...