Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import freenect
  3. import cv
  4. import numpy as np
  5.  
  6. cv.NamedWindow('Depth')
  7. cv.NamedWindow('Video')
  8. print('Press ESC in window to stop')
  9.  
  10.  
  11. def pretty_depth(depth):
  12. np.clip(depth, 0, 2**10 - 1, depth)
  13. depth >>= 2
  14. return depth.astype(np.uint8)
  15.  
  16.  
  17. def get_depth():
  18. data, _ = freenect.sync_get_depth()
  19. data = pretty_depth(data)
  20. image = cv.CreateImageHeader((data.shape[1], data.shape[0]),
  21. cv.IPL_DEPTH_8U,
  22. 1)
  23. cv.SetData(image, data.tostring(),
  24. data.dtype.itemsize * data.shape[1])
  25. return image
  26.  
  27.  
  28. def get_video():
  29. data, _ = freenect.sync_get_video()
  30. data = data[:, :, ::-1].astype(np.uint8) # RGB -> BGR
  31. image = cv.CreateImageHeader((data.shape[1], data.shape[0]),
  32. cv.IPL_DEPTH_8U,
  33. 3)
  34. cv.SetData(image, data.tostring(),
  35. data.dtype.itemsize * 3 * data.shape[1])
  36. return image
  37.  
  38.  
  39. while 1:
  40. cv.ShowImage('Depth', get_depth())
  41. cv.ShowImage('Video', get_video())
  42. if cv.WaitKey(10) == 27:
  43. break
Add Comment
Please, Sign In to add comment