From 29dfa14e4419fb6ceb9350223f410e967e8cc4f6 Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 1 Mar 2013 10:30:50 +0000 Subject: [PATCH 1/1] =?utf8?q?Refactoring=20orient=C3=A9=20objet.?= 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@415 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/kinect/pygamedisplay.py | 48 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/kinect/pygamedisplay.py b/src/kinect/pygamedisplay.py index 79eda18..82621ea 100755 --- a/src/kinect/pygamedisplay.py +++ b/src/kinect/pygamedisplay.py @@ -15,31 +15,36 @@ 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 +class RGB : + def __init__(self) : + self.context = Context() + self.context.init() + self.imgGene = ImageGenerator() + self.imgGene.create(self.context) + self.imgGene.set_resolution_preset(RES_VGA) + self.imgGene.fps = FPS + self.context.start_generating_all() + + def capture(self) : + rgb_frame = numpy.fromstring(self.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') -def main() : - # init openni - context = Context() - context.init() + return pyimage + + def update(self) : + return self.context.wait_one_update_all(self.imgGene) - #init pygame + + +def main() : 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() - + rgb = RGB() sur = pygame.Surface((640, 480)) sur.fill((255, 255, 255)) @@ -48,12 +53,13 @@ def main() : for event in pygame.event.get(): pass - context.wait_one_update_all(imgGene) - - rgbImg = capture_rgb(imgGene) + rgb.update() + + rgbImg = rgb.capture() sur.blit(rgbImg, (0, 0)) screen.blit(pygame.transform.flip(sur, True, False), (0, 0)) pygame.display.flip() + if __name__ == "__main__" : main() -- 2.20.1