demo_cv_threshold.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import freenect
3 import cv
4 import frame_convert
5 import numpy as np
6 
7 
8 threshold = 100
9 current_depth = 0
10 
11 
12 def change_threshold(value):
13  global threshold
14  threshold = value
15 
16 
17 def change_depth(value):
18  global current_depth
19  current_depth = value
20 
21 
22 def show_depth():
23  global threshold
24  global current_depth
25 
26  depth, timestamp = freenect.sync_get_depth()
27  depth = 255 * np.logical_and(depth >= current_depth - threshold,
28  depth <= current_depth + threshold)
29  depth = depth.astype(np.uint8)
30  image = cv.CreateImageHeader((depth.shape[1], depth.shape[0]),
31  cv.IPL_DEPTH_8U,
32  1)
33  cv.SetData(image, depth.tostring(),
34  depth.dtype.itemsize * depth.shape[1])
35  cv.ShowImage('Depth', image)
36 
37 
38 def show_video():
39  cv.ShowImage('Video', frame_convert.video_cv(freenect.sync_get_video()[0]))
40 
41 
42 cv.NamedWindow('Depth')
43 cv.NamedWindow('Video')
44 cv.CreateTrackbar('threshold', 'Depth', threshold, 500, change_threshold)
45 cv.CreateTrackbar('depth', 'Depth', current_depth, 2048, change_depth)
46 
47 print('Press ESC in window to stop')
48 
49 
50 while 1:
51  show_depth()
52  show_video()
53  if cv.WaitKey(10) == 27:
54  break
def video_cv(video)
def change_threshold(value)


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38