From 18944a0196254fc2c01f416e4f39b8511ee6eb19 Mon Sep 17 00:00:00 2001 From: pin Date: Wed, 24 Apr 2013 20:52:00 +0000 Subject: [PATCH] =?utf8?q?Utilisation=20de=20la=20kinect=20sur=20une=20pla?= =?utf8?q?ge=20de=20distance=20plus=20r=C3=A9duite.?= 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@422 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/kinect/pygamedisplay.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/kinect/pygamedisplay.py b/src/kinect/pygamedisplay.py index 17ab173..321578d 100755 --- a/src/kinect/pygamedisplay.py +++ b/src/kinect/pygamedisplay.py @@ -14,9 +14,13 @@ import pygame SCREEN_SIZE = 640, 480 SCREEN_TITLE = "Kinect debug" FPS = 30 +MOUSE_SCREEN_COORDINATES = 0 +MOUSE_REAL_COORDINATES = 1 +DEFAULT_HAND_DISTANCE_RANGE = 150 # distance de débatement, autour du centre, en mm class RGB : - def __init__(self) : + def __init__(self, mouseMode=MOUSE_REAL_COORDINATES) : + self.mouseMode = mouseMode self.context = Context() self.context.init() self.imgGene = ImageGenerator() @@ -48,16 +52,28 @@ class RGB : screen = pygame.display.get_surface() self.xratio = float(screen.get_size()[0]) / SCREEN_SIZE[0] self.yratio = float(screen.get_size()[1]) / SCREEN_SIZE[1] + self.handCenteredPosition = None + self.pygameScreenWidth, self.pygameScreenHeight = screen.get_size() def getProjPos(self, realPos) : return self.depthGene.to_projective([realPos])[0] def setMousePosition(self, realPos) : - x, y, z = self.getProjPos(realPos) - # mirror - x = SCREEN_SIZE[0] - x - # scale - x, y = x * self.xratio, y * self.yratio + if self.mouseMode == MOUSE_SCREEN_COORDINATES : + x, y, z = self.getProjPos(realPos) + # mirror + x = SCREEN_SIZE[0] - x + # scale + x, y = x * self.xratio, y * self.yratio + elif self.mouseMode == MOUSE_REAL_COORDINATES : + x, y = realPos[:2] + x, y = x - self.handCenteredPosition[0], y - self.handCenteredPosition[1] + x = -x # miroir + x, y = x + DEFAULT_HAND_DISTANCE_RANGE, DEFAULT_HAND_DISTANCE_RANGE - y + x, y = map(lambda i : numpy.clip(i, 0, DEFAULT_HAND_DISTANCE_RANGE * 2), [x, y]) + x = x * (self.pygameScreenWidth / (2. * DEFAULT_HAND_DISTANCE_RANGE)) + y = y * (self.pygameScreenHeight / (2. * DEFAULT_HAND_DISTANCE_RANGE)) + print x, y pygame.mouse.set_pos(int(x), int(y)) def handCreateCB(self, src, id, pos, time): @@ -76,6 +92,7 @@ class RGB : print 'gestureProgress', src, gesture, point, progress self.handsGene.start_generating() self.handsGene.start_tracking(point) + self.handCenteredPosition = point def newUserCB(self, *args, **kw) : print 'newUserCB', args, kw -- 2.20.1