def run(self, camera=False): frame = cv2.namedWindow(FRAME_NAME) # Set callback cv2.setMouseCallback(FRAME_NAME, self.draw) if camera: cap = cv2.VideoCapture(0) for i in range(10): status, image = cap.read() else: image = cv2.imread('00000001.jpg') self.image = cv2.undistort(image, CMATRIX, DIST, None, NCMATRIX) # Get various data about the image from the user self.get_pitch_outline() self.get_zone('Zone_0', 'draw LEFT Defender') self.get_zone('Zone_1', 'draw LEFT Attacker') self.get_zone('Zone_2', 'draw RIGHT Attacker') self.get_zone('Zone_3', 'draw RIGHT Defender') self.get_goal('Zone_0') self.get_goal('Zone_3') print 'Press any key to finish.' cv2.waitKey(0) cv2.destroyAllWindows() # Write out the data # self.dump('calibrations/calibrate.json', self.data) tools.save_croppings(pitch=self.pitch, data=self.data)
def run(self, camera=False): frame = cv2.namedWindow(FRAME_NAME) # Set callback cv2.setMouseCallback(FRAME_NAME, self.draw) if camera: self.image = self.camera.get_raw_frame() else: self.image = cv2.imread('00000001.jpg') self.image = self.camera.fix_radial_distortion(self.image) self.image = self.camera.fix_perspective(self.image) # Get various data about the image from the user self.get_pitch_outline() self.get_zone('Zone_0', 'draw LEFT Defender') self.get_zone('Zone_1', 'draw RIGHT Defender') self.get_zone('Goal_0', 'Point in the center of the left goal') self.get_zone('Goal_1', 'Point in the cneter of the right goal') #self.get_goal('Zone_0') #self.get_goal('Zone_3') print 'Press any key to finish.' cv2.waitKey(0) cv2.destroyAllWindows() # Write out the data # self.dump('calibrations/calibrate.json', self.data) tools.save_croppings(pitch=self.pitch, data=self.data)
def run(self, camera=False): ''' Run constructs a new OpenCV window, displays the frame for cropping and begins the routine of the program asking for user input. :param camera: True indicates using the camera feed, False will use a \ image entitled '00000001.jpg' instead. ''' frame = cv2.namedWindow(FRAME_NAME) # Set mouse callback to the self.draw function cv2.setMouseCallback(FRAME_NAME, self.draw) # If we're using the camera, pull multiple images to ensure # we have a valid one. (Initial pulled images can be strange.) if camera: cap = cv2.VideoCapture(0) for i in range(10): status, image = cap.read() # Otherwise, use plain image else: image = cv2.imread('00000001.jpg') # Apply barrel distortion fix to the image self.image = cv2.undistort(image, CMATRIX, DIST, None, NCMATRIX) self.get_zone('Zone_0', 'draw LEFT Defender') self.get_zone('Zone_1', 'draw LEFT Attacker') self.get_zone('Zone_2', 'draw RIGHT Attacker') self.get_zone('Zone_3', 'draw RIGHT Defender') self.data['Zone_3'].extend(self.data['Zone_2']) self.data['Zone_2'].extend(self.data['Zone_1']) self.data['Zone_1'].extend(sorted(self.data['Zone_0'], key = lambda x : x[0], reverse = True)[:2]) minx = min(self.data['outline'], key = lambda x: x[0])[0] miny = min(self.data['outline'], key = lambda x: x[1])[1] for k in ['Zone_0', 'Zone_1', 'Zone_2', 'Zone_3']: self.data[k] = [(x-minx, y-miny) for (x,y) in self.data[k]] for k in ['outline', 'Zone_0', 'Zone_1', 'Zone_2', 'Zone_3']: self.data[k] = self.sortPoly(self.data[k]) # Calculate the goal positions for each zone self.get_goal('Zone_0') self.get_goal('Zone_3') self.draw_poly(self.reshape()) print 'Press any key to finish.' cv2.waitKey(0) cv2.destroyAllWindows() # Write out the data tools.save_croppings(pitch=self.pitch, data=self.data)