-
Notifications
You must be signed in to change notification settings - Fork 2
/
kinect_video.py
73 lines (57 loc) · 1.99 KB
/
kinect_video.py
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
#!/usr/bin/env python
import freenect
import cv2
import frame_convert
import time
# import vision_processing
import numpy
lookup_table_depth = []
# cv.NamedWindow('Depth')
cv2.namedWindow('Video')
cv2.namedWindow('Thresholded')
print('Press ESC in window to stop')
def depth_in_meters_at_pixel(x, y, depth_data):
if depth_data:
pixel_to_look_at = depth_data[x][y]
return lookup_table_depth[int(pixel_to_look_at)]
else:
return
def get_depth():
depth_data = freenect.sync_get_depth()[0]
print(depth_in_meters_at_pixel(320, 240, depth_data))
print(lookup_table_depth[int(pixel_to_look_at)])
return frame_convert.pretty_depth_cv(depth_data)
def get_video():
video_data = freenect.sync_get_video()
return video_data[1], frame_convert.video_cv(video_data[0])
def generate_lookup_table():
for i in range(2048):
lookup_table_depth.append(1/(i * -0.0030711016 + 3.3309495161))
generate_lookup_table()
while 1:
# cv.ShowImage('Depth', get_depth())
# print(freenect.get_depth_format(freenect.DevPtr._ptr))
ret, video_frame = get_video()
# print type(video_frame)
video_frame = numpy.asarray(video_frame[:,:]) # access as mat
# print video_frame.shape
if video_frame.size <= 10:
continue
# print type(video_frame)
# thresholded_image = vision_processing.threshold_image_for_tape(video_frame)
cv2.imshow('Video', video_frame)
char = cv2.waitKey(10)
if char == 115:
cv2.imwrite("img/vision_testing_" + str(int(time.time()/10)) + ".png", video_frame)
elif char == 27:
break
# cv2.imshow('Thresholded', thresholded_image)
# save = raw_input("Save?")
# if save.upper() == "EXIT":
# break;
# if "V" in save.upper():
# cv2.imwrite("img/video_" + str(int(time.time()/100)) + ".png",
# video_frame)
# if "T" in save.upper():
# cv2.imwrite("img/thresholded_" + str(int(time.time()/100)) + ".png",
# thresholded_image)