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()

Changelog

  • 1.70.0:
    • Recommend to upgrade device firmware to 1.70 to this SDK
    • API change
      • Remove deprecated dmcam_cmap_float
      • change dmcam_param_roi_t structure
      • remove filter id DMCAM_FILTER_ID_BINNING
    • New: support dual-freq of SONY IMX556
    • New: support binning mode
      • EPC driver: 2x2, 4x4 and 2x4
      • IMX driver: 2x2, 4x4, and 8x8
    • New: ethernet based Tof camera support
    • Enhance: Use parameter set/get API with parameter id PARAM_ROI to set ROI and Binning instead of using filter interface.
    • Enhance: better support replay in HDR /Dual-freq/Binning mode
    • FIX:
      • C sample compiling issue
      • wrong frame info when seeking frames of oni file
      • First frame checksum error sometimes
  • 1.68.2:
    • Fix: Correct to set gray/ir value to be zero when overexposure.
    • New: add DMCAM_FILTER_ID_BINNING to support pix binning
    • Enhance: better support ROI.
  • 1.68.1:
    • Enhance: Optimize TC-E2 accuracy and error correction of calibration data.
    • New: add parameter id PARAM_INFO_LENS for user to get lens parameter through dmcam_param_batch_get
  • 1.68.0:
    • Enhance:
      • replay supports gray frames related with ambient compensation from FW 164
      • replay support switching between HDR to normal mode.
      • dmcam_dev_get_uri returns URI with token for eth devices
      • Enhance performance of dmcam_frame_get_pcl_xyzd and dmcam_frame_get_pcl_xyzi
    • New:
      • add dmcam_frame_get_pcl_xyzi api to get point clouds with gray as texture
      • add dmcam_cap_seek_frame api to seek frames when device is replay-file
      • add dmcam_frame_get_dist_raw for user to get raw distance without calibration
      • For sony sensors:
        • add compression support for SONY sensor
        • Filter chain optimized
        • Calibration method refined.
    • Fix:
      • lens paramter file not closed after open
      • recorded replay file without timestamp
      • device cannot close properly sometimes (FW ver= 164/165)
  • 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.

Files for dmcam, version 1.70.1
Filename, size & hash File type Python version Upload date
dmcam-1.70.1-cp27-cp27m-win32.whl (1.0 MB) View hashes Wheel cp27
dmcam-1.70.1-cp34-cp34m-win32.whl (1.0 MB) View hashes Wheel cp34
dmcam-1.70.1-cp35-cp35m-win32.whl (1.0 MB) View hashes Wheel cp35
dmcam-1.70.1-cp36-cp36m-win32.whl (1.0 MB) View hashes Wheel cp36
dmcam-1.70.1-cp37-cp37m-win32.whl (1.0 MB) View hashes Wheel cp37

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page