From 48515b57682bc23747045cdb64247eb6219bbe7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Sun, 11 Nov 2012 23:08:51 +0100 Subject: [PATCH] Last version from HackWAW. See ya next year! --- Lasers_und_stuff/crosshair.png | Bin 0 -> 4491 bytes Lasers_und_stuff/main.py | 101 ++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 Lasers_und_stuff/crosshair.png diff --git a/Lasers_und_stuff/crosshair.png b/Lasers_und_stuff/crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..a3f0cd348e5d0bced6520648ee36d74175cfab2f GIT binary patch literal 4491 zcmc&$cTm&W7QPXrH>o1V1?dQcj&w-qRUk+ZQHl^0ks?YH486G^Al)FSv{0mIAQYtu z2ojpqP^5`~z*~wzX%FA-+tqpVX5Jrf$C-QQ&UfbA`F`h|@7(i?IcKWJNOyt`0KjOV zuWbPUWb@mmp*pm54Nb)!9<-kNHa7u~Zkc{*~UDdOWX_c+YO8Di;1sOR_|$A>+Mj_ur;4t(M^R8RiUz5ilZeW7FnTh&9| zNW+k-FKaH3VJL#1I`%%Sy|rz6PEs?3PQVke&{SRFySc{?0o%ctBLZcgb7tU(N`G$k>JGQEtC)e!FR$cd{pm zHr#RiLxSFJHT}UZbl`NWfg=GW#y)G#>J_h@d2d4|?{o}2N%XZ~|G|}+De)Z&^(lE! zeoY+`m?%+b=S1<@NSFoX(>Oy0V7<757-1;#aOy2tlmO=C|lM-X6K43fM6xTGy0 ziR`S>Xr}={J10b}T#IM3>9}|!)ybx#<4yFt_6p%}f!1a?3!Lr>=A^g1Xh|qsB(l34 zDrOIRrwNs7G;csGbgLp`}qmAdkVP=y~VD~V+rbrcB#gX$EjsouS-d`wZJRR ziqj@Lbyb`$VJL1pQGULJqAq63si(r1k~Ku9kye4y7tZT&N=qMQj4~b3FXTNbAa`tx zR*{w>+`L)%baJ85bD`Q}Us{hl%1B3{^u_sySQFS_EP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JypGh(vy@dYYa=WX`XJXMKmO)Or_ebB6U#X7AlxIrku#4Y4fQ)g(?3y9k?y%pVjM9}j1@QR%o z3T89)!r^NqmPef7#FfTzcSK~|Z=NU0qw`h9_=D#~#jS)ZJudw&iytN>vTd1C zacLjYm~JqRjy-3bI{$oS>$46Cmewsostdy-2v1(A*3>%}ydie0Xds^=H<4eF3akAS zFC2!qZ}hG51lE6+`!q@ahx(qt+80=J$HOgXei`%I??slc7?p`bH z6#W!?)cj2NVZysXXulfLB4OyvvK~|WFE978YrYbU3XE32K5U!e_tf^ETO`v?kxwxy zkKMi(STapL@XKu|8Vb7x&s@*c&9cngv30bqHG8YxH?%Yvu&YP0=lFyRre)51>d)>pj%re47H^OQ_!;3%{@*+>RB5`7~!T&eTgQ3A}CAEo$ zjQ|hwYx33<=R~l#@E){_>{giqc7J?iZT#-FM&F!`zHvP= zRYX|Ne&SXFGva7MMnYF4W8`x7S#>3)84d5f#oYo#&y^mbY_9#s`(0&RoUq{S!R29M zUwU6|+Im{@EB8BjdrOVW+|NjD&26V%zVVZlzO;FMXQjz^+!wm`WQy5r?hfx=kptH+ z6nh@+)s={?Hl=HkWX+ z!i_wdy%_9MTpcEFPH=6}&v-ATmFkna5CB@#fD#H=e1K*zeSs|8)6=|F$cK zls|#>$Ji7hfJPbcegv2t3J}WlZT*S=F#V4Iayi6*y8OSd98&%S)*oZ5rTr$3zsmlz zYjjw!A8YoX65hAJ-jjZ$rfDU;h(z@;lu7(H?kKdTS=jfd3JfFM_W8OcP^^K<3M#y3 z_pz_Al=#@lp-%YuHU3`mf2W>*RMz*b-#6NS>7w1Hg3c04k0kmG1V@E+lT%W DHLaz- literal 0 HcmV?d00001 diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py index 3b3851c..296ea0d 100644 --- a/Lasers_und_stuff/main.py +++ b/Lasers_und_stuff/main.py @@ -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/", methods=["POST"]) def move_left(amount): cannon.move_left(amount) @@ -55,7 +73,7 @@ def move_down(amount): def fire(): cannon.fire() cannon.send_data() - + @app.route("/stop_fire/", methods=["POST"]) def stop_fire(): pass @@ -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,30 +101,33 @@ 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) RED = (150, 0, 0) GREEN = (0, 150, 0) BLUE = (30, 30, 180) VERYLIGHT = (210, 210, 210) - + colors = [GRAY, VIOLET, RED, GREEN, BLUE, VERYLIGHT] - + global cannon cannon = HackWAWCannonController() - - + + screen = Screen(window, colors) screen.draw_surface(cannon) - + gunpoint = Gunpoint((5, 4), (200, 4), (5, 210)) - - + + keep_running = True while keep_running: screen.draw_surface(cannon) - + for event in pygame.event.get(): if event.type == pygame.QUIT: keep_running = False @@ -119,7 +142,7 @@ def main(): cannon.move_up(20) elif event.key == K_DOWN: cannon.move_down(20) - elif event.key == K_l: + elif event.key == K_l: if cannon.laser: cannon.disable_laser() if "Laser enabled" in screen.communicates : @@ -130,7 +153,7 @@ def main(): if "Laser disabled" in screen.communicates : screen.communicates.remove("Laser disabled") screen.communicates.append("Laser enabled") - elif event.key == K_c: + elif event.key == K_c: point1 = get_calibration_point(window, "Point1") point2 = get_calibration_point(window, "Point2") point3 = get_calibration_point(window, "Point3") @@ -138,8 +161,18 @@ 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: mousex, mousey = pygame.mouse.get_pos() print mousex, mousey @@ -152,7 +185,7 @@ def main(): screen.change_color() print "Pygame thread exited." os.kill(os.getpid(), signal.SIGINT) - + def get_key(): @@ -169,11 +202,11 @@ def display_box(screen, message, xx, yy): pygame.draw.rect(screen, (222,222,222),(xx, yy, 300,30), 0) pygame.draw.rect(screen, (20,20,20), (xx -2, yy-2, 302,34), 1) - + if len(message) != 0: screen.blit(font_object.render(message, 3, (0,0,0)), (xx + 6, yy + 6) ) - + pygame.display.flip() def ask(screen, question): @@ -196,15 +229,15 @@ def ask(screen, question): display_box(screen, question + ": " + "".join(current_string), 20, 400) return "".join(current_string) - + def get_calibration_point(screen, message): point_string = ask(screen, message) while(not (is_valid_point(point_string)) ): point_string = ask(screen, "Again, " + message) return [float(x) for x in point_string.split(",")] - + def is_valid_point(string): - point = string.split(',') + point = string.split(',') if (len(point) != 2): return False if((not point[0].isdigit()) or (not point[1].isdigit())): @@ -214,7 +247,7 @@ def is_valid_point(string): return True class Screen: - + def __init__(self, window, colors): self.communicates = [] self.communicates.append("Press space to fire!") @@ -224,29 +257,33 @@ class Screen: self.window = window self.colors = colors self.color = random.choice(self.colors) - + def change_color(self): self.color = random.choice(self.colors) - + def draw_surface(self, cannon): self.window.fill(self.color) for i, text in enumerate(self.communicates): - self.print_text(text, 20, 20 + i*20, (0, 0, 0), 30, self.window) - - self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window) + self.print_text(text, 20, 20 + i*20, (0, 0, 0), 30, self.window) + + self.print_text([str(x) for x in cannon.get_data()].__str__(), 20, 300, (0, 0, 0), 30, self.window) if camera: image = camera.get_image() self.window.blit(image, (CAMERA_X, CAMERA_Y)) - - pygame.display.flip() - + + 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): font = pygame.font.SysFont(None,text_size) ren = font.render(text,1,color) screen.blit(ren, (xx,yy)) - - + + if __name__ == '__main__': def pygame_runner(): try: @@ -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) @@ -267,4 +304,4 @@ if __name__ == '__main__': print "Starting pygame..." t.start() print "Starting flask..." - t2.start() \ No newline at end of file + t2.start()