-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodule1.py
More file actions
44 lines (31 loc) · 1.1 KB
/
module1.py
File metadata and controls
44 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import thread
import pygame
from pykinect import nui
DEPTH_WINSIZE = 320,240
screen_lock = thread.allocate()
screen = None
tmp_s = pygame.Surface(DEPTH_WINSIZE, 0, 16)
def depth_frame_ready(frame):
with screen_lock:
frame.image.copy_bits(tmp_s._pixels_address)
arr2d = (pygame.surfarray.pixels2d(tmp_s) >> 7) & 255
pygame.surfarray.blit_array(screen, arr2d)
pygame.display.update()
def main():
"""Initialize and run the game."""
pygame.init()
# Initialize PyGame
global screen
screen = pygame.display.set_mode(DEPTH_WINSIZE, 0, 8)
screen.set_palette(tuple([(i, i, i) for i in range(256)]))
pygame.display.set_caption('PyKinect Depth Map Example')
with nui.Runtime() as kinect:
kinect.depth_frame_ready += depth_frame_ready
kinect.depth_stream.open(nui.ImageStreamType.Depth, 2, nui.ImageResolution.Resolution320x240, nui.ImageType.Depth)
# Main game loop
while True:
event = pygame.event.wait()
if event.type == pygame.QUIT:
break
if __name__ == '__main__':
main()