Skip to content

Commit

Permalink
python async example exits on esc and avoids GC
Browse files Browse the repository at this point in the history
python wrapper example demo_cv_async now avoids temporary
reallocations on video bgr reordering that provoqued GC stalls.

Also adds gracefull exit on ESC by using the Kill signal.

Signed-off-by: David García Garzón <[email protected]>
  • Loading branch information
David García Garzón authored and qdot committed Dec 28, 2010
1 parent 09a8141 commit 693e489
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions wrappers/python/demo_cv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
cv.NamedWindow('Depth')
cv.NamedWindow('RGB')

die = False

def display_depth(dev, data, timestamp):
data -= np.min(data.ravel())
data *= 65536 / np.max(data.ravel())
Expand All @@ -15,18 +17,32 @@ def display_depth(dev, data, timestamp):
cv.SetData(image, data.tostring(),
data.dtype.itemsize * data.shape[1])
cv.ShowImage('Depth', image)
cv.WaitKey(5)
global die
if cv.WaitKey(5) == 27 : die = True

rgb = None

lastVideo = None

def display_rgb(dev, data, timestamp):
global rgb
if rgb is None :
rgb = np.zeros(data.shape, np.uint8)
rgb[:] = data[:, :, ::-1]
image = cv.CreateImageHeader((data.shape[1], data.shape[0]),
cv.IPL_DEPTH_8U,
3)
# Note: We swap from RGB to BGR here
cv.SetData(image, data[:, :, ::-1].tostring(),
cv.SetData(image, rgb,
data.dtype.itemsize * 3 * data.shape[1])
cv.ShowImage('RGB', image)
cv.WaitKey(5)
global die
if cv.WaitKey(5) == 27 : die = True

def body(context, device) :
if die : raise freenect.Kill

freenect.runloop(depth=display_depth,
video=display_rgb)
video=display_rgb,
body=body)

0 comments on commit 693e489

Please sign in to comment.