Python Wrapper
Xvisio SDK 文档主页

PythonDemo.py文档


概述

PythonDemo.py文件包含Python接口的调用示例和数据解析示例。

1.0 文件目录

平台 目录
Windows 安装目录\bin\python-wrapper 默认C:\Program Files\xvsdk\bin\python-wrapper
Linux/Ubuntu 安装目录/share/python-wrapper, 默认/usr/share/python-wrapper

2.0 示例介绍

PythonDemo.py文件包含Python接口的调用示例和数据解析示例。详细内容如下:

引用相关库,包含xvsdk库:

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

初始化设备及启动相关功能:

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

获取设备SN号:

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

获取FE相机标定参数:

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

获取RGB相机标定参数:

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

获取TOF相机标定参数:

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

获取slam callback返回的slam数据,包含host及edge时间戳,6Dof数据,及转换后的orientation和quaternion数据:

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

获取getPose返回的slam数据,包含host及edge时间戳,6Dof数据,及转换后的orientation和quaternion数据,参数为预测值,单位为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")

获取IMU callback返回的IMU数据,包含host及edge时间戳,3dof数据(加速度及角速度):

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

获取FE callback返回的FE数据,包含host及edge时间戳,FE图像的宽,高,二进制数据及数据大小,及FE图像显示:

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)

获取RGB callback返回的RGB数据,包含host及edge时间戳,RGB图像的宽,高,二进制数据及数据大小,及RGB图像显示:

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)

获取TOF callback返回的TOF数据,包含host及edge时间戳,TOF图像的宽,高,二进制数据及数据大小:

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

获取FE Apriltag callback返回的Apriltag数据,包含host及edge时间戳,tag的6Dof数据,及转换后的orientation和quaternion数据:

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

获取基于fisheye Apriltag 返回的Apriltag数据,包含host及edge时间戳,tag的6Dof数据,及转换后的orientation和quaternion数据:

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

获取基于slam Apriltag 返回的Apriltag数据,包含host及edge时间戳,tag的6Dof数据,及转换后的orientation和quaternion数据:

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

获取相对于传感器当前位置的April-tag位置信息(tagFEPoses)及相对于April-tag的传感器当前位置信息(tagFETrans),包含host及edge时间戳,tag的6Dof数据,及转换后的orientation和quaternion数据:

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 文档主页

PythonDemo.py文档

概述