Zivid SDK 互操作性
To use Zivid SDK and Zivid Motion together in the same application, convert Zivid SDK point cloud coordinates from millimeters to meters before passing them to Zivid Motion.
In C++, also instantiate Application before Motion::Application.
These integration steps are manual for now; tighter interoperability between the two SDKs is planned for the future.
有关结合 Zivid Motion 和 Zivid SDK 的完整示例应用程序,请参阅 基于 Zivid 点云的障碍物 示例。
单位:毫米 VS 米
注意:
Zivid SDK 点云坐标的单位是毫米。
Zivid Motion 的几何形状和障碍物坐标以米为单位。
在利用 SDK 点云创建运动障碍物之前,务必将坐标从毫米转换为米。
const Zivid::Matrix4x4 millimetersToMetersTransform{ {
{ 0.001f, 0.f, 0.f, 0.f },
{ 0.f, 0.001f, 0.f, 0.f },
{ 0.f, 0.f, 0.001f, 0.f },
{ 0.f, 0.f, 0.f, 1.f },
} };
frame.pointCloud().transform(millimetersToMetersTransform);
millimeters_to_meters_transform = np.diag([0.001, 0.001, 0.001, 1])
frame.point_cloud().transform(millimeters_to_meters_transform)
C++ 集成细节
应用程序实例化顺序
在同一个 C++ 进程中使用 Zivid SDK 和 Zivid Motion 时,请先创建一个 Application,然后再创建一个 Motion::Application,以避免初始化错误。
请按以下顺序操作:
Zivid::Application zividApp;
Zivid::Motion::Application motionApp;
数据类型转换
SDK 和 Motion 类型是不同的 C++ 类型,即使它们表示相同的概念。
例如:
PointXYZ是 SDK 点类型。Zivid::Motion::Vector3f是 Motion 点类型。
从 SDK 点云数据创建运动障碍物时,需要显式转换:
// Ensure that the point cloud is in meters, not millimeters, before copying the XYZ data.
// Also, make sure to use an unorganized point cloud, as Motion always expects unorganized point clouds.
const auto xyzData = unorganizedPointCloud.copyPointsXYZ();
std::vector<Zivid::Motion::Vector3f> points;
points.reserve(xyzData.size());
for(const auto &p : xyzData)
{
points.emplace_back(Zivid::Motion::Vector3f{ p.x, p.y, p.z });
}
planner.setObstacles({ Zivid::Motion::Obstacle::fromPointCloud("point_cloud_obstacle", points) });
Python 集成详情
在 Python 中,互操作性更容易实现:
Zivid SDK 和 Zivid Motion 都能自然地与 NumPy 兼容的数据配合使用。
除了毫米到米的转换之外,不需要任何特殊的数据转换步骤。
zivid.Application()和zividmotion.Application()之间没有实例化顺序的限制。