|
5 | 5 |
|
6 | 6 | cv.NamedWindow('Depth')
|
7 | 7 | cv.NamedWindow('RGB')
|
| 8 | +keep_running = True |
8 | 9 |
|
9 |
| -die = False |
10 | 10 |
|
11 | 11 | def display_depth(dev, data, timestamp):
|
12 |
| - data <<= (16-11) # 11 bits -> 16 bits |
| 12 | + global keep_running |
| 13 | + data = data.astype(np.uint8) |
13 | 14 | image = cv.CreateImageHeader((data.shape[1], data.shape[0]),
|
14 |
| - cv.IPL_DEPTH_16U, |
| 15 | + cv.IPL_DEPTH_8U, |
15 | 16 | 1)
|
16 | 17 | cv.SetData(image, data.tostring(),
|
17 | 18 | data.dtype.itemsize * data.shape[1])
|
18 | 19 | cv.ShowImage('Depth', image)
|
19 |
| - global die |
20 |
| - if cv.WaitKey(5) == 27 : die = True |
| 20 | + if cv.WaitKey(10) == 27: |
| 21 | + keep_running = False |
21 | 22 |
|
22 |
| -rgb = None |
23 | 23 |
|
24 | 24 | def display_rgb(dev, data, timestamp):
|
25 |
| - global rgb |
26 |
| - if rgb is None : |
27 |
| - rgb = np.zeros(data.shape, np.uint8) |
28 |
| - rgb[:] = data[:, :, ::-1] |
| 25 | + global keep_running |
29 | 26 | image = cv.CreateImageHeader((data.shape[1], data.shape[0]),
|
30 | 27 | cv.IPL_DEPTH_8U,
|
31 | 28 | 3)
|
32 | 29 | # Note: We swap from RGB to BGR here
|
33 |
| - cv.SetData(image, rgb, |
| 30 | + cv.SetData(image, data[:, :, ::-1].tostring(), |
34 | 31 | data.dtype.itemsize * 3 * data.shape[1])
|
35 | 32 | cv.ShowImage('RGB', image)
|
36 |
| - global die |
37 |
| - if cv.WaitKey(5) == 27 : die = True |
| 33 | + if cv.WaitKey(10) == 27: |
| 34 | + keep_running = False |
38 | 35 |
|
39 |
| -def body(context, device) : |
40 |
| - if die : raise freenect.Kill |
41 | 36 |
|
| 37 | +def body(*args): |
| 38 | + if not keep_running: |
| 39 | + raise freenect.Kill |
| 40 | +print('Press ESC in window to stop') |
42 | 41 | freenect.runloop(depth=display_depth,
|
43 | 42 | video=display_rgb,
|
44 | 43 | body=body)
|
45 |
| - |
0 commit comments