Created
December 12, 2014 13:51
-
-
Save Krb686/cad6284b2a8ef2bf5b07 to your computer and use it in GitHub Desktop.
Python Webcam Laser Tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import psyco | |
class Tracker(object): | |
def __init__(self): | |
psyco.full() | |
self.createVariables() | |
def createVariables(self): | |
pass | |
def track(self, image): | |
self.whitelist = [] | |
pixels = image.load() | |
for y in range(image.size[1]): | |
for x in range(image.size[0]): | |
if pixels[x,y][0] > 245 and pixels[x,y][1] > 245 and pixels[x,y][2] > 245: | |
self.whitelist.append((x,y)) | |
pixels[x,y] = (0,255,0) | |
left = top = 1000 | |
right = bottom = 0 | |
for x,y in self.whitelist: | |
if x < left: | |
left = x | |
if x > right: | |
right = x | |
if y < top: | |
top = y | |
if y > bottom: | |
bottom = y | |
center = (((right + left)/2),((bottom+top) / 2)) | |
if len(self.whitelist) > 0: | |
for z in range(image.size[1]): | |
pixels[center[0], z] = (0,0,255) | |
for z in range(image.size[0]): | |
pixels[z, center[1]] = (0,0,255) | |
return image | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment