Last version from HackWAW. See ya next year!

master
q3k 2012-11-11 23:08:51 +01:00
parent dab79a6a80
commit 48515b5768
2 changed files with 69 additions and 32 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -6,6 +6,7 @@ Created on Nov 10, 2012
import random, pygame, sys
import subprocess
import flask
import threading
import os
@ -27,6 +28,23 @@ CAMERA_Y = 30
cannon = None
def run_detection():
p = subprocess.Popen("/home/q3k/balloontracker/facedetect", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write("\n")
p.stdin.write("\n")
p.stdin.write("\n")
p.stdin.write("\n")
p.stdin.flush()
print("L: " + p.stdout.readline())
print("L: " + p.stdout.readline())
print("L: " + p.stdout.readline())
data = p.communicate()[0]
lines = data.split("\n")
print lines
x, y = [int(i) for i in lines[-2].split(",")]
global dot_pos
dot_pos = (x, y)
@app.route("/left/<int:amount>", methods=["POST"])
def move_left(amount):
cannon.move_left(amount)
@ -68,6 +86,8 @@ def status():
def root():
return flask.render_template("status.html", data=cannon.get_data())
dot = None
dot_pos = None
#Camera stuff
@ -81,6 +101,9 @@ except:
def main():
#create the screen
window = pygame.display.set_mode((1200, 800))
global dot
dot = pygame.image.load("crosshair.png").convert_alpha()
dot = pygame.transform.scale(dot, (25, 25))
GRAY = ( 182, 182, 182)
VIOLET = (150, 100, 190)
@ -138,6 +161,16 @@ def main():
gunpoint.calibrate(point1, point2, point3)
print gunpoint.horizontal_angle, gunpoint.vertical_angle
screen.communicates.append("Calibrated")
elif event.key == K_d:
global camera
startcam = False
if camera:
camera.stop()
run_detection()
startcam = True
camera = pygame.camera.Camera("/dev/video0", (640, 480))
if startcam:
camera.start()
cannon.send_data()
elif event.type == MOUSEBUTTONUP:
@ -238,6 +271,10 @@ class Screen:
image = camera.get_image()
self.window.blit(image, (CAMERA_X, CAMERA_Y))
global dot
if dot_pos:
self.window.blit(dot, (dot_pos[0] - 12 + CAMERA_X, dot_pos[1] - 12 + CAMERA_Y))
pygame.display.flip()
def print_text(self, text,xx,yy,color,text_size, screen):
@ -258,7 +295,7 @@ if __name__ == '__main__':
def flask_runner():
try:
app.run(use_reloader=False)
app.run(use_reloader=False, host="0.0.0.0")
except Exception as e:
print "Flask thread raised exception %s" % str(e)
os.kill(os.getpid(), signal.SIGINT)