RobotApi.ubtStartRobotAction("for", 5) # 待调 # 矫正方位 if __name__ == "__main__": camera = PiCamera() camera.resolution = (480, 320) camera.framerate = 25 flag = 0 start = time.time() with picamera.array.PiRGBArray(camera, size=(480, 320)) as output: for frame in camera.capture_continuous(output, format="bgr", use_video_port=True): frame = frame.array frame = color_detection.balanced(frame) if color_detection.find_yellow(frame): flag = 1 print "find yellow" elif flag == 1: print "start forward" RobotApi.ubtStartRobotAction("first", 1) RobotApi.ubtStartRobotAction("for", 6) break else: print "find nothing" end = time.time() if end - start >= 20: print "time out" break output.truncate(0)
import glob import color_detection fs = glob.glob('/home/pi/Desktop/test0816/*.jpg') for f in fs: if 'balance' in f: img = color_detection.cv2.imread(f) balance = color_detection.balanced(img) color_detection.cv2.imwrite(f, balance) print fs