def setupCameraMap(self): ''' Sets up camera and map for a given level ''' self.camera = Camera(self.game_screen) self.background = Background(self.game_display) self.game_map = Map(self.game_display, self.screen_dims, 32)
def __init__(self, is_picture=False): self.start_time = datetime.now() self.tank = Tank() self.camera = Camera() self.plc = PLC(self.camera.number) self.is_picture = is_picture if not is_picture: self.camera.start() self.model = TFModel(model_name='sticker')
def main(args): left_motor_pins = { 'forward': 20, 'reverse': 21, 'control': 12 } right_motor_pins = { 'forward': 19, 'reverse': 26, 'control': 13 } app = Application( camera=Camera(args.camera, args.width, args.height, args.quality, args.stopdelay), driver=Driver(left_motor_pins, right_motor_pins) ) app.listen(args.port) tornado.ioloop.IOLoop.current().start()
def on_connect_camera(self, data: int) -> None: """ Funktion zum Verbinden mit einer angeschlossenen Kamera. Wird ausgeführt, sobald der Client die Nachricht "connect_camera" sendet. Funktion liest zuerst alle Verfügbaren Kameras aus. Sofern eine oder mehrere Kameras verfügbar sind und noch keine Kamera verbunden ist wird die Kamera des übetrragenenen Indizes verbundne. Sollte keine Kamera verfügbar sein, wird dem Client eine Fehlermeldung zurück geschickt. :param data: Index der zu verbindenden Kamera :type data: int :return: None """ cameras = Camera.get_available_cameras() if cameras: if not self.camera_selected: self.camera_selected = Camera(data) self.send('camera_init', self.camera_selected.get_information()) else: self.send('camera_not_available')
def play(screen, height): global current_level smooth_end = 0 finished = [] alpha_surf = pygame.Surface(screen.get_size(), pygame.SRCALPHA) alpha_surf.fill((255, 255, 255, 220), special_flags=pygame.BLEND_RGBA_MULT) camera = Camera(screen.get_size()[1]) running = True player1.isMoving = True player1.isMovingDown = True player2.isMoving = True player2.isMovingDown = True draw_sprites = pygame.sprite.Group() while running: playable = player1.isPlayable and player2.isPlayable draw_sprites.empty() time_delta = clock.tick(fps) / 1000 for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: terminate() else: eval(str(buttons.get(event.key))) alpha_surf.fill((255, 255, 255, 250), special_flags=pygame.BLEND_RGBA_MULT) new_alpha = pygame.Surface(screen.get_size(), pygame.SRCALPHA) screen.fill((0, 0, 0)) if not player1.move(time_delta, player_group, tile_group, all_sprites, alpha_surf, finish): finished.append(1) if not player2.move(time_delta, player_group, tile_group, all_sprites, alpha_surf, finish): finished.append(2) if playable and not finished: if player1.rect.y > screen.get_size()[1]: finish.rect.y = player2.rect.y - finish.rect.h finished.append(2) if player2.rect.y > screen.get_size()[1]: finish.rect.y = player1.rect.y - finish.rect.h finished.append(1) elif ((not player1.isPlayable and not player2.isPlayable) and (not finished and (player1.rect.y <= screen.get_size()[1] * 0.6 or player2.rect.y <= screen.get_size()[1] * 0.6))): player1.isPlayable = True player2.isPlayable = True alpha_surf.blit( pygame.transform.scale(load_image("start.png"), screen.get_size()), (0, 0)) player1.inverted += player2.other_inverted * 3 player2.inverted += player1.other_inverted * 3 player1.other_inverted, player2.other_inverted = 0, 0 y = camera.scroll_for( player1 if player1.rect.y < player2.rect.y else player2) new_alpha.blit(alpha_surf, (0, -y)) alpha_surf = new_alpha for sprite in all_sprites: camera.apply(sprite) camera.apply(finish) screen.blit(alpha_surf, (0, 0)) for sprite in tile_group: if 0 - 2 / 3 * tile_size < sprite.rect.y < height: # + tile_size: sprite.add(draw_sprites) draw_sprites.draw(screen) pygame.display.flip() if finished: if playable: result = "Player " + str(finished[0]) + " has won!" if len( finished) == 1 else "draw!" if result == "draw!": player1.isPlayable = False player2.isPlayable = False else: k = ("player" + str(int(result.split("Player ")[1][0]) % 2 + 1) + ".switch_off()") eval(k) smooth_end += time_delta if smooth_end > 1.22: time.sleep(0.3) running = False SCORE[1] += 1 in finished SCORE[2] += 2 in finished current_level += 1 return result
def main(): print("initializing") pool = ThreadPool(processes=1) #Time operator have to push button after product is detected IMG_SAVE_DELAY = 500 #This is used to signal that if operator dont push button then save image to approved folder flagPhotoSensor = False #Resolution on image resolution = (1280, 720) #Paths to put images path_approved = '/media/storage/good/' path_not_approved = '/media/storage/bad/' #Create camera object that takes images and store in approved or not approved folder camera = Camera(resolution, 'png', path_approved, path_not_approved) #GPIO stuff on_off = GPIO(7, 'in') disallowed_img = GPIO(138, 'in') disallowed_img.edge = 'rising' photoSensor = GPIO(140, 'in') photoSensor.edge = 'rising' #Create Display object display = Display() #Variable to handle debounce on input from photosensor lastPhotoSensorValue = False #Variable to handle debounce on input from operator button lastOperatorBtnValue = False #Get time in ms currentTime_ms = lambda: int(round(time.time() * 1000)) #Calculate new time - old time to get time difference between two events deltaTime_ms = lambda oldTime_ms: int(round(time.time() * 1000) ) - oldTime_ms #Store time to calculate time difference oldTime_ms = currentTime_ms() print("initialization done") #Run forever while True: #If system is turned on by switch, run program display.off() if on_off.read() or True: print("System started") #Make sure no old values are stored flagPhotoSensor = False camera.camera.start() #Stay in loop as long as system is turned on while on_off.read() or True: #If there is a product in front of camera, take a picture and record the time if photoSensor.read( ) and not lastPhotoSensorValue and not flagPhotoSensor: #img = camera.camera.get_image() async_img = pool.apply_async(camera.take_image) oldTime_ms = currentTime_ms() #Save that photo sensor has been high flagPhotoSensor = True #If operator push button before IMG_SAVE_DELAY time, save image to not approved folder #and blink red light once to inform operator while deltaTime_ms(oldTime_ms) <= IMG_SAVE_DELAY: if disallowed_img.read() and not lastOperatorBtnValue: img = async_img.get() threading.Thread(target=display.show_img, args=(img, False)).start() camera.save_img(img, False) flagPhotoSensor = False lastOperatorBtnValue = disallowed_img.read() #if operator dont push button before IMG_SAVE_DELAY time run out, save #image to approved folder and blink green light. if (deltaTime_ms(oldTime_ms) > IMG_SAVE_DELAY) and flagPhotoSensor: img = async_img.get() threading.Thread(target=display.show_img, args=(img, True)).start() camera.save_img(img, True) flagPhotoSensor = False camera.camera.stop() lastPhotoSensorValue = photoSensor.read()