frame_convert.py
Go to the documentation of this file.
1 import numpy as np
2 
3 
4 def pretty_depth(depth):
5  """Converts depth into a 'nicer' format for display
6 
7  This is abstracted to allow for experimentation with normalization
8 
9  Args:
10  depth: A numpy array with 2 bytes per pixel
11 
12  Returns:
13  A numpy array that has been processed whos datatype is unspecified
14  """
15  np.clip(depth, 0, 2**10 - 1, depth)
16  depth >>= 2
17  depth = depth.astype(np.uint8)
18  return depth
19 
20 
21 def pretty_depth_cv(depth):
22  """Converts depth into a 'nicer' format for display
23 
24  This is abstracted to allow for experimentation with normalization
25 
26  Args:
27  depth: A numpy array with 2 bytes per pixel
28 
29  Returns:
30  An opencv image who's datatype is unspecified
31  """
32  import cv
33  depth = pretty_depth(depth)
34  image = cv.CreateImageHeader((depth.shape[1], depth.shape[0]),
35  cv.IPL_DEPTH_8U,
36  1)
37  cv.SetData(image, depth.tostring(),
38  depth.dtype.itemsize * depth.shape[1])
39  return image
40 
41 
42 def video_cv(video):
43  """Converts video into a BGR format for opencv
44 
45  This is abstracted out to allow for experimentation
46 
47  Args:
48  video: A numpy array with 1 byte per pixel, 3 channels RGB
49 
50  Returns:
51  An opencv image who's datatype is 1 byte, 3 channel BGR
52  """
53  import cv
54  video = video[:, :, ::-1] # RGB -> BGR
55  image = cv.CreateImageHeader((video.shape[1], video.shape[0]),
56  cv.IPL_DEPTH_8U,
57  3)
58  cv.SetData(image, video.tostring(),
59  video.dtype.itemsize * 3 * video.shape[1])
60  return image
def pretty_depth_cv(depth)
def video_cv(video)
def pretty_depth(depth)
Definition: frame_convert.py:4


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Mon Jun 10 2019 13:46:42