def setup(self, all_sprites): self.image = None self.zoomPoint = None self.preview = False self.timer = 0 # detect focus self.focus = ProcessFocus() self.focus.start() # stack images self.stack = ProcessStacking() self.stack.start() self.showStack = False # tracking images self.telescope = Telescope(self.config['telescope_dev']) self.tracker = ProcessTracking(self.telescope) self.tracker.start() self.tracking = False self.focusText = LcarsText((255,0,0), (17,303), "Focus: ") self.trackingText = LcarsText((255,0,0), (17,380), "Track: ") all_sprites.add(LcarsBackgroundImage("assets/jarvis.png")) all_sprites.add(self.focusText) all_sprites.add(self.trackingText)
class PiScopeProxy: def __init__(self): self.x_correction = 0 self.y_correction = 0 def setCorrection(self, x_correction, y_correction): self.x_correction = x_correction self.y_correction = y_correction cap = cv2.VideoCapture(p) ret, frame = cap.read() rows, cols = frame.shape[:2] piscope = PiScopeProxy() tracker = ProcessTracking(piscope) tracker.controllerX.SetKp(2.0) tracker.controllerX.SetKi(1.0) tracker.controllerY.SetKp(2.0) tracker.controllerY.SetKi(1.0) tracker.start() def now(): time.time() - time_origin def bump(x): if random.random() < x: return 1
class MainScreen(LcarsScreen): def __init__(self, config, camera): self.config = config self.cam = camera LcarsScreen.__init__(self) def setup(self, all_sprites): self.image = None self.zoomPoint = None self.preview = False self.timer = 0 # detect focus self.focus = ProcessFocus() self.focus.start() # stack images self.stack = ProcessStacking() self.stack.start() self.showStack = False # tracking images self.telescope = Telescope(self.config['telescope_dev']) self.tracker = ProcessTracking(self.telescope) self.tracker.start() self.tracking = False self.focusText = LcarsText((255,0,0), (17,303), "Focus: ") self.trackingText = LcarsText((255,0,0), (17,380), "Track: ") all_sprites.add(LcarsBackgroundImage("assets/jarvis.png")) all_sprites.add(self.focusText) all_sprites.add(self.trackingText) #all_sprites.add(LcarsGifImage("assets/jarvis_gadgets.gif", (83, 258))) # all_sprites.add(LcarsMoveToMouse(colours.BEIGE)) def setImage(self, image): # do background processing self.focus.addFrame(image) if self.tracking: self.tracker.addFrame(image) if self.showStack: self.stack.addFrame(image) if self.showStack and self.stack.outputFrame is not None: image = self.stack.getFrame() if self.tracking: image = self.tracker.getFrame() if (image == None): return self.image = pygame.image.frombuffer(image, (len(image[0]), len(image)), 'RGB').convert() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.timer > 100: self.focusText.setText("Focus: %d" % self.focus.focus) self.timer = pygame.time.get_ticks() self.trackingText.setText("Track: %s" % self.tracker.getStatus()) if (self.image != None): screenSurface.blit(self.image, # placement of preview window (100, 100), # area of image to display Rect(100, 100, self.image.get_width(), self.image.get_height())) def handleEvents(self, event, fpsClock): if (event.type == KEYUP and event.key == K_p): if (self.preview): self.cam.stopPreview() self.preview = False else: self.cam.startPreview() self.preview = True if (event.type == KEYUP and event.key == K_t): self.tracking = not self.tracking if not self.tracking: self.tracker.reset() if (event.type == KEYUP and event.key == K_s): #self.showStack = not self.showStack #self.stack.clear() self.telescope.down() if (event.type == KEYUP and event.key == K_w): self.telescope.up() if (event.type == KEYUP and event.key == K_a): self.telescope.left() if (event.type == KEYUP and event.key == K_d): self.telescope.right() if (event.type == KEYUP and event.key == K_1): self.telescope.setSteps("3") if (event.type == KEYUP and event.key == K_2): self.telescope.setSteps("4") if (event.type == KEYUP and event.key == K_3): self.telescope.setSteps("5") if (event.type == KEYUP and event.key == K_z): self.telescope.stop() if (event.type == KEYUP and event.key == K_x): self.telescope.start() return LcarsScreen.handleEvents(self, event, fpsClock) def timeStamped(self, fname, fmt='%Y-%m-%d-%H-%M-%S_{fname}'): return datetime.now().strftime(fmt).format(fname=fname)
class PiScopeProxy: def __init__(self): self.x_correction = 0 self.y_correction = 0 def setCorrection(self, x_correction, y_correction): self.x_correction = x_correction self.y_correction = y_correction cap = cv2.VideoCapture(p) ret, frame = cap.read() rows,cols = frame.shape[:2] piscope = PiScopeProxy() tracker = ProcessTracking(piscope) tracker.controllerX.SetKp(2.0) tracker.controllerX.SetKi(1.0) tracker.controllerY.SetKp(2.0) tracker.controllerY.SetKi(1.0) tracker.start() def now(): time.time() - time_origin def bump(x): if random.random()<x: return 1 else: