def do_dream(): colour_sensed = Color20(b,PORT_3).get_color() print "LEGO Colour: "+colours[colour_sensed] im = get_image() dream = get_dream(im, colour_sensed) assert 0 <= dream < len(pbm_images) print "writing image %s to peggy" % pbm_images[dream] write_frame(pbm_lines(IMG_DIR + pbm_images[dream])) im.save('dream' + time.strftime('%H%M%S') + '.jpg', 'JPEG') print "saving photo" highgui.cvReleaseCapture(camera)#reset camera global camera camera = highgui.cvCreateCameraCapture(1) time.sleep(DISPLAY_TIME) write_frame()
time.sleep(1) def write_frame(lines=None): if not lines: lines = BLANK_FRAME ser.write(START_FRAME) for line in lines: ser.write(line) ser.write(END_LINE) def write_random(): write_lines(["".join([chr(randint(0, 255)) for x in range(4)]) for y in range(25)]) if __name__ == "__main__": try: while True: img_dir = "../images/" for dirname, dirnames, filenames in os.walk(img_dir): shuffle(filenames) if not filenames[0].startswith("."): write_frame(pbm_lines(img_dir + filenames[0])) time.sleep(2) except Exception, e: print e finally: ser.close()
def fresh_frame(self, lines=None): self._frame(lines, self.FRESH_FRAME) def subtractive_frame(self, lines=None): self._frame(lines, self.SUBTRACTIVE_FRAME) def additive_frame(self, lines=None): self._frame(lines, self.ADDITIVE_FRAME) def random_frame(self): frame = [''.join([chr(random.randint(0,255)) for x in range(self.WIDTH_IN_BYTES)]) for y in range(self.HEIGHT_IN_PIX)] self.fresh_frame(frame) if __name__ == '__main__': peggy = FrameDisplayPeggy() try: while(True): img_dir = '../images/' for dirname, dirnames, filenames in os.walk(img_dir): random.shuffle(filenames) if not filenames[0].startswith('.'): peggy.frame(pbm_lines(img_dir + filenames[0])) time.sleep(2) except Exception, e: print e finally: peggy.done()