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

Source Code for Module text_screen

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  #    text_screen.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.cv import * 
24   
25 -class Text_screen():
26 """Clase para insertar texto en las imágenes""" 27
28 - def __init__(self):
29 """Inicializamos la fuente que usaremos""" 30 self.font = cvInitFont(1, 1, 1.0, 1.0)
31
32 - def insert_text(self, img, text, point = (20,20), colour = (0,0,0)):
33 """Función que nos inserta texto en una imagen dada (una auxiliar). 34 Parámetros: 35 *img: imagen que usaremos para colocar el texto 36 *text: texto que insertaremos 37 *point: coordenada de la imagen donde insertaremos el texto 38 *colour: color del texto """ 39 self.img = img 40 self.text = text 41 self.colour = colour 42 self.point = CvPoint() 43 self.point.x = point[0] 44 self.point.y = point[1] 45 self.img_aux = cvCloneImage(self.img) 46 cvPutText(self.img_aux, text, self.point, self.font, self.colour)
47
48 - def get_image(self):
49 """Funcion que nos devuelve la imagen auxiliar donde anteriormente 50 habremos introducido el texto""" 51 return self.img_aux
52
53 - def change_color(self,colour):
54 """Función que cambiar el color del texto""" 55 insert_text(self, self.text, colour)
56
57 - def change_pos(self, num_pixel = (0, 0)): # val puede ser pos o neg.
58 """Funcion para mover la posición del texto un número de pixeles. 59 *num_pixel: posición que moveremos los pixeles en los ejes (x,y), 60 dependiendo de si el valor es positivo o negativo moveremos hacia 61 un lado u otro """ 62 # TODO, comprobar si el texto está fuera de la imagen para avisar 63 self.point.x = self.point.x + num_pixel[0] 64 self.point.y = self.point.y + num_pixel[1] 65 self.img_aux = cvCloneImage(self.img) # copiamos la imagen original 66 cvPutText(self.img_aux, self.text, self.point, self.font, self.colour)
67