<commit_before>#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 festival
from PIL import Image

# 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)

json_file = open("data/db.json")

db = json.load(json_file)

# 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.parse_config('enable')


#festival.sayText("Criticon ha despertado, buscando codigo de barras")
os.system( "echo criticón ha despertado, buscando código de barras. | iconv -f utf-8 -t iso-8859-1 | 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)
    scanner.scan(image)

    # extract results
    for symbol in image:
        sys.stdout.write("\a")
	sys.stdout.flush()
        # do something useful with results
        streeng = "decoded " + str(symbol.type) + " symbol " + str(symbol.data)
        print streeng
	try:
            tags = db['codes'][str(symbol.data)]

            _text = random.choice(db[tags[0]]) + random.choice(db[tags[1]])
            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'))

        except KeyError:
            os.system( "echo criticón ha despertado, buscando código de barras. | 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)<commit_msg>fixed prints<commit_after>#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 festival
from PIL import Image

# 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)

json_file = open("data/db.json")

db = json.load(json_file)

# 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.parse_config('enable')


#festival.sayText("Criticon ha despertado, buscando codigo de barras")
os.system( "echo criticón ha despertado, buscando código de barras. | iconv -f utf-8 -t iso-8859-1 | 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)
    scanner.scan(image)

    # extract results
    for symbol in image:
        sys.stdout.write("\a")
        sys.stdout.flush()
        # do something useful with results
        streeng = "decoded " + str(symbol.type) + " symbol " + str(symbol.data)
        print(streeng)
        try:
            tags = db['codes'][str(symbol.data)]

            _text = random.choice(db[tags[0]]) + random.choice(db[tags[1]])
            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'))

        except KeyError:
            os.system( "echo criticón ha despertado, buscando código de barras. | 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)
{'fraction_non_alphanumeric': 0.12184146763586017, 'fraction_numerical': 0.028729664243682937, 'mean_word_length': 3.2649446494464947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1005864', 'n_tokens_mistral': 2116, 'n_tokens_neox': 1999, 'n_words': 509}