def run(self): try: self.ctx = freenect.init() self.dev = freenect.open_device(self.ctx, 0) freenect.set_depth_mode(self.dev, freenect.RESOLUTION_MEDIUM, freenect.DEPTH_11BIT) freenect.set_depth_callback(self.dev, self._depth_cb) freenect.set_video_mode(self.dev, freenect.RESOLUTION_MEDIUM, freenect.VIDEO_RGB) freenect.set_video_callback(self.dev, self._video_cb) self.video_started = False self.depth_started = False while self.keep_running: with self.lock: if self.led_update is not None: freenect.set_led(self.dev, self.led_update) self.led_update = None self.update_streams() if not self.video_started and not self.depth_started: self.update_cond.wait() continue self.update.clear() if not self.keep_running: break freenect.base_runloop(self.ctx, self._body) finally: with self.lock: for k in self.depth_consumers.keys() + self.video_consumers.keys(): k.put(StreamerDied("The Kinect streamer died")) self.depth_consumers = {} self.video_consumers = {} self.update_streams() freenect.close_device(self.dev) freenect.shutdown(self.ctx)
def testkinect1(): # test video modes [ctx,dev] = initkinect() print(freenect.get_video_format(dev)) freenect.set_video_mode(dev,1,1) print(freenect.get_video_format(dev)) killkinect(ctx,dev) old_time = time.time() while time.time()-old_time < 10: cv.ShowImage('Video', get_video()) cv2.waitKey(1) cv2.destroyAllWindows() cv2.waitKey(1000) freenect.sync_stop() [ctx,dev] = initkinect() freenect.set_video_mode(dev,1,2) print(freenect.get_video_format(dev)) killkinect(ctx,dev) old_time = time.time() while time.time()-old_time < 10: cv.ShowImage('Video', get_video()) cv2.waitKey(1) cv2.destroyAllWindows() cv2.waitKey(1000) freenect.sync_stop() [ctx,dev] = initkinect() freenect.set_video_mode(dev,1,3) print(freenect.get_video_format(dev)) killkinect(ctx,dev) old_time = time.time() while time.time()-old_time < 10: cv.ShowImage('Video', get_video()) cv2.waitKey(1) cv2.destroyAllWindows() freenect.sync_stop() [ctx,dev] = initkinect() freenect.set_video_mode(dev,1,5) print(freenect.get_video_format(dev)) killkinect(ctx,dev) old_time = time.time() while time.time()-old_time < 10: cv.ShowImage('Video', get_video()) cv2.waitKey(1) cv2.destroyAllWindows() freenect.sync_stop() [ctx,dev] = initkinect() freenect.set_video_mode(dev,1,6) print(freenect.get_video_format(dev)) killkinect(ctx,dev) old_time = time.time() while time.time()-old_time < 10: cv.ShowImage('Video', get_video()) cv2.waitKey(1) cv2.destroyAllWindows() freenect.sync_stop()
def body_callback(self, dev, ctx): # _set_led hackery is required because for some reason calling set_led # from update loop hangs the process if self._set_led: freenect.set_led(dev, self._set_led) self._set_led = None if self._set_video is not None: freenect.stop_video(dev) freenect.set_video_mode(dev, freenect.RESOLUTION_MEDIUM, self._set_video) freenect.start_video(dev) self._set_video = None if self._last_setting_check + self.settings_delay < time.time(): self.load_settings() self._last_setting_check = time.time()
def __init__(self, dev, device_num, stream_type, streamer): self.dev = dev self.device_num = device_num self.stream_type = stream_type self.streamer = streamer self.consumers = set() # set([KinectConsumer]) self.lock = threading.Lock() self.frame = 0 # frame counter self.producing = False # true if freenect is sending us data assert stream_type in ('depth', 'video') if stream_type == 'depth': freenect.set_depth_mode(dev, freenect.RESOLUTION_MEDIUM, freenect.DEPTH_11BIT) freenect.set_depth_callback(dev, self._data_cb) elif stream_type == 'video': freenect.set_video_mode(dev, freenect.RESOLUTION_MEDIUM, freenect.VIDEO_RGB) freenect.set_video_callback(dev, self._data_cb)
def run(self): try: self.ctx = freenect.init() self.dev = freenect.open_device(self.ctx, 0) freenect.set_depth_mode(self.dev, freenect.RESOLUTION_MEDIUM, freenect.DEPTH_11BIT) freenect.set_depth_callback(self.dev, self._depth_cb) freenect.set_video_mode(self.dev, freenect.RESOLUTION_MEDIUM, freenect.VIDEO_RGB) freenect.set_video_callback(self.dev, self._video_cb) self.video_started = False self.depth_started = False while self.keep_running: with self.lock: if self.led_update is not None: freenect.set_led(self.dev, self.led_update) self.led_update = None self.update_streams() if not self.video_started and not self.depth_started: self.update_cond.wait() continue self.update.clear() if not self.keep_running: break freenect.base_runloop(self.ctx, self._body) finally: with self.lock: for k in self.depth_consumers.keys( ) + self.video_consumers.keys(): k.put(StreamerDied("The Kinect streamer died")) self.depth_consumers = {} self.video_consumers = {} self.update_streams() freenect.close_device(self.dev) freenect.shutdown(self.ctx)
def set_video_mode(self): if self.video_mode: self.log.debug('Setting video mode') fn.set_video_mode(self.device, self.video_mode.resolution, self.video_mode.fmt)