def detectBallProcess(ballLocation, ballLocated): name = multiprocessing.current_process().name print name, " Starting" # setup camera stream videoProxy, cam = camera.setupCamera(ip, port) try: while True: # get and process a camera frame image = camera.getFrame(videoProxy, cam) if image is not False: # Check if we can find a ball, and point the head towards it if so ballDet = camera.findBall(image) if ballDet != False: ballLocated.value = True centerOnBall(ballDet, ballLocation) print "Ball detected" else: ballLocated.value = False print "No ball detected" if cv2.waitKey(33) == 27: videoProxy.unsubscribe(cam) break sleep(0.2) except: pass print name, " Exiting"
def main(): global videoProxy, cam, blocked setup() say("Please give me the command start, to start") # start timer start = time() end = time() try: while end - start < duration: updateSonar() # get and process a camera frame image = camera.getFrame(videoProxy, cam) if image is not False: # Check if we can find a ball, and point the head towards it if so ballDet = camera.findBall(image) if not blocked: onBallDetect(ballDet) # close the video proxy and end the script if escape is pressed if cv2.waitKey(33) == 27: videoProxy.unsubscribe(cam) break # start a random walk if not walking and not blocked and not foundBall: initRandomWalk() # look around if we are not doing much special if not blocked and not foundBall: # look around lookAround() # update time end = time() say("This was my presentation") except KeyboardInterrupt: print "Interrupted by user, shutting down" except Exception, e: print "Unexpected error:", sys.exc_info()[0], ": ", str(e)