Module window
[hide private]
[frames] | no frames]

Source Code for Module window

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  #    window.py 
 5  #        
 6  #    Copyright 2010 Victor Ramirez <virako.9@gmail.com> 
 7  #        
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20   
21   
22   
23  from opencv.highgui import * 
24  from opencv.cv import * 
25  from opencv import * 
26  from difference import * 
27  import camera 
28  import os 
29   
30   
31 -class Window:
32 """Clase para trabajar con ventanas""" 33
34 - def __init__(self):
35 """Creamos una ventana solo si hay más de una cámara para elegir cámara""" 36 self.cam = camera.Camera() 37 self.name_cameras = self.cam.check_name_cameras() 38 self.num_cam = len(self.name_cameras) 39 self.pos = 0
40
41 - def start_window(self):
42 """Funcion que busca cámaras conectadas y devuelve: 43 *1: si no existe camara conectada 44 *2: si solo hay una cámara conectada 45 *3: si hay mas de una cámara conectada 46 """ 47 if self.num_cam == 0: 48 print "There is not camera conected" 49 return -1 50 elif self.num_cam == 1: 51 print "Camera default" 52 return 0 53 elif self.num_cam > 1: 54 print "Choose camera" 55 return 1
56
57 - def create_window(self, name, name_camera = 0):
58 """Funcion que crea una ventana para elegir que cámara vamos a usar""" 59 # TODO quizas no hay camara 60 self.name = name 61 self.camera = self.cam.open_camera(name_camera) 62 cvNamedWindow( self.name, 1 ) 63 cvCreateTrackbar( " ", self.name, self.pos, self.num_cam-1, self.switch_callback )
64
65 - def switch_callback(self, position):
66 """Funcion que crea el callback de selección de cámara""" 67 self.pos = position 68 if self.cam: 69 self.cam.close_camera() 70 71 self.camera = self.cam.open_camera(position)
72
73 - def show_window(self):
74 """Funcion que muestra la ventana creada en pantalla. Funcion en pruebas""" 75 count = 0 76 while 1: 77 frame = self.cam.get_frame() 78 if ( not frame ): 79 print "get_frame failed" 80 return -1 81 82 cvShowImage(self.name, frame ) 83 keystroke = cvWaitKey(30) 84 85 # TODO poner un boton 86 if keystroke == "\n": 87 self.cam.close_camera() 88 return self.pos 89 90 # Update de la captura y destruccion de la ventana 91 self.cam.close_camera() 92 93 cvDestroyWindow(self.name)
94
95 - def close_window(self):
96 """Funcion que destruye la ventana para que no aparezca en pantalla""" 97 cvDestroyWindow(self.name)
98