Last version from HackWAW. See ya next year!
parent
dab79a6a80
commit
48515b5768
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
|
@ -6,6 +6,7 @@ Created on Nov 10, 2012
|
||||||
|
|
||||||
|
|
||||||
import random, pygame, sys
|
import random, pygame, sys
|
||||||
|
import subprocess
|
||||||
import flask
|
import flask
|
||||||
import threading
|
import threading
|
||||||
import os
|
import os
|
||||||
|
@ -27,6 +28,23 @@ CAMERA_Y = 30
|
||||||
|
|
||||||
cannon = None
|
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"])
|
@app.route("/left/<int:amount>", methods=["POST"])
|
||||||
def move_left(amount):
|
def move_left(amount):
|
||||||
cannon.move_left(amount)
|
cannon.move_left(amount)
|
||||||
|
@ -68,6 +86,8 @@ def status():
|
||||||
def root():
|
def root():
|
||||||
return flask.render_template("status.html", data=cannon.get_data())
|
return flask.render_template("status.html", data=cannon.get_data())
|
||||||
|
|
||||||
|
dot = None
|
||||||
|
dot_pos = None
|
||||||
|
|
||||||
#Camera stuff
|
#Camera stuff
|
||||||
|
|
||||||
|
@ -81,6 +101,9 @@ except:
|
||||||
def main():
|
def main():
|
||||||
#create the screen
|
#create the screen
|
||||||
window = pygame.display.set_mode((1200, 800))
|
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)
|
GRAY = ( 182, 182, 182)
|
||||||
VIOLET = (150, 100, 190)
|
VIOLET = (150, 100, 190)
|
||||||
|
@ -138,6 +161,16 @@ def main():
|
||||||
gunpoint.calibrate(point1, point2, point3)
|
gunpoint.calibrate(point1, point2, point3)
|
||||||
print gunpoint.horizontal_angle, gunpoint.vertical_angle
|
print gunpoint.horizontal_angle, gunpoint.vertical_angle
|
||||||
screen.communicates.append("Calibrated")
|
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()
|
cannon.send_data()
|
||||||
|
|
||||||
elif event.type == MOUSEBUTTONUP:
|
elif event.type == MOUSEBUTTONUP:
|
||||||
|
@ -238,6 +271,10 @@ class Screen:
|
||||||
image = camera.get_image()
|
image = camera.get_image()
|
||||||
self.window.blit(image, (CAMERA_X, CAMERA_Y))
|
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()
|
pygame.display.flip()
|
||||||
|
|
||||||
def print_text(self, text,xx,yy,color,text_size, screen):
|
def print_text(self, text,xx,yy,color,text_size, screen):
|
||||||
|
@ -258,7 +295,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
def flask_runner():
|
def flask_runner():
|
||||||
try:
|
try:
|
||||||
app.run(use_reloader=False)
|
app.run(use_reloader=False, host="0.0.0.0")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "Flask thread raised exception %s" % str(e)
|
print "Flask thread raised exception %s" % str(e)
|
||||||
os.kill(os.getpid(), signal.SIGINT)
|
os.kill(os.getpid(), signal.SIGINT)
|
||||||
|
|
Loading…
Reference in New Issue