forked from OpenKinect/libfreenect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up the demos to reflect decisions made from the forum/irc dis…
…cussions. 1. Abstracted the frame conversion code to frame_convert.py. This will prevent the massive changes that we have been seeing as all of the duplicative code is in there now. This makes optimization and normalization experiments cleaner to test out. 2. Removed demo_ipython and demo_kill_async as they are mostly duplicates of the other demos 3. Made the "multi" demo default to using all kinects at once instead of one at a time 4. Change the default normalization to make better use of the 8 bit range. Signed-off-by: Brandyn A. White <[email protected]>
Showing
10 changed files
with
136 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
#!/usr/bin/env python | ||
import freenect | ||
import cv | ||
import numpy as np | ||
import frame_convert | ||
|
||
cv.NamedWindow('Depth') | ||
cv.NamedWindow('Video') | ||
print('Press ESC in window to stop') | ||
|
||
|
||
def get_depth(): | ||
return frame_convert.pretty_depth_cv(freenect.sync_get_depth()[0]) | ||
|
||
|
||
def get_video(): | ||
return frame_convert.video_cv(freenect.sync_get_video()[0]) | ||
|
||
|
||
while 1: | ||
depth, timestamp = freenect.sync_get_depth() | ||
rgb, timestamp = freenect.sync_get_video() | ||
cv.ShowImage('Depth', depth.astype(np.uint8)) | ||
cv.ShowImage('Video', rgb[:, :, ::-1].astype(np.uint8)) | ||
cv.ShowImage('Depth', get_depth()) | ||
cv.ShowImage('Video', get_video()) | ||
if cv.WaitKey(10) == 27: | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
#!/usr/bin/env python | ||
"""This goes through each kinect on your system, grabs one frame and | ||
displays it. Uncomment the commented line to shut down after each frame | ||
if your system can't handle it (will get very low FPS but it should work). | ||
This will keep trying indeces until it finds one that doesn't work, then it | ||
starts from 0. | ||
""" | ||
import freenect | ||
import cv | ||
import numpy as np | ||
import frame_convert | ||
|
||
cv.NamedWindow('Depth') | ||
cv.NamedWindow('Video') | ||
ind = 0 | ||
print('Press ESC to stop') | ||
print('%s\nPress ESC to stop' % __doc__) | ||
|
||
|
||
def get_depth(ind): | ||
return frame_convert.pretty_depth_cv(freenect.sync_get_depth(ind)[0]) | ||
|
||
|
||
def get_video(ind): | ||
return frame_convert.video_cv(freenect.sync_get_video(ind)[0]) | ||
|
||
|
||
while 1: | ||
print(ind) | ||
try: | ||
depth, timestamp = freenect.sync_get_depth(ind) | ||
rgb, timestamp = freenect.sync_get_video(ind) | ||
depth = get_depth(ind) | ||
video = get_video(ind) | ||
except TypeError: | ||
ind = 0 | ||
continue | ||
ind += 1 | ||
cv.ShowImage('Depth', depth.astype(np.uint8)) | ||
cv.ShowImage('Video', rgb[:, :, ::-1].astype(np.uint8)) | ||
cv.ShowImage('Depth', depth) | ||
cv.ShowImage('Video', video) | ||
if cv.WaitKey(10) == 27: | ||
break | ||
freenect.sync_stop() # NOTE: May remove if you have good USB bandwidth | ||
#freenect.sync_stop() # NOTE: Uncomment if your machine can't handle it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
#!/usr/bin/env python | ||
import freenect | ||
import matplotlib.pyplot as mp | ||
import numpy as np | ||
import frame_convert | ||
import signal | ||
|
||
keep_running = True | ||
mp.ion() | ||
mp.figure(1) | ||
mp.gray() | ||
image_depth = mp.imshow(freenect.sync_get_depth()[0].astype(np.uint8), | ||
interpolation='nearest', animated=True) | ||
mp.figure(2) | ||
image_rgb = mp.imshow(freenect.sync_get_video()[0], | ||
interpolation='nearest', animated=True) | ||
|
||
|
||
def get_depth(): | ||
return frame_convert.pretty_depth(freenect.sync_get_depth()[0]) | ||
|
||
|
||
def get_video(): | ||
return freenect.sync_get_video()[0] | ||
|
||
|
||
def handler(signum, frame): | ||
"""Sets up the kill handler, catches SIGINT""" | ||
global keep_running | ||
keep_running = False | ||
|
||
|
||
mp.ion() | ||
mp.gray() | ||
mp.figure(1) | ||
image_depth = mp.imshow(get_depth(), interpolation='nearest', animated=True) | ||
mp.figure(2) | ||
image_rgb = mp.imshow(get_video(), interpolation='nearest', animated=True) | ||
print('Press Ctrl-C in terminal to stop') | ||
signal.signal(signal.SIGINT, handler) | ||
|
||
while keep_running: | ||
mp.figure(1) | ||
image_depth.set_data(freenect.sync_get_depth()[0].astype(np.uint8)) | ||
image_depth.set_data(get_depth()) | ||
mp.figure(2) | ||
image_rgb.set_data(freenect.sync_get_video()[0]) | ||
image_rgb.set_data(get_video()) | ||
mp.draw() | ||
mp.waitforbuttonpress(0.01) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import cv | ||
import numpy as np | ||
|
||
|
||
def pretty_depth(depth): | ||
"""Converts depth into a 'nicer' format for display | ||
This is abstracted to allow for experimentation with normalization | ||
Args: | ||
depth: A numpy array with 2 bytes per pixel | ||
Returns: | ||
A numpy array that has been processed whos datatype is unspecified | ||
""" | ||
np.clip(depth, 0, 2**10 - 1, depth) | ||
depth >>= 2 | ||
depth = depth.astype(np.uint8) | ||
return depth | ||
|
||
|
||
def pretty_depth_cv(depth): | ||
"""Converts depth into a 'nicer' format for display | ||
This is abstracted to allow for experimentation with normalization | ||
Args: | ||
depth: A numpy array with 2 bytes per pixel | ||
Returns: | ||
An opencv image who's datatype is unspecified | ||
""" | ||
depth = pretty_depth(depth) | ||
image = cv.CreateImageHeader((depth.shape[1], depth.shape[0]), | ||
cv.IPL_DEPTH_8U, | ||
1) | ||
cv.SetData(image, depth.tostring(), | ||
depth.dtype.itemsize * depth.shape[1]) | ||
return image | ||
|
||
|
||
def video_cv(video): | ||
"""Converts video into a BGR format for opencv | ||
This is abstracted out to allow for experimentation | ||
Args: | ||
video: A numpy array with 1 byte per pixel, 3 channels RGB | ||
Returns: | ||
An opencv image who's datatype is 1 byte, 3 channel BGR | ||
""" | ||
video = video[:, :, ::-1] # RGB -> BGR | ||
image = cv.CreateImageHeader((video.shape[1], video.shape[0]), | ||
cv.IPL_DEPTH_8U, | ||
3) | ||
cv.SetData(image, video.tostring(), | ||
video.dtype.itemsize * 3 * video.shape[1]) | ||
return image |