Skip to main content

DM camera python extension

Project description

Introduction

The dmcam Python extension is part of SmartToF SDK, it's developed for python programmers to interacting with SmartToF Module.

Quick example

import sys, os
import numpy as np
import time

import dmcam

# --  init the lib with default log file
dmcam.init(None)
# --  init with specified log file
# dmcam.init("test.log")

# -- set debug level
dmcam.log_cfg(dmcam.LOG_LEVEL_INFO, dmcam.LOG_LEVEL_DEBUG, dmcam.LOG_LEVEL_NONE)

# -- list device
print(" Scanning dmcam device ..")
devs = dmcam.dev_list()
if devs is None:
    print(" No device found")
    sys.exit(1)

print("found %d device" % len(devs))

for i in range(len(devs)):
    print("#%d: %s" % (i, dmcam.dev_get_uri(devs[i], 256)[0]))

print(" Open dmcam device ..")
# open the first device
dev = dmcam.dev_open(devs[0])
# Or open by URI
# dev = dmcam.dev_open_by_uri("xxxx")
assert dev is not None

# - set capture config  -
cap_cfg = dmcam.cap_cfg_t()
cap_cfg.cache_frames_cnt = 10  # framebuffer = 10
cap_cfg.on_error = None        # use cap_set_callback_on_error to set cb
cap_cfg.on_frame_rdy = None    # use cap_set_callback_on_frame_ready to set cb
cap_cfg.en_save_replay = True  # True = save replay, False = not save
cap_cfg.en_save_dist_u16 = False # True to save dist stream for openni replay
cap_cfg.en_save_gray_u16 = False # True to save gray stream for openni replay
cap_cfg.fname_replay = os.fsencode("dm_replay.oni")  # set replay filename

dmcam.cap_config_set(dev, cap_cfg)
# dmcam.cap_set_callback_on_frame_ready(dev, on_frame_rdy)
# dmcam.cap_set_callback_on_error(dev, on_cap_err)

print(" Set paramters ...")
wparams = {
    dmcam.PARAM_INTG_TIME: dmcam.param_val_u(),
    dmcam.PARAM_FRAME_RATE: dmcam.param_val_u(),
}
wparams[dmcam.PARAM_INTG_TIME].intg.intg_us = 1000
wparams[dmcam.PARAM_FRAME_RATE].frame_rate.fps = 20

if not dmcam.param_batch_set(dev, wparams):
    print(" set parameter failed")

print(" Start capture ...")
dmcam.cap_start(dev)

f = bytearray(320 * 240 * 4 * 2)
print(" sampling 100 frames ...")
count = 0
run = True
while run:
    # get one frame
    finfo = dmcam.frame_t()
    ret = dmcam.cap_get_frames(dev, 1, f, finfo)
    # print("get %d frames" % ret)
    if ret > 0:
        w = finfo.frame_info.width
        h = finfo.frame_info.height

        print(" frame @ %d, %d, %dx%d" %
              (finfo.frame_info.frame_idx, finfo.frame_info.frame_size, w, h))

        dist_cnt, dist = dmcam.frame_get_distance(dev, w * h, f, finfo.frame_info)
        gray_cnt, gray = dmcam.frame_get_gray(dev, w * h, f, finfo.frame_info)
        # dist = dmcam.raw2dist(int(len(f) / 4), f)
        # gray = dmcam.raw2gray(int(len(f) / 4), f)

        count += 1
        if count >= 100:
            break

    else:
        break
    time.sleep(0.01)
    # break

print(" Stop capture ...")
dmcam.cap_stop(dev)

print(" Close dmcam device ..")
dmcam.dev_close(dev)

dmcam.uninit()

Changlog

  • 1.62.2:
    • FIX: the problem that replay file size > 2GB may not work properly under windows
    • Enhance: some kind of error tolerance on playing corrupted replay file.
    • Enhance: add en_fdev_rewind in dmcam_cap_cfg_t to allow rewind replay when use dmcam replay file as device.
  • 1.62.1:
    • Enhance: during file replay mode, if fps is set to 0, frame capture is only ongoing after invoking dmcam_get_frames/dmcam_get_frame . This is usefully to pause & resume the replay at application level
  • 1.62.0:
    • Fix: replay problem when switch from QVGA to VGA
    • Fix: replay file cannot played in Niviewer of OpenNI
    • Enhance: optimize env-light compensation
  • 1.61.6:
    • Enhance: optimize DIST&GRAY calc performance further (boost about 50%). TC-E3 can reach up-to 115fps @ Cortex-A7 1Ghz
    • FIX: TC-E3 replay problem
    • FIX: wrong return value of dmcam_cap_get_frames when the host process is slow.
    • New: support SONY sensors
    • New: support env-light compensation
  • 1.61.2:
    • Enhance : optimize DIST&GRAY calc performance (boost about 40%)
    • FIX: dmcam_frame_get_pcl_xyzd and dmcam_frame_get_pcl_xyz now return number of points (x,y,z) / (x,y,z,d) equal to the number of pixels of the depth image. Invalid point in the cloud is denoted as (0,0,0) and (0,0,0,0) respectively.
  • 1.61.1: Fix a possible problem cause memory exhaustion.
  • 1.61.0: Fix: unicode problem, all python API should use 'bytes' instead of 'str' to invoke C API in type of 'char*'
  • 1.60.0: Major release
    • Support save replay and play replay.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

dmcam-1.62.2-cp37-cp37m-win_amd64.whl (822.6 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

dmcam-1.62.2-cp37-cp37m-win32.whl (814.6 kB view hashes)

Uploaded CPython 3.7m Windows x86

dmcam-1.62.2-cp37-cp37m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m

dmcam-1.62.2-cp37-cp37m-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 3.7m

dmcam-1.62.2-cp36-cp36m-win_amd64.whl (822.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

dmcam-1.62.2-cp36-cp36m-win32.whl (814.5 kB view hashes)

Uploaded CPython 3.6m Windows x86

dmcam-1.62.2-cp36-cp36m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m

dmcam-1.62.2-cp36-cp36m-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 3.6m

dmcam-1.62.2-cp35-cp35m-win_amd64.whl (822.5 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

dmcam-1.62.2-cp35-cp35m-win32.whl (814.6 kB view hashes)

Uploaded CPython 3.5m Windows x86

dmcam-1.62.2-cp35-cp35m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.5m

dmcam-1.62.2-cp35-cp35m-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 3.5m

dmcam-1.62.2-cp34-cp34m-win_amd64.whl (818.2 kB view hashes)

Uploaded CPython 3.4m Windows x86-64

dmcam-1.62.2-cp34-cp34m-win32.whl (813.2 kB view hashes)

Uploaded CPython 3.4m Windows x86

dmcam-1.62.2-cp34-cp34m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.4m

dmcam-1.62.2-cp34-cp34m-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 3.4m

dmcam-1.62.2-cp27-cp27mu-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 2.7mu

dmcam-1.62.2-cp27-cp27mu-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 2.7mu

dmcam-1.62.2-cp27-cp27m-win_amd64.whl (818.6 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

dmcam-1.62.2-cp27-cp27m-win32.whl (813.0 kB view hashes)

Uploaded CPython 2.7m Windows x86

dmcam-1.62.2-cp27-cp27m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 2.7m

dmcam-1.62.2-cp27-cp27m-manylinux1_i686.whl (1.0 MB view hashes)

Uploaded CPython 2.7m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page