def convert_input_to_barrier(line): ''' Parse the pig input to create pig object. ''' m = line.strip().split('|') name = m[0] strength = float(m[1]) xCent = float(m[2]) yCent = float(m[3]) radBa = float(m[4]) return Barrier(name, strength, xCent, yCent, radBa)
def open(self): if not self._open: # Open cameras self._captures = [] for id in self._deviceIds: capture = cv2.VideoCapture(id) capture.set(cv2.CAP_PROP_FRAME_WIDTH, self._width) capture.set(cv2.CAP_PROP_FRAME_HEIGHT, self._height) capture.set(cv2.CAP_PROP_FPS, self._framerate) fourcc = cv2.VideoWriter_fourcc(*self._pixel_format) capture.set(cv2.CAP_PROP_FOURCC, fourcc) self._captures.append(capture) self._open = True # Start thread self._barrier = Barrier.Barrier(len(self._deviceIds)) self._threads = [] for id in range(len(self._deviceIds)): self._threads.append( threading.Thread(target=self._eventloop, args=(id, ))) self._threads[id].daemon = True self._threads[id].start()
def setup_level(self): w = len(MAP[0]) h = len(MAP) + 1 # We add a bit of space for the text at the bottom self.barriers = [] self.ghosts = [] self.foods = [] self.stage_width, self._stage_height = w, h - 1 self.size = (w * ICON_SIZE, h * ICON_SIZE) for i in range(len(MAP)): for j in range(len(MAP[i])): key = MAP[i][j] if key == 'P': self.set_player(Pacman(i, j, 24, 24, {})) elif key == 'G': self.add_ghost(Ghost(i, j, 24, 24, {})) elif key == 'O': self.add_food(Food(i, j, 10, 10, {})) elif key == 'X': self.add_barrier(Barrier(i, j, 24, 24, {})) self.goal_CGPA = 3.0 self.current_CGPA = 0.0 self.goal_message = "Objective: Collect good marks to meet your CGPA!"
pigs.append(Pig(pig['xc'], pig['radius'], pig['name'], pig['yc'])) #PRINT INITIAL INFORMATION ABOUT PIGS print() print('There are {} pigs:'.format(len(pigs))) #FOR LOOP TO PRINT PIGS for pig in pigs: print(' {}: ({:.1f},{:.1f})'.format(pig.name, float(pig.x), float(pig.y))) #BARRIER LIST barriers = [] for barrier in dictionary['barriers']: #ADD BARRIER OBJECTS TO A LIST barriers.append( Barrier(barrier['yc'], barrier['name'], barrier['xc'], barrier['radius'], barrier['strength'])) #PRINT INITIAL INFORMATION ABOUT BARRIERS print() print('There are {} barriers:'.format(len(barriers))) #FOR LOOP TO PRINT BARRIERS for barrier in barriers: print(' {}: ({:.1f},{:.1f})'.format(barrier.name, float(barrier.x), float(barrier.y))) #INITIALIZE TIME COUNTER time = 0 #KEEP TRACK OF WHAT BIRD YOURE ON bird_num = 0
#Create pig list pigs = [] #Parse Data for line in open(pig_file): data = line.strip().split("|") pig = Pig(data[0],data[1],data[2],data[3]) pigs.append(pig) #Create barrier list barriers = [] #Parse Data for line in open(barrier_file): data = line.strip().split("|") barrier = Barrier(data[0],data[1],data[2],data[3],data[4]) barriers.append(barrier) #Output initial set-up #Birds first print("") print("There are {} birds:".format(len(birds))) for bird in birds: print(" {}: ({:.1f},{:.1f})".format(bird.name,bird.x,bird.y)) #Now pigs print("") print("There are {} pigs:".format(len(pigs))) for pig in pigs: print(" {}: ({:.1f},{:.1f})".format(pig.name,pig.x,pig.y))
def setup_method(self): self.barrier = Barrier.Barrier(400, 400)
def start_calibration( self, chessboard=(11, 8), duration=30, number_of_samples=100, stereo=True, calibration_file=(dirname(abspath(__file__)) + "/../../../../../json/" + "nico_vision_calibration_params.json"), overwrite=False, term_criteria=(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1), calibration_flags=(cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW)): """ Records images for given duration to calibrate cameras. Calibration related code was partially taken from: https://medium.com/@kennethjiang/calibrate-fisheye-lens-using-opencv-333b05afa0b0 and https://github.com/sourishg/fisheye-stereo-calibration/blob/master/calibrate.cpp (stereo term_criteria and fov_scale) :param chessboard: Dimensions of the chessboard pattern (inner corners) :type chessboard: tuple(int) :param duration: Duration of the recording :type duration: int :param number_of_samples: Subset of images used for calibration (to reduce computing time) :type number_of_samples: int :param stereo: Whether cameras should be calibrated individually or as stereo cameras :type overwrite: bool :param calibration_file: json file path to save calibration parameters :type calibration_file: str :param overwrite: Whether preexisting parameters in the file should be overwritten :type overwrite: bool :param term_criteria: cv2 term_criteria for calibration :type term_criteria: list :param calibration_flags: cv2 calibration_flags :type calibration_flags: list """ self._chessboard = chessboard self._criteria = term_criteria self._calibration_flags = calibration_flags # 2d points in image plane. self._imgpoints = [[]] * len(self._deviceIds) self._rvals = [False] * len(self._deviceIds) self._chess_detection_barrier = Barrier.Barrier(len(self._deviceIds)) devicenames = MultiCamRecorder.get_devices() devicenames = map(lambda i: devicenames[i], self._deviceIds) zoom = self._device.get_zoom() # load preexisting calibrations from file if isfile(calibration_file): with open(calibration_file, 'r') as existing_file: existing_calibration = json.load(existing_file) if (stereo and str(devicenames) not in existing_calibration[ "stereo"]): existing_calibration["stereo"][str(devicenames)] = {} elif (stereo and str(self._dim) in existing_calibration["stereo"][str(devicenames)]): existing_calibration["stereo"][str( devicenames)][str(self._dim)] = {} elif not stereo: for name in devicenames: if name not in existing_calibration["mono"]: existing_calibration["mono"][name] = {} else if str(self._dim) not in existing_calibration[ "mono"][name]: existing_calibration["mono"][name][ str(self._dim)] = {} else: existing_calibration = { "stereo": {str(devicenames): {str(self._dim): {}}}, "mono": dict(zip(devicenames, [{str(self._dim): {}} for _ in devicenames]))} # abort if calibration for device and dim already exists and overwrite # not enabled if not overwrite: if (stereo and str(zoom) in existing_calibration["stereo"] [str(devicenames)][str(self._dim)]): self._logger.warning(("Calibration aborted - Overwrite not " + "enabled and setting for devices {} " + "and dimension {} already exists in {}" ).format(devicenames, self._dim, calibration_file)) return elif not stereo: for i in range(len(self._deviceIds)): if (str(zoom[i]) in existing_calibration["mono"] [str(devicenames[i])][str(self._dim)]): self._logger.warning( ("Calibration aborted - Overwrite " + "not enabled and setting for " + "device {} and dimension {} " + "already exists in {}" ).format(devicenames[i], self._dim, calibration_file)) return # start recording self._logger.info("Start recording images for calibration") self._recorder.add_callback(self._callback) self._recorder._open = True time.sleep(duration) self._chess_detection_barrier.abort() self._recorder.stop_recording() self._stop_event.set() self._display.join() time.sleep(1) self._logger.info("Recording finished - preparing for calibration") # reduce recorded image points to number of samples new_length = min(number_of_samples, len( self._imgpoints[0]), len(self._imgpoints[1])) self._imgpoints = map(lambda x: takespread( x, new_length), self._imgpoints) # start calibration if stereo: calib_params = self._calibrate_stereo() if calib_params: existing_calibration["stereo"][str(devicenames)][str( self._dim)][str(zoom)] = calib_params else: for i in range(len(self._deviceIds)): calib_params = self._calibrate_mono(i) if calib_params: existing_calibration["mono"][devicenames[i]][str( self._dim)][str(zoom[i])] = calib_params # save results self._logger.info("Calibration finished - saving results") self._logger.debug( "Saving calibration {}".format(existing_calibration)) with open(calibration_file, 'w') as outfile: json.dump(existing_calibration, outfile, cls=NumpyEncoder)
import Barrier import Background import random import os import time import sys import Physics #Preventing the recursion limit of the gameloop to close the game sys.setrecursionlimit(10000) Images = ["tankpic2.png", "tankpic.png"] barrier = Barrier.Barrier(random.randint(450, 600), 470) tank1 = Tank.Tank(Images[0], 800, 610, 1, 2) tank2 = Tank.Tank(Images[1], 300, 610, 0, 1) bg = Background.Background() # The introduction screen of the game def game_intro(): intro = True while intro:
#Reads the file and add them to the list as objects for line in open(bd_f): line = line.strip() b = [] b = line.split("|") birds.append(Bird(b[0],b[1],b[2],b[3],b[4],b[5],b[6])) for line in open(pg_f): line = line.strip() p = [] p = line.split("|") pigs.append(Pig(p[0],p[1],p[2],p[3])) for line in open(br_f): line = line.strip() b = [] b = line.split("|") barriers.append(Barrier(b[0],b[1],b[2],b[3],b[4])) #Prints out the initial information print("") print("There are {} birds:".format(len(birds))) for b in birds: print(" " + str(b)) print("") print("There are {} pigs:".format(len(pigs))) for p in pigs: print(" " + str(p)) print("") print("There are {} barriers:".format(len(barriers))) for b in barriers: print(" " + str(b)) print("")