Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
sensors:kinect_library [2017/03/01 17:15] m16devan [Processing data] |
sensors:kinect_library [2019/04/25 14:08] (current) |
||
---|---|---|---|
Line 277: | Line 277: | ||
==== Processing data ==== | ==== Processing data ==== | ||
- | Here is some examples how to proceed data in order to display it using pygame. | + | Here is some examples how to proceed data in order to display it using pygame. Some packages must be first imported for this example |
+ | |||
+ | <code python> | ||
+ | import ctypes | ||
+ | import _ctypes | ||
+ | import pymedia.video.vcodec as vcodec | ||
+ | import pygame | ||
+ | from pygame.locals import * | ||
+ | import numpy as np | ||
+ | </code> | ||
=== Color data === | === Color data === | ||
Line 283: | Line 292: | ||
<code python> | <code python> | ||
pygame.init() | pygame.init() | ||
- | screen = pygame.display.set_mode((self._infoObject.current_w >> 1, self._infoObject.current_h >> 1), | + | infoObject = pygame.display.Info() |
+ | screen = pygame.display.set_mode((infoObject.current_w >> 1, infoObject.current_h >> 1), | ||
pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32) | pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE, 32) | ||
# back buffer surface for getting Kinect color frames, 32bit color, width and height equal to the Kinect color frame size | # back buffer surface for getting Kinect color frames, 32bit color, width and height equal to the Kinect color frame size | ||
- | frame_surface = pygame.Surface((self._kinect.color_frame_desc.Width, self._kinect.color_frame_desc.Height), 0, 32) | + | frame_surface = pygame.Surface((kinect.color_frame_desc.Width, kinect.color_frame_desc.Height), 0, 32) |
frame_surface.lock() | frame_surface.lock() | ||
Line 296: | Line 306: | ||
# --- copy back buffer surface pixels to the screen, resize it if needed and keep aspect ratio | # --- copy back buffer surface pixels to the screen, resize it if needed and keep aspect ratio | ||
# --- (screen size may be different from Kinect's color frame size) | # --- (screen size may be different from Kinect's color frame size) | ||
- | h_to_w = float(self._frame_surface.get_height()) / self._frame_surface.get_width() | + | h_to_w = float(frame_surface.get_height()) / frame_surface.get_width() |
- | target_height = int(h_to_w * self._screen.get_width()) | + | target_height = int(h_to_w * screen.get_width()) |
- | surface_to_draw = pygame.transform.scale(self._frame_surface, (self._screen.get_width(), target_height)); | + | surface_to_draw = pygame.transform.scale(frame_surface, (screen.get_width(), target_height)); |
- | self._screen.blit(surface_to_draw, (0,0)) | + | screen.blit(surface_to_draw, (0,0)) |
surface_to_draw = None | surface_to_draw = None | ||
pygame.display.update() | pygame.display.update() | ||
Line 417: | Line 427: | ||
</code> | </code> | ||
+ | ==== Closing the Kinect ==== | ||
+ | <code python> | ||
+ | kinect.close() | ||
+ | </code> |