I'm revisiting an old IR tracking project, and want to use it in a blender game.
I would like to know if anyone could help optimize the parsing algorithm or tell me an easier way to track multiple points with code.
"im" is an instance of an image I captured via VideoCapture module that accesses the webcam. I use Image from PIL to find pixels. There is a filter on the webcam, so I only get IR light. All other pixel values are black or (0,0,0).
I've tried using psycho to speed things up a bit. I'm thinking threading could help the speed, but I'm new to threading; if that's even an option.
#Method to parse for two IR points. #This method is really slow; even with psycho. #Returns average of each point so we map the middle of the dot #not just the first true value. def xy(self,im,res): imxy =  x = 0 y = 0 p1x = p1y = p2x = p2y = 0 while x*y <= res: #Resolution of the cam. 640*480 if im.getpixel((x,y)) > (250,250,250): #RGB threshold imxy.append((x,y)) x += 1 if x == 640: x = 0 y += 1 if y == 480: break #Take the average point1 = imxy[:len(imxy)/2] #slice to separate the two dots point2 = imxy[len(imxy)/2:] for i in points1: p1x += i p1y += i for i in points2: p2x += i p2y += i #return average return (p1x/len(point1),p1y/len(point1)),(p2x/len(point2),p2y/len(point2))