From 7f861db051bcbbaed3f47e3a90e60a3b9781f5e4 Mon Sep 17 00:00:00 2001 From: pin Date: Thu, 28 Feb 2013 12:12:44 +0000 Subject: [PATCH 1/1] =?utf8?q?D=C3=A9but=20d'int=C3=A9gration=20de=20la=20?= =?utf8?q?Kinect.=20Ajout=20d'un=20script=20qui=20affiche=20la=20vid=C3=A9?= =?utf8?q?o=20dans=20une=20fen=C3=AAtre=20pygame.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@412 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/kinect/__init__.py | 0 src/kinect/pygamedisplay.py | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 src/kinect/__init__.py create mode 100755 src/kinect/pygamedisplay.py diff --git a/src/kinect/__init__.py b/src/kinect/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/src/kinect/pygamedisplay.py b/src/kinect/pygamedisplay.py new file mode 100755 index 0000000..6a4f834 --- /dev/null +++ b/src/kinect/pygamedisplay.py @@ -0,0 +1,60 @@ +# -*- 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() -- 2.20.1