How to save Point Cloud in ZED-ArUco sample

Hi,

I’m going to use ZED-ArUco to estimate the depth in a multi-camera environment.
I estimated the camera location using ArUco markers and checked the resulting point cloud.

I have some questions regarding ZED ArUco as below.

Q1. Is there a way to increase the accuracy of multiple ZED camera calibration?
I used two ArUco markers as the default setting, but the calibration accuracy is too low.

Q2. Is there a way to save a calibrated point cloud (like a PLY file)?
You want to check the code and save the point cloud. As a result of referring to the API document, the GPU memory type could not be saved, so we copied to the CPU memory type MAT. However, attempting to save results in a Segmentation fault.

Here’s my save code. The function below is set to be called when there is a keystroke.

void PointCloud::save() {
    std::cout << "SAVE Start" << std::endl;

    sl::Mat matCPU_;
    matCPU_.alloc(512, 288, sl::MAT_TYPE::F32_C4, sl::MEM::CPU);
    matCPU_.setFrom(matGPU_, sl::COPY_TYPE::GPU_CPU);

    std::cout << "[DEBUG] matCPU_ is (" << matCPU_.getWidth()
              << " x " << matCPU_.getHeight() << ")" 
              << matCPU_.getChannels()
              << matCPU_.getDataType() << ", " << matCPU_.getMemoryType() << std::endl;

    sl::ERROR_CODE err = matCPU_.write('point_cloud.ply');
    std::cout << "MAT write return: " << err << std::endl;

    std::cout << "SAVE Done" << std::endl;
}
$ ./ZED_Multi_Reloc_Aruco 
Make sure the ArUco marker is a 6x6 (100), measuring 160 mm
Opening [0] ZED 2i SNXXXXXXX
Opening [1] ZED 2i SNXXXXXXX

key s pressed!
SAVE Start
[DEBUG] matCPU_ is (512 x 288)432F C4, CPU
Segmentation fault (core dumped)

How can I save it?

Best Regards,
Lee.

Hi

You can simplify the code, either you copy the GPU memory portion into the CPU one from the same sl::Mat, it will automatically allocates the memory:

matGPU_.updateCPUfromGPU();
matGPU_.write("point_cloud.ply");

Or even simpler, directly write the point cloud from GPU, it should also work;

matGPU_.write("point_cloud.ply", sl::MEM::GPU);

If it doesn’t work, we’ll investigate a possible bug.

For the precision, generally speaking, having bigger aruco markers tends to help get better accuracy, the placement should also have an impact, trying to get them well spread while all visible. You can also increase the number to reduce incertainty.

1 Like