-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriticon.py
127 lines (100 loc) · 3.24 KB
/
criticon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#coding:latin-1
#!/usr/bin/python
## taken from https://gist.github.com/loleg/5b581d774fc8500325f7
import os
import sys
import time
import random
import json
from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
#import zbar
import zbar
import festival
from PIL import Image
from generador_frases import GeneradorFrases
# Debug mode
DEBUG = False
if len(sys.argv) > 1:
DEBUG = sys.argv[-1] == '-d'
# Configuration options
if not DEBUG:
RESOLUTION = (640, 480)
else:
RESOLUTION = (480, 270)
generador = GeneradorFrases(5)
codes_filename = "data/codes.txt"
with open(codes_filename) as f:
codes = f.readlines()
codes = [x.strip() for x in codes]
# Initialise Raspberry Pi camera
camera = PiCamera()
camera.resolution = RESOLUTION
#camera.framerate = 10
#camera.vflip = True
#camera.hflip = True
#camera.color_effects = (128, 128)
# set up stream buffer
rawCapture = PiRGBArray(camera, size=RESOLUTION)
# allow camera to warm up
time.sleep(0.1)
print("PiCamera ready")
#seleccionar voz en espaõl
festival.execCommand("(voice_JuntaDeAndalucia_es_sf_diphone)")
# Initialise OpenCV window
if DEBUG:
#cv2.namedWindow("#iothack15", cv2.WND_PROP_FULLSCREEN)
#cv2.setWindowProperty("#iothack15", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.namedWindow("#criticon")
print("OpenCV version: %s" % (cv2.__version__))
print("Press q to exit ...")
#scanner = zbar.ImageScanner()
scanner = zbar.Scanner()
#scanner.parse_config('enable')
#festival.sayText("Criticon ha despertado, buscando codigo de barras")
saludo = u"criticón ha despertado, buscando código de barras."
os.system( "echo "+ saludo + " | iconv -f utf-8 -t iso-8859-1 | festival --tts")
#os.system( "echo "+ saludo + " | festival --tts")
# Capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# as raw NumPy array
output = frame.array.copy()
# raw detection code
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY, dstCn=0)
pil = Image.fromarray(gray)
width, height = pil.size
raw = pil.tobytes()
# create a reader
#image = zbar.Image(width, height, 'Y800', raw)
symbols = scanner.scan(gray)
# extract results
for symbol in symbols:
# do something useful with results
streeng = "decoded " + str(symbol.type) + " symbol " + str(symbol.data)
code = str(symbol.data, 'utf-8')
#code = _code.encode('utf-8')
print(streeng)
print(code)
if code in codes:
text = generador.autogenerar()
#text = _text.encode('utf-8')
print(text)
cmd = "echo " + text + " | iconv -f utf-8 -t iso-8859-1 | festival --tts"
os.system(cmd)
#festival.sayText(text.encode('latin-1'))
else:
os.system( "echo criticón no entiende esta obra. Nada que decir | iconv -f utf-8 -t iso-8859-1 | festival --tts")
# show the frame
if DEBUG:
cv2.imshow("#criticon", output)
# clear stream for next frame
rawCapture.truncate(0)
# Wait for the magic key
keypress = cv2.waitKey(1) & 0xFF
if keypress == ord('q'):
break
# When everything is done, release the capture
camera.close()
if DEBUG:
cv2.destroyAllWindows()