+# -*- coding: utf-8 -*-
+"""
+Affichage vidéo (et autres) de la kinect pour expérimentations / debug.
+
+$Id$
+$URL$
+"""
+
+from openni import *
+import numpy
+import cv
+import pygame
+
+SCREEN_SIZE = 640, 480
+SCREEN_TITLE = "Kinect debug"
+FPS = 30
+
+def capture_rgb(imgGene):
+ rgb_frame = numpy.fromstring(imgGene.get_raw_image_map_bgr(), dtype=numpy.uint8).reshape(480, 640, 3)
+ image = cv.fromarray(rgb_frame)
+ cv.CvtColor(cv.fromarray(rgb_frame), image, cv.CV_BGR2RGB)
+ pyimage = pygame.image.frombuffer(image.tostring(), cv.GetSize(image), 'RGB')
+
+ return pyimage
+
+def main() :
+ # init openni
+ context = Context()
+ context.init()
+
+ #init pygame
+ pygame.init()
+ screen = pygame.display.set_mode(SCREEN_SIZE)
+ pygame.display.set_caption(SCREEN_TITLE)
+
+ imgGene = ImageGenerator()
+ imgGene.create(context)
+ imgGene.set_resolution_preset(RES_VGA)
+ imgGene.fps = FPS
+
+ context.start_generating_all()
+
+
+ sur = pygame.Surface((640, 480))
+ sur.fill((255, 255, 255))
+
+ while True :
+ for event in pygame.event.get():
+ pass
+
+ context.wait_one_update_all(imgGene)
+ cv.WaitKey(10)
+
+ rgbImg = capture_rgb(imgGene)
+ sur.blit(rgbImg, (0, 0))
+ screen.blit(sur, (0, 0))
+ pygame.display.flip()
+
+if __name__ == "__main__" :
+ main()