1
2 """
3 [cam.py]
4 Modulo que utiliza la cam para captar las fotos del cubo.
5 """
6
7 __author__ = "Victor Ramirez de la Corte"
8 __date__ = "02/04/2009"
9 __version__ = "PyRubik v0.5"
10
11 import pygame
12 from pygame.locals import *
13 import sys, os
14 import opencv
15 from opencv import highgui
16 import colorsys
17 from language import *
18
19 camera = highgui.cvCreateCameraCapture(0)
21 """devuelve la imagen obtenida desde la cam utilizando el modulo opencv"""
22 im = highgui.cvQueryFrame(camera)
23 im = opencv.cvGetMat(im)
24 return opencv.adaptors.Ipl2PIL(im)
25
26
28 """Clase que utiliza la cam para hacer 2 o 6 fotos del cubo, segun elijas"""
30 fps = 30.0
31 pygame.init()
32 pygame.display.init()
33 window = pygame.display.set_mode((640,480))
34 pygame.display.set_caption("PyRubik")
35 screen = pygame.display.get_surface()
36 if numMalla == 2:
37 malla = pygame.image.load("DATOS/malla2.png")
38 posicionador = pygame.image.load("DATOS/posicionador.png")
39 cont = 6
40 square = pygame.Rect((0,0), (160,160))
41 text = lll.press
42 pos = ((0,0),(0,160),(160,160),(320, 160),(480,160),(480,320))
43
44 else:
45 malla = pygame.image.load("DATOS/malla1.png")
46 cont = 2
47 text = lll.press[:lll.press.index(" ")] + " 1(XXL), 2(XL), 3(L)"
48
49 font = pygame.font.Font(os.path.join( "FONT", "Times.ttf" ) , 30)
50 cut = 0
51
52 while 1:
53 im = get_image()
54 pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
55 pg_img = pygame.transform.flip(pg_img, True, False)
56 fuente = font.render(text, True, (255, 255, 0))
57 screen.blit(pg_img, (0,0))
58 screen.blit(malla, (0,0))
59 if numMalla == 2: screen.blit(posicionador, pos[abs(cont-6)])
60 screen.blit(fuente, (300,0))
61 pygame.display.flip()
62 pygame.time.delay(int(1000 * 1.0/fps))
63
64 pygame.event.pump()
65 keypress = pygame.key.get_pressed()
66
67 if keypress[K_RETURN] and numMalla == 2:
68 pygame.image.save(pg_img, "capa%d.png" % abs(cont-6))
69 cont -=1
70 if cont <= 0: break
71
72 elif (keypress[K_1] or keypress[K_2] or keypress[K_3]) and numMalla != 2:
73 if keypress[K_1]: cut = 442
74 elif keypress[K_2]: cut = 338
75 elif keypress[K_3]: cut = 258
76 print cut
77 rect1 = pygame.Rect((640-(640-cut)/2, 480-(480-cut)/2), (640, 480))
78 rect2 = pygame.Rect((0, 0), (0+(640-cut)/2, 0+(480-cut)/2))
79
80 subScreen = pygame.transform.chop(pg_img, rect1)
81 subSubScreen = pygame.transform.chop(subScreen, rect2)
82 subSubScreen = pygame.transform.flip(subSubScreen, True, False)
83 pygame.display.flip()
84 pygame.image.save(pg_img, "capa%d.png" % cont)
85 cont -= 1
86
87 if cont <= 0:
88 break
89