-
Notifications
You must be signed in to change notification settings - Fork 7
/
kinect_video.py
37 lines (32 loc) · 1.1 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
from freenect import sync_get_depth as get_depth, sync_get_video as get_video
import cv2
import numpy as np
import glob
import sys
def doloop():
global depth, rgb
path = "./kpictures/"
num = glob.glob(str(path) + "*.avi")
i = len(num)
video = cv2.VideoWriter(path+'video'+str(i)+'.avi',cv2.cv.CV_FOURCC('D','I','V','X'),20,(1280,480))
if not video.isOpened():
print 'error with video opening'
sys.exit(1)
print 'press "q" to exit'
while True:
# Get a fresh frame
(depth, _), (rgb, _) = get_depth(), get_video()
# Build a two panel color image
d3 = np.dstack((depth, depth, depth)).astype(np.uint8, copy=False)
bgr = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
da = np.hstack((d3, bgr)).astype(np.uint8, copy=False)
# src = cv2.cv.fromarray(da)
cv2.imshow('both', da)
video.write(da)
k = cv2.waitKey(5)
if (k > -1) and (k < 256):
if chr(k)=='q':
# video.release()
cv2.destroyAllWindows()
sys.exit(0)
doloop()