File: demo_cv_thresh_sweep.py

package info (click to toggle)
libfreenect 1%3A0.1.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,700 kB
  • sloc: ansic: 6,092; cs: 2,060; cpp: 1,896; python: 948; ruby: 873; java: 722; xml: 40; makefile: 28; sh: 27
file content (32 lines) | stat: -rwxr-xr-x 842 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env python
"""Sweeps throught the depth image showing 100 range at a time"""
import freenect
import cv
import numpy as np
import time

cv.NamedWindow('Depth')


def disp_thresh(lower, upper):
    depth, timestamp = freenect.sync_get_depth()
    depth = 255 * np.logical_and(depth > lower, depth < upper)
    depth = depth.astype(np.uint8)
    image = cv.CreateImageHeader((depth.shape[1], depth.shape[0]),
                                 cv.IPL_DEPTH_8U,
                                 1)
    cv.SetData(image, depth.tostring(),
               depth.dtype.itemsize * depth.shape[1])
    cv.ShowImage('Depth', image)
    cv.WaitKey(10)


lower = 0
upper = 100
max_upper = 2048
while upper < max_upper:
    print('%d < depth < %d' % (lower, upper))
    disp_thresh(lower, upper)
    time.sleep(.1)
    lower += 20
    upper += 20