def __init__(self, pitch, width=640, height=480): self.width = width self.height = height self.pitch = pitch self.new_polygon = True self.polygon = self.polygons = [] self.points = [] self.camera = Camera(pitch=pitch) keys = [ 'outline', 'Zone_0', 'Zone_1', 'Zone_2', 'Zone_3', 'pitch_inner', "Goal_0", "Goal_1" ] self.data = self.drawing = {} # Create keys for key in keys: self.data[key] = [] self.drawing[key] = [] self.color = RED
drivers.init() drivers.LED4.off() print("Self-identifying...") identity = None with open("identity.dat", "r") as file: identity = file.readlines()[0].strip() print(identity, "online. Pray to Lafayette Official God.\nWaiting for start signal") while not os.path.isfile("go"): pass os.remove("go") print("Go time!") camera = Camera() mod = VisionModule(width=640, height=480) collecting = False drivers.move(drivers.RobotState(drivers.DRIVE, -in_to_cm(6))) def sweep(): cube = turn_to_block() if cube != None: drivers.move(drivers.RobotState(drivers.DRIVE, -cube.dist / 3)) cube = turn_to_block() if cube != None: drivers.move(drivers.RobotState(drivers.DRIVE, -cube.dist / 5)) drivers.move(drivers.RobotState(drivers.TURN, math.pi)) drivers.move(drivers.RobotState(drivers.DRIVE, 10))
import cv2 from vision import Camera import argparse parser = argparse.ArgumentParser() parser.add_argument("pitch", help="[0] Main pitch, [1] Secondary pitch") args = parser.parse_args() pitch_number = int(args.pitch) capture = Camera(pitch=pitch_number) while True: frame = capture.get_frame() cv2.imwrite("currBg_" + str(pitch_number) + ".png", frame) #cv2.imwrite("../currBg_" + str(pitch_number) + ".png", frame) cv2.imshow('Background view', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break print "done"
Save perspetive point fixes """ tools.save_data(self.pitch, self.points, 'calibrations/perspective.json') if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() parser.add_argument("pitch", help="[0] Main pitch, [1] Secondary pitch") args = parser.parse_args() pitch_number = int(args.pitch) WINDOW_NAME = 'Perspective Calibration' cam = Camera(pitch=pitch_number) perspective = Perspective(pitch_number) cv2.namedWindow(WINDOW_NAME) cv2.setMouseCallback(WINDOW_NAME, perspective.add_point) while (1): frame = cam.get_raw_frame() frame = cam.fix_radial_distortion(frame) frame = perspective.draw_points(frame) cv2.imshow(WINDOW_NAME, frame) if cv2.waitKey(20) & 0xFF == 27: break