e5b1e59f83e495a4d056e51c65c4cacd9a8a7f46
[minwii.git] / src / kinect / pygamedisplay.py
1 # -*- coding: utf-8 -*-
2 """
3 Affichage vidéo (et autres) de la kinect pour expérimentations / debug.
4
5 $Id$
6 $URL$
7 """
8
9 from openni import *
10 import numpy
11 import cv
12 import pygame
13
14 SCREEN_SIZE = 640, 480
15 SCREEN_TITLE = "Kinect debug"
16 FPS = 30
17
18 def capture_rgb(imgGene):
19 rgb_frame = numpy.fromstring(imgGene.get_raw_image_map_bgr(), dtype=numpy.uint8).reshape(480, 640, 3)
20 image = cv.fromarray(rgb_frame)
21 cv.CvtColor(cv.fromarray(rgb_frame), image, cv.CV_BGR2RGB)
22 pyimage = pygame.image.frombuffer(image.tostring(), cv.GetSize(image), 'RGB')
23
24 return pyimage
25
26 def main() :
27 # init openni
28 context = Context()
29 context.init()
30
31 #init pygame
32 pygame.init()
33 screen = pygame.display.set_mode(SCREEN_SIZE)
34 pygame.display.set_caption(SCREEN_TITLE)
35
36 imgGene = ImageGenerator()
37 imgGene.create(context)
38 imgGene.set_resolution_preset(RES_VGA)
39 imgGene.fps = FPS
40
41 context.start_generating_all()
42
43
44 sur = pygame.Surface((640, 480))
45 sur.fill((255, 255, 255))
46
47 while True :
48 for event in pygame.event.get():
49 pass
50
51 context.wait_one_update_all(imgGene)
52
53 rgbImg = capture_rgb(imgGene)
54 sur.blit(rgbImg, (0, 0))
55 screen.blit(sur, (0, 0))
56 pygame.display.flip()
57
58 if __name__ == "__main__" :
59 main()