diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2012-02-04 06:29:57 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2012-02-04 06:29:57 (GMT) |
commit | 3e78fdfda653f22448e9c0f20d4ba4524b73633f (patch) | |
tree | 24426d16c0961bf0a5d65876b24ea0f6f020fa1d /qreader.py | |
parent | 949d17fd643d48eec442a8f3e524cfaa28efeee7 (diff) |
adding files to begin to process
Diffstat (limited to 'qreader.py')
-rwxr-xr-x | qreader.py | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/qreader.py b/qreader.py new file mode 100755 index 0000000..18fa10c --- /dev/null +++ b/qreader.py @@ -0,0 +1,152 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# QReader +# Copyright (C) 2011, 2012, Alan Aguiar +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Contact information: +# Alan Aguiar <alanjas@gmail.com> + +import pygame +import pygame.camera +import gtk + +import time +from gettext import gettext as _ + +# seteamos el tamaño de captura +tamanioc = (320, 240) + +from qrtools import QR + +class Captura(object): + + def __init__(self, tamanio): + # creamos una superfcie para usarla de pantalla + self.pantalla = pygame.display.get_surface() + # creamos una superficie para la captura + self.captura = pygame.surface.Surface(tamanio, 0, self.pantalla) + # inicializamos el modulo pygame de la camara + pygame.camera.init() + # inicializo en None la cámara + self.cam = None + # obtenemos la lista de camaras + self.lcamaras = pygame.camera.list_cameras() + # si no hay ninguna camara + if self.lcamaras: + # creamos la camara, con tamanio y modo color RGB + self.cam = pygame.camera.Camera(self.lcamaras[0], tamanio, 'RGB') + # obtengo la resolución de la cámara + res = self.cam.get_size() + # si no es 320, 240 (Sugar nuevo) + if not (res == tamanio): + tamanio = (352, 288) + # inicializo en 352, 288 + self.cam = pygame.camera.Camera(self.lcamaras[0], tamanio, 'RGB') + try: + # seteamos flip en horizontal, vertical false + self.cam.set_controls(True, False) + # iniciamos la camara + self.cam.start() + # obtengo el estado + res = self.cam.get_controls() + # guardo si el flip lo hace la cámara + self.flip = res[0] + except: + print _('Error en la inicialización de la cámara') + else: + # mandamos el error correspondiente + print _('No se encontro ninguna camara.') + + + + def obtener_captura(self): + # guardamos una captura + self.captura = self.cam.get_image(self.captura) + # si el flip no lo hace la cámara + if not(self.flip): + # giro la captura en el horizontal + self.captura = pygame.transform.flip(self.captura,True,False) + + + def mostrar_posicion(self): + + # escalo la captura para mostrar + self.captura2 = pygame.transform.scale(self.captura, (int(self.tamaniom[0]), int(self.tamaniom[1]))) + # si es una posicion valida + if (x != -1): + # creo un punto para mostrar la posicion + rect = pygame.draw.rect(self.captura2, (255,0,0), (x*self.c1, y*self.c2, 20, 20), 16) + # rellenamos la pantalla con un color homogeneo + self.pantalla.fill((84,185,72)) + + # muestro la captura en pantalla + self.pantalla.blit(self.captura2, (self.xblit, self.yblit)) + # rellenamos la esquina superior con el color calibrado + self.pantalla.fill(color, (0,0,120,120)) + # recuadramos el color para resaltarlo + rect = pygame.draw.rect(self.pantalla, (0,0,0), (0,0,120,120), 4) + + + def limpiar(self): + # relleno la pantalla con un color homogeneo + self.pantalla.fill((84, 185, 72)) + + + +class QReader: + + def __init__(self, parent): + # guardo referencia al padre + self.parent = parent + # para manejar la tasa de refresco + self.clock = pygame.time.Clock() + + + + def run(self): + + myCode = QR() + + # establezco un tamaño incial + self.tamanioi = (960.0, 720.0) + # por defecto se muestra la captura + self.mostrar = True + # creamos una captura, inicializamos la camara + #self.c = Captura((640, 480)) + + + # mientras True + while True: + # Pump GTK messages. + while gtk.events_pending(): + gtk.main_iteration() + # Pump PyGame messages. + for event in pygame.event.get(): + if event.type == pygame.QUIT: + # salgo + return + elif event.type == pygame.VIDEORESIZE: + pygame.display.set_mode(event.size, pygame.RESIZABLE) + + + #print myCode.decode_webcam() + + + # actualizo la pantalla + pygame.display.flip() + # seteo a 10 CPS (CuadrosPorSegundo) + self.clock.tick(10) |