-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess.py
More file actions
84 lines (66 loc) · 2.03 KB
/
process.py
File metadata and controls
84 lines (66 loc) · 2.03 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
import sys, cv2, freenect
from functools import partial
from danutil import *
KEY_UP = 63232
KEY_DN = 63233
do_depth_edge = True
do_rgb_edge = False
do_blur = True
print "Reloaded!"
rgb_image = None
def print_trackbar(value):
print "%s" % value
cv2.createTrackbar('clipNear', 'Depth', 0, 2**10-1, print_trackbar)
cv2.createTrackbar('clipFar', 'Depth', 2**10-1, 2**10-1, print_trackbar)
#min:11, max:26
cv2.createTrackbar('minVal', 'Depth', 0, 255, print_trackbar)
cv2.createTrackbar('maxVal', 'Depth', 0, 255, print_trackbar)
cv2.createTrackbar('minVal', 'RGB', 0, 255, print_trackbar)
cv2.createTrackbar('maxVal', 'RGB', 0, 255, print_trackbar)
def clip(d):
mindepth = cv2.getTrackbarPos('clipNear', 'Depth')
maxdepth = cv2.getTrackbarPos('clipFar', 'Depth')
d[np.where(d <= mindepth)] = 0
d[np.where(d >= maxdepth)] = 0
#np.clip(d, cv2.getTrackbarPos('clipMin', 'Depth'),
#cv2.getTrackbarPos('clipMax', 'Depth'), d)
d >>= 2
d = d.astype(np.uint8)
return d
def rgb_func(d):
global rgb_image
rgb_image = d
if do_blur:
d = cv2.GaussianBlur(d, (5,5), 0)
if do_rgb_edge:
d = cv2.Canny(d, cv2.getTrackbarPos('minVal', 'RGB'),
cv2.getTrackbarPos('maxVal', 'RGB'))
return d
def depth_func(d, k):
global do_depth_edge, do_rgb_edge, do_blur
#sys.stdout.write('[%s]' % k)
#sys.stdout.flush()
if k == ord('e'):
print "swap do_depth_edge"
do_depth_edge = not do_depth_edge
elif k == ord('f'):
print "swap do_rgb_edge"
do_rgb_edge = not do_rgb_edge
elif k == ord('p'):
pickle({'rgb': rgb_image, 'depth': d}, '/tmp/kinect.pickle')
print "pickled to /tmp/kinect.pickle"
elif k == ord('b'):
do_blur = not do_blur
elif k != '':
print "key: %s" % k
d = clip(d)
if do_blur:
d = cv2.GaussianBlur(d, (5,5), 0)
#d = np.clip(d, 130, 140, d)
if do_depth_edge:
e = cv2.Canny(d, cv2.getTrackbarPos('minVal', 'Depth'),
cv2.getTrackbarPos('maxVal', 'Depth'))
return e
return where(e == 0, [d, e])
return d