2D 图像捕获流程

2D 捕获 API 会在采集完成后返回。

跳转到源码

source

const auto frame2D = camera.capture2D(settings);
跳转到源码

源码

using (var frame2D = camera.Capture2D(settings))
跳转到源码

源码

frame_2d = camera.capture_2d(settings)

从 Frame2D 对象获取图像的方法会在 2D 图像在 CPU 内存中可用后返回。此函数调用会造成阻塞,直到处理和复制过程完成。图像对象持有 CPU 内存中图像数据的句柄。

小技巧

使用 推荐的硬件 来最小化 2D 图像处理时间。

跳转到源码

source

const auto imageSRGB = frame2D.imageRGBA_SRGB();
跳转到源码

源码

var imageSRGB = frame2D.ImageRGBA_SRGB();
跳转到源码

源码

image_srgb = frame_2d.image_rgba_srgb()

可以获取不同色彩空间的图像,例如 linear(线性) RGB( BGRA 和 RGBA )和 sRGB( SRGB )。更多相关信息,请参阅 2D 色彩空间、镜头畸变和输出格式 。

备注

在 C++ 和 C# 中,类 Image 继承自 Array2D ,此外还提供了一种以 PNG 文件格式保存图像的方法。

当图像在 CPU 内存中可用时,我们可以在机器视觉应用程序中使用它或将其保存到磁盘。

跳转到源码

source

const auto imageFile = "ImageRGBA_sRGB.png";
std::cout << "Saving 2D color image (sRGB color space) to file: " << imageFile << std::endl;
imageSRGB.save(imageFile);
跳转到源码

源码

var imageFile = "ImageRGBA_sRGB.png";
Console.WriteLine($"Saving 2D color image (sRGB color space) to file: {imageFile}");
imageSRGB.Save(imageFile);
跳转到源码

源码

image_file = "ImageRGBA_sRGB.png"
print(f"Saving 2D color image (sRGB color space) to file: {image_file}")
image_srgb.save(image_file)

小技巧

为了优化时间,请在 2D 捕获 API 返回后移动机器人或移动场景中的对象。这必须在调用 API 从 Frame2D 对象获取图像之前或同时发生。

2D 帧可以保存到 .zdf 文件中,并在之后重新加载到内存中。这在启用 诊断(Diagnostics) 时尤为有用,可将原始帧数据分享给 Zivid 支持团队以进行更全面的故障排查。

跳转到源码

source

const auto dataFile2D = "Frame2D.zdf";
std::cout << "Saving 2D frame to file: " << dataFile2D << std::endl;
frame2D.save(dataFile2D);
跳转到源码

源码

var dataFile2D = "Frame2D.zdf";
Console.WriteLine("Saving 2D frame to file: " + dataFile2D);
frame2D.Save(dataFile2D);
跳转到源码

源码

data_file_2d = "Frame2D.zdf"
print(f"Saving 2D frame to file: {data_file_2d}")
frame_2d.save(data_file_2d)

保存的文件可以使用带有文件路径参数的 Frame2D 构造函数加载。

跳转到源码

source

std::cout << "Loading 2D frame from file: " << dataFile2D << std::endl;
const auto loadedFrame2D = Zivid::Frame2D{ dataFile2D };
跳转到源码

源码

Console.WriteLine("Loading 2D frame from file: " + dataFile2D);
using (var loadedFrame2D = new Zivid.NET.Frame2D(dataFile2D))
跳转到源码

源码

print(f"Loading 2D frame from file: {data_file_2d}")
loaded_frame_2d = zivid.Frame2D(data_file_2d)

readFrameFileType returns whether a .zdf file contains a 3D Frame or a Frame2D. This is useful when a file path is given as input and the type is not known in advance.

跳转到源码

源码

const auto frameFileType2D = Zivid::readFrameFileType(dataFile2D);
std::cout << "Frame file type: " << (frameFileType2D == Zivid::FrameFileType::frame2D ? "Frame2D" : "Frame")
          << std::endl;
跳转到源码

源码

var frameFileType2D = Zivid.NET.FrameFile.ReadFrameFileType(dataFile2D);
Console.WriteLine("Frame file type: " + frameFileType2D);
跳转到源码

源码

frame_file_type_2d = zivid.read_frame_file_type(data_file_2d)
print(f"Frame file type: {frame_file_type_2d}")

版本历史

SDK

变更

2.18.0

Added support for saving and loading Frame2D to and from .zdf files, and readFrameFileType to identify the frame type in a file.

2.12.0

Zivid 2+ 上的 2D 采集时间减少了高达 50%。

2.11.0

添加了对 SRGB 色彩空间的支持。

2.9.0

捕获(Capture)功能在采集完成后返回,提高了捕获速度。

2.8.0

提高了 Zivid 2 的捕获速度。