Python Wrapper
Xvisio SDK Documentation Home Page

PythonDemo.py


Overview

PythonDemo.py contains Python interface call demo and data analysis demo.

1.0 File Catalogue

Platform Catalogue
Windows Installation path: \bin\python-wrapper, default path:\Program Files\xvsdk\bin\python-wrapper
Linux/Ubuntu Installation path: /share/python-wrapper, default path:/usr/share/python-wrapper

2.0 Demo Introduction

PythonDemo.py contains Python interface call demo and data analysis demo.Please refer to the details as below:

Call related libraries which including xvsdk library:

from ctypes import *
import datetime
import xvsdk
import numpy as np
import cv2

Init deVice and start related functions:

xvsdk.init()
xvsdk.slam_start()
xvsdk.stereo_start()
xvsdk.imu_start()
xvsdk.rgb_start()
xvsdk.april_tag_start(b"36h11", c_double(0.0639), c_double(50.))

Get device SN:

sn = xvsdk.xvisio_get_sn()
print("device sn = ", sn.value.decode('utf8'), "\n")

Get FE camera calibration parameter:

fe_trans_size, fe_ucm_size, fe_transform, fe_ucm = xvsdk.xvisio_get_fisheye_intrinsics()
for transform in fe_transform:
print("fe R:[", transform.rotation[0], ",", transform.rotation[1], ",", transform.rotation[2], ",", transform.rotation[3], ",", transform.rotation[4], ",", transform.rotation[5], ",", transform.rotation[6], ",", transform.rotation[7], ",", transform.rotation[8], "]\n")
print("fe T:[", transform.translation[0], ",", transform.translation[1], ",", transform.translation[2], "]\n")
for ucm in fe_ucm:
print("fe UCM: { w=", ucm.w, ", h=", ucm.h, ", fx=", ucm.fx, ", fy=", ucm.fy, ", u0=", ucm.u0, ", v0=", ucm.v0, ", xi=", ucm.xi, "}\n")

Get RGB camera calibration parameter:

rgb_trans_size, rgb_pdcm_size, rgb_transform, rgb_pdcm = xvsdk.xvisio_get_rgb_intrinsics()
for transform in rgb_transform:
print("rgb R:[", transform.rotation[0], ",", transform.rotation[1], ",", transform.rotation[2], ",", transform.rotation[3], ",", transform.rotation[4], ",", transform.rotation[5], ",", transform.rotation[6], ",", transform.rotation[7], ",", transform.rotation[8], "]\n")
print("rgb T:[", transform.translation[0], ",", transform.translation[1], ",", transform.translation[2], "]\n")
for pdcm in rgb_pdcm:
print("rgb pdcm: { w=", pdcm.w, ", h=", pdcm.h, ", fx=", pdcm.fx, ", fy=", pdcm.fy, ", u0=", pdcm.u0, ", v0=", pdcm.v0, ", distor[0]=", pdcm.distor[0], ", distor[1]=", pdcm.distor[1], ", distor[2]=", pdcm.distor[2], ", distor[3]=", pdcm.distor[3], ", distor[4]=", pdcm.distor[4], "}\n")

Get TOF camera calibration parameter:

tof_trans_size, tof_pdcm_size, tof_transform, tof_pdcm = xvsdk.xvisio_get_tof_intrinsics()
for transform in tof_transform:
print("tof R:[", transform.rotation[0], ",", transform.rotation[1], ",", transform.rotation[2], ",", transform.rotation[3], ",", transform.rotation[4], ",", transform.rotation[5], ",", transform.rotation[6], ",", transform.rotation[7], ",", transform.rotation[8], "]\n")
print("tof T:[", transform.translation[0], ",", transform.translation[1], ",", transform.translation[2], "]\n")
for pdcm in tof_pdcm:
print("tof pdcm: { w=", pdcm.w, ", h=", pdcm.h, ", fx=", pdcm.fx, ", fy=", pdcm.fy, ", u0=", pdcm.u0, ", v0=", pdcm.v0, ", distor[0]=", pdcm.distor[0], ", distor[1]=", pdcm.distor[1], ", distor[2]=", pdcm.distor[2], ", distor[3]=", pdcm.distor[3], ", distor[4]=", pdcm.distor[4], "}\n")

Get slam data returned by "slam callback" which also contains host&edge timestamp, 6Dof data and converted orientation/quaternion data:

position, orientation, quaternion, slam_edgeTimestamp, slam_hostTimestamp, slam_confidence = xvsdk.xvisio_get_6dof()
print("6dof: position x =", position.x , ", y = ", position.y, ", z = ", position.z, ", pitch =", orientation.x * 180 / 3.14 , ", yaw = ", orientation.y * 180 / 3.14, ", roll = ", orientation.z * 180 / 3.14, ", quaternion[0] = ", quaternion.q0, ", quaternion[1] = ", quaternion.q1, ", quaternion[2] = ", quaternion.q2, ", quaternion[3] = ", quaternion.q3, ", edgeTimestamp = ", slam_edgeTimestamp.value, ", hostTimestamp = ", slam_hostTimestamp.value, ", confidence = ", slam_confidence.value, "\n")

Get slam data returned by "getPose" which also contains host&edge timestamp, 6Dof data and converted orientation/quaternion data (predictive value with a unit of "s"):

position, orientation, quaternion, slam_edgeTimestamp, slam_hostTimestamp, slam_confidence = xvsdk.xvisio_get_6dof_prediction(c_double(0.005))
print("6dof with prediction: position x =", position.x , ", y = ", position.y, ", z = ", position.z, ", pitch =", orientation.x * 180 / 3.14 , ", yaw = ", orientation.y * 180 / 3.14, ", roll = ", orientation.z * 180 / 3.14, ", quaternion[0] = ", quaternion.q0, ", quaternion[1] = ", quaternion.q1, ", quaternion[2] = ", quaternion.q2, ", quaternion[3] = ", quaternion.q3, ", edgeTimestamp = ", slam_edgeTimestamp.value, ", hostTimestamp = ", slam_hostTimestamp.value, ", confidence = ", slam_confidence.value, "\n")

Get IMU data returned by "IMU callback" which also contains host&edge timestamp, 3dof data (acceleration and angular velocity):

accel, gyro, imu_edgeTimestamp, imu_hostTimestamp = xvsdk.xslam_get_imu()
print("imu: accel x =", accel.x , ", y = ", accel.y, ", z = ", accel.z, ", gyro x =", gyro.x , ", y = ", gyro.y, ", z = ", gyro.z, ", edgeTimestamp = ", imu_edgeTimestamp.value, ", hostTimestamp = ", imu_hostTimestamp.value, "\n")

Get FE data returned by "FE callback" which also contains host&edge timestamp, width&height of FE image, binary data and data size, and FE iamge display.

fe_width, fe_height, stereo_edgeTimestamp, stereo_hostTimestamp, fe_left_data, fe_right_data, fe_dataSize = xvsdk.xvisio_get_stereo()
print("fisheye left: width = ", fe_width.value, ", height = ", fe_height.value, ", edgeTimestamp = ", stereo_edgeTimestamp.value, ", hostTimestamp = ", stereo_hostTimestamp.value, ", datasize = ", fe_dataSize.value, "\n")
if fe_dataSize.value > 0 :
left_image = np.asfortranarray(fe_left_data)
left_image = left_image[:fe_width.valuefe_height.value]
left_image = left_image.reshape(fe_height.value, fe_width.value)
left_image = cv2.cvtColor(left_image, cv2.COLOR_GRAY2BGR)
cv2.imshow('left', left_image)
cv2.waitKey(1)
right_image = np.asfortranarray(fe_right_data)
right_image = right_image[:fe_width.value
fe_height.value]
right_image = right_image.reshape(fe_height.value, fe_width.value)
right_image = cv2.cvtColor(right_image, cv2.COLOR_GRAY2BGR)
cv2.imshow('right', right_image)
cv2.waitKey(1)

Get RGB data returned by "RGB callback" which also contains host&edge timestamp, width&height of RGB image, binary data and data size, and RGB iamge display.

rgb_width, rgb_height, rgb_edgeTimestamp, rgb_hostTimestamp, rgb_data, rgb_dataSize = xvsdk.xvisio_get_rgb()
print("rgb: width = ", rgb_width.value, ", height = ", rgb_height.value, ", edgeTimestamp = ", rgb_edgeTimestamp.value, ", hostTimestamp = ", rgb_hostTimestamp.value, ", datasize = ", rgb_dataSize.value, "\n")
if rgb_dataSize.value > 0 :
color_image = np.asfortranarray(rgb_data)
nheight = int(rgb_height.value3/2)
color_image = color_image[:rgb_width.value
nheight]
color_image = color_image.reshape(nheight, rgb_width.value)
color_image = cv2.cvtColor(color_image, cv2.COLOR_YUV2BGR_IYUV)
cv2.imshow('rgb', color_image)
cv2.waitKey(1)

Get TOF data returned by "TOF callback" which also contains host&edge timestamp, width&height of TOF image, binary data and data size:

tof_width, tof_height, tof_edgeTimestamp, tof_hostTimestamp, tof_data, tof_dataSize = xvsdk.xvisio_get_tof()
print("tof: width = ", tof_width.value, ", height = ", tof_height.value, ", edgeTimestamp = ", tof_edgeTimestamp.value, ", hostTimestamp = ", tof_hostTimestamp.value, ", datasize = ", tof_dataSize.value, "\n")

Get Apriltag data returned by "FE Apriltag callback" which also contains host&edge timestamp, 6Dof data of tag , and converted orientation/quaternion data:

tags = xvsdk.xvisio_get_fe_april_tags()
for tag in tags:
print("Tag: tagid = ", tag.tagID, ", position x =", tag.position[0] , ", y = ", tag.position[1], ", z = ", tag.position[2], ", pitch =", tag.orientation[0] * 180 / 3.14 , ", yaw = ", tag.orientation[1] * 180 / 3.14, ", roll = ", tag.orientation[2] * 180 / 3.14, ", quaternion[0] = ", tag.quaternion[0], ", quaternion[1] = ", tag.quaternion[1], ", quaternion[2] = ", tag.quaternion[2], ", quaternion[3] = ", tag.quaternion[3], ", edgeTimestamp = ", tag.edgeTimestamp, ", hostTimestamp = ", tag.hostTimestamp, ", confidence = ", tag.confidence, "\n")
print("start xvisio_get_fe_april_tags_withslam")

Get Apriltag data returned by "fisheye Apriltag" which also contains host&edge timestamp, 6Dof data of tag , and converted orientation/quaternion data:

tags = xvsdk.xvisio_get_fe_april_tags()
for tag in tags:
print("Tag: tagid = ", tag.tagID, ", position x =", tag.position[0] , ", y = ", tag.position[1], ", z = ", tag.position[2], ", pitch =", tag.orientation[0] * 180 / 3.14 , ", yaw = ", tag.orientation[1] * 180 / 3.14, ", roll = ", tag.orientation[2] * 180 / 3.14, ", quaternion[0] = ", tag.quaternion[0], ", quaternion[1] = ", tag.quaternion[1], ", quaternion[2] = ", tag.quaternion[2], ", quaternion[3] = ", tag.quaternion[3], ", edgeTimestamp = ", tag.edgeTimestamp, ", hostTimestamp = ", tag.hostTimestamp, ", confidence = ", tag.confidence, "\n")
print("start xvisio_get_fe_april_tags_withslam")

Get Apriltag data returned by "slam Apriltag" which also contains host&edge timestamp, 6Dof data of tag , and converted orientation/quaternion data:

tagSlamPoses = xvsdk.xvisio_get_fe_april_tags_withslam(b"36h11", c_double(0.0639))
for tagPos in tagSlamPoses:
print("TagPose with slam: tagid = ", tagPos.tagID, ", position x =", tagPos.position[0] , ", y = ", tagPos.position[1], ", z = ", tagPos.position[2], ", pitch =", tagPos.orientation[0] * 180 / 3.14 , ", yaw = ", tagPos.orientation[1] * 180 / 3.14, ", roll = ", tagPos.orientation[2] * 180 / 3.14, ", quaternion[0] = ", tagPos.quaternion[0], ", quaternion[1] = ", tagPos.quaternion[1], ", quaternion[2] = ", tagPos.quaternion[2], ", quaternion[3] = ", tagPos.quaternion[3], ", edgeTimestamp = ", tagPos.edgeTimestamp, ", hostTimestamp = ", tagPos.hostTimestamp, ", confidence = ", tagPos.confidence, "\n")

Get April-tag pose (tagFEPoses) that relative to the current position of the sensor returned by "fisheye Apriltag" , and the current pose that relative to April-tag sensor, which also contains host&edge timestamp, 6Dof data of tag , and converted orientation/quaternion data:

tagFEPoses, tagFETrans = xvsdk.xvisio_get_fe_april_tags_withFE(b"36h11", c_double(0.0639))
for tagPos in tagFEPoses:
print("TagPose with FE: tagid = ", tagPos.tagID, ", position x =", tagPos.position[0] , ", y = ", tagPos.position[1], ", z = ", tagPos.position[2], ", pitch =", tagPos.orientation[0] * 180 / 3.14 , ", yaw = ", tagPos.orientation[1] * 180 / 3.14, ", roll = ", tagPos.orientation[2] * 180 / 3.14, ", quaternion[0] = ", tagPos.quaternion[0], ", quaternion[1] = ", tagPos.quaternion[1], ", quaternion[2] = ", tagPos.quaternion[2], ", quaternion[3] = ", tagPos.quaternion[3], ", edgeTimestamp = ", tagPos.edgeTimestamp, ", hostTimestamp = ", tagPos.hostTimestamp, ", confidence = ", tagPos.confidence, "\n")
for tagTrans in tagFETrans:
print("TagPose by transformed: tagid = ", tagTrans.tagID, ", position x =", tagTrans.position[0] , ", y = ", tagTrans.position[1], ", z = ", tagTrans.position[2], ", pitch =", tagTrans.orientation[0] * 180 / 3.14 , ", yaw = ", tagTrans.orientation[1] * 180 / 3.14, ", roll = ", tagTrans.orientation[2] * 180 / 3.14, ", quaternion[0] = ", tagTrans.quaternion[0], ", quaternion[1] = ", tagTrans.quaternion[1], ", quaternion[2] = ", tagTrans.quaternion[2], ", quaternion[3] = ", tagTrans.quaternion[3], "\n")

Python Wrapper
Xvisio SDK Documentation Home Page

PythonDemo.py

Overview