# Multi camera spatial mapping

**URL:** <https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015>\
**Category:** C++\
**Tags:** multi-camera\
**Created:** [November 20, 2023, 12:22pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015 "2023-11-20T12:22:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@davide](https://community.stereolabs.com/u/davide)\
**Post date:** [November 20, 2023, 12:22pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/1 "2023-11-20T12:22:19Z")

</div>

Hi,

I am trying to use 2 zed2i camera to reconstruct scene with these 2 camera. I have found multi camera spatial mapping support in zed-sdk sample. Even though there is no instructuion how to use this app, I used zed360 tool to get camera json. I rigidly assemble 2 camera on 2 different head of long stick. I supposed that after 6-7 iteration of calibration process on zed360 it is enough to provide calibration file after that I supplied this file to multi-reconst app but this is not work as mono spatial mapping. It is completly dark. Can you check on this link.

> <https://github.com/stereolabs/zed-sdk/issues/597>
>
> \### Preliminary Checks
> 
> \- \[X\] This issue is not a duplicate. Before opening a …new issue, please search existing issues.
> \- \[X\] This issue is not a question, feature request, or anything other than a bug report directly related to this project.
> 
> \### Description
> 
> Spatial mapping works well, but when attempting to use two Zed cameras together, it only shows a black reconstructed point cloud. I have obtained the calibration .json files from Zed360. I also have a question: If I rigidly mount these two cameras on a stick and obtain the correct calibration matrix from Zed360, can I move the stick and still achieve accurate results with spatial mapping?
> 
> \### Steps to Reproduce
> 
> 1. cd /usr/local/zed/samples/spatial mapping/multi camera/cpp/ && mkdir build && cd build && cmake .. && make 
> 2. ./ZED\_SpatialMappingFusion zed\_calibration\_360.json
> 
> 
> \### Expected Result
> 
> I expect colored mesh and nice reconstructed point cloud.
> 
> \### Actual Result
> 
> !\[Screenshot from 2023-11-07 21-00-04\](https://github.com/stereolabs/zed-sdk/assets/33879396/801916d5-1a19-4bdd-b51b-29ea73e6c840)
> 
> 
> \### ZED Camera model
> 
> ZED2i
> 
> \### Environment
> 
> \`\`\`shell
> OS: Ubuntu 20.04
> CPU x64
> GPU Nvidia Jetson Nx
> Zed SDK 4.0
> \`\`\`
> 
> 
> \### Anything else?
> 
> \_No response\_

So my question is:

What kind of things should i aware of to get nice and colored point cloud. ( lighning is enough if it is not enough then it could not get enough feature )  
Mono camera works great.  
There is a multi camera recording sample but is it enough to record sync svo to supply the output for multi spatial mapping app ?

Thank You

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [November 20, 2023, 5:33pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/2 "2023-11-20T17:33:05Z")

</div>

Hi @davide,

For now, it’s not possible to save the textures when using the spatial mapping fusion, it’s only possible in mono-camera. Thanks for the feedback, it’s something we want to do but it probably won’t be short-term.

On the other side, yeah you can use the multi-recording sample to record SVO, but you will also need the ZED360 configuration file for the camera to run the spatial mapping fusion sample with the SVOs.

Explanations on how to modify the ZED360 configuration file for SVO can be found in this post : [Fusion Sample Code with SVO Files - #2 by JPlou](https://community.stereolabs.com/t/fusion-sample-code-with-svo-files/2391/2)

---

<div class="post-metadata">

**Author:** ![davide](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@davide](https://community.stereolabs.com/u/davide)\
**Post date:** [November 20, 2023, 7:13pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/3 "2023-11-20T19:13:38Z")

</div>

Hi @JPlou ,

Thank you for your answer. I wonder that is it possible to run mono spatial mapping for dedicated camera respectively their serial number. If the calibration is correct and getting 2 seperate mono spatial mapping output I can use ICP or other aligning algorithm to make align those 2 mapped mesh.

Do you have any other suggestion ? If I decide to modify the multi camera spatial mapping is it technically possible to make meshed one ?

it seems that a user have done with it

> <https://github.com/stereolabs/zed-sdk/issues/477#issuecomment-1103027971>
>
> \### Preliminary Checks
> 
> \- \[X\] This issue is not a duplicate. Before opening a …new issue, please search existing issues.
> \- \[X\] This issue is not a question, feature request, or anything other than a bug report directly related to this project.
> 
> \### Description
> 
> I have two ZED2i cameras and I try to use them together (in a rigid body) in a real time mapping process.
> 
> \### Steps to Reproduce
> 
> I updated the realtime mapping sample to handle two cameras : 
> 
> \`\`\`
> c
> /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> \*\* This sample demonstrates how to capture a live 3D reconstruction of a scene \*\*
> \*\* as a fused point cloud and display the result in an OpenGL window. \*\*
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
> 
> // ZED includes
> \#include \<sl/Camera.hpp\>
> 
> // Sample includes
> \#include "GLViewer.hpp"
> 
> \#include \<opencv2/opencv.hpp\>
> 
> // Using std and sl namespaces
> using namespace std;
> using namespace sl;
> 
> int main(int argc, char \*\*argv) {
> Camera zed1;
> Camera zed2;
> 
> // Set configuration parameters for the ZED
> InitParameters init\_parameters;
> init\_parameters.depth\_mode = DEPTH\_MODE::ULTRA;    
> init\_parameters.coordinate\_system = COORDINATE\_SYSTEM::RIGHT\_HANDED\_Y\_UP; // OpenGL's coordinate system is right\_handed    
> 
> // Open the camera
> init\_parameters.input.setFromCameraID(0);
> zed1.open(init\_parameters);
> 
> init\_parameters.input.setFromCameraID(1);
> zed2.open(init\_parameters);
> 
> auto camera\_infos = zed1.getCameraInformation();
> 
> // Point cloud viewer
> GLViewer viewer;
> 
> // Initialize point cloud viewer
> FusedPointCloud map;
> GLenum errgl = viewer.init(argc, argv, camera\_infos.camera\_configuration.calibration\_parameters.left\_cam, &map, camera\_infos.camera\_model);
> 
> // Setup and start positional tracking
> Pose pose;
> POSITIONAL\_TRACKING\_STATE tracking\_state = POSITIONAL\_TRACKING\_STATE::OFF;
> PositionalTrackingParameters positional\_tracking\_parameters;
> positional\_tracking\_parameters.enable\_area\_memory = false;
> zed1.enablePositionalTracking(positional\_tracking\_parameters);
> zed2.enablePositionalTracking(positional\_tracking\_parameters);
> 
> 
> // Set spatial mapping parameters
> SpatialMappingParameters spatial\_mapping\_parameters;
> // Request a Point Cloud
> spatial\_mapping\_parameters.map\_type = SpatialMappingParameters::SPATIAL\_MAP\_TYPE::FUSED\_POINT\_CLOUD;
> // Set mapping range, it will set the resolution accordingly (a higher range, a lower resolution)
> spatial\_mapping\_parameters.set(SpatialMappingParameters::MAPPING\_RANGE::SHORT);
> spatial\_mapping\_parameters.set(SpatialMappingParameters::MAPPING\_RESOLUTION::HIGH);
> // Request partial updates only (only the latest updated chunks need to be re-draw)
> spatial\_mapping\_parameters.use\_chunk\_only = true;
> // Start the spatial mapping
> zed1.enableSpatialMapping(spatial\_mapping\_parameters);
> zed2.enableSpatialMapping(spatial\_mapping\_parameters);
>     
> // Timestamp of the last fused point cloud requested
> chrono::high\_resolution\_clock::time\_point ts\_last1;
> chrono::high\_resolution\_clock::time\_point ts\_last2;
> 
> // Setup runtime parameters
> RuntimeParameters runtime\_parameters;
> // Use low depth confidence avoid introducing noise in the constructed model
> runtime\_parameters.confidence\_threshold = 50;
> 
> auto resolution = camera\_infos.camera\_configuration.resolution;
> 
> // Define display resolution and check that it fit at least the image resolution
> Resolution display\_resolution(min((int)resolution.width, 720), min((int)resolution.height, 404));
> 
> // Create a Mat to contain the left image and its opencv ref
> Mat image\_zed1(display\_resolution, MAT\_TYPE::U8\_C4);
> Mat image\_zed2(display\_resolution, MAT\_TYPE::U8\_C4);
> cv::Mat image\_zed\_ocv1(image\_zed1.getHeight(), image\_zed1.getWidth(), CV\_8UC4, image\_zed1.getPtr\<sl::uchar1\>(MEM::CPU));
> cv::Mat image\_zed\_ocv2(image\_zed2.getHeight(), image\_zed2.getWidth(), CV\_8UC4, image\_zed2.getPtr\<sl::uchar1\>(MEM::CPU));
> 
> // Start the main loop
> while (viewer.isAvailable()) {
> // Grab a new image
> if (zed1.grab(runtime\_parameters) == ERROR\_CODE::SUCCESS) {
> // Retrieve the left image
> zed1.retrieveImage(image\_zed1, VIEW::LEFT, MEM::CPU, display\_resolution);
> // Retrieve the camera pose data
> tracking\_state = zed1.getPosition(pose);
> viewer.updatePose(pose, tracking\_state);
> 
> if (tracking\_state == POSITIONAL\_TRACKING\_STATE::OK) {                
> auto duration = chrono::duration\_cast\<chrono::milliseconds\>(chrono::high\_resolution\_clock::now() - ts\_last1).count();
>                 
> // Ask for a fused point cloud update if 500ms have elapsed since last request
> if((duration \> 500) && viewer.chunksUpdated()) {
> // Ask for a point cloud refresh
> zed1.requestSpatialMapAsync();
> ts\_last1 = chrono::high\_resolution\_clock::now();
> }
>                 
> // If the point cloud is ready to be retrieved
> if(zed1.getSpatialMapRequestStatusAsync() == ERROR\_CODE::SUCCESS) {                    
> zed1.retrieveSpatialMapAsync(map);
> viewer.updateChunks();
> }
> }
> cv::imshow("ZED View 1", image\_zed\_ocv1);
> }
> if (zed2.grab(runtime\_parameters) == ERROR\_CODE::SUCCESS) {
> // Retrieve the left image
> zed2.retrieveImage(image\_zed2, VIEW::LEFT, MEM::CPU, display\_resolution);
> // Retrieve the camera pose data
> tracking\_state = zed2.getPosition(pose);
> //viewer.updatePose(pose, tracking\_state);
> 
> if (tracking\_state == POSITIONAL\_TRACKING\_STATE::OK) {
> auto duration = chrono::duration\_cast\<chrono::milliseconds\>(chrono::high\_resolution\_clock::now() - ts\_last2).count();
> 
> // Ask for a fused point cloud update if 500ms have elapsed since last request
> if ((duration \> 500) && viewer.chunksUpdated()) {
> // Ask for a point cloud refresh
> zed2.requestSpatialMapAsync();
> ts\_last2 = chrono::high\_resolution\_clock::now();
> }
> 
> // If the point cloud is ready to be retrieved
> if (zed2.getSpatialMapRequestStatusAsync() == ERROR\_CODE::SUCCESS) {
> zed2.retrieveSpatialMapAsync(map);
> viewer.updateChunks();
> }
> }
> cv::imshow("ZED View 2", image\_zed\_ocv2);
> }
> cv::waitKey(15);
> }
> 
> // Save generated point cloud
> //map.save("MyFusedPointCloud");
> 
> // Free allocated memory before closing the camera
> image\_zed1.free();
> image\_zed2.free();
> 
> // Close the ZED
> zed1.close();
> zed2.close();
> 
> return 0;
> }
> \`\`\`
> 
> \### Expected Result
> 
> See in OpenGLWindow the realtime mapping with the two cameras and two openCV windows with the left image of each camera
> 
> \### Actual Result
> 
> Mapping with only the second camera.
> See the openCV window of the second camera
> Get errors in loop on the console : 
> 
> \`\`\`
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> CUDA error at C:\\builds\\sl\\ZEDKit\\lib\\src\\sl\_zed\\SpatialMappingHandler.cpp:539 code=400(cudaErrorInvalidResourceHandle) "cudaEventRecord(ev\_cpu\_data, strm)"
> \`\`\`
> 
> \### ZED Camera model
> 
> ZED2i
> 
> \### Environment
> 
> \`\`\`shell
> Config :
> Zed SDK : 3.7.2
> Cuda : 11.5.119
> 
> Processor : i9-11980HK
> RAM : 32Go
> GPU : Nvidia RTX3080 16Go
> 
> OS : Windows 10 Pro
> \`\`\`
> 
> 
> \### Anything else?
> 
> \_No response\_

My last question is :  
If I assemble 2 camera on 5m long stick then getting calibration file using with zed360 when stick is motionless. Can I use this calibration file when i move stick holding 2 camera still same pozisition. I mean that I will try to turn around an object with stick to get full 3d structure

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [November 21, 2023, 10:14am UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/4 "2023-11-21T10:14:10Z")

</div>

Hi @davide,

To clarify, the mesh you get is black but should be a correct merged mesh from the cameras. The issue is the colors/textures.

You should be able to run multiple spatial mapping samples at the same time, yes. You can merge the resulting meshes/textures using any method of your choice.

> Can I use this calibration file when i move stick holding 2 camera still same pozisition

Yes, I would even say that’s the way to use it. The spatial mapping benefits from the cameras moving, and the calibration file tells the Fusion where cameras are relative to one another.

---

<div class="post-metadata">

**Author:** ![davide](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@davide](https://community.stereolabs.com/u/davide)\
**Post date:** [November 21, 2023, 2:28pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/5 "2023-11-21T14:28:29Z")

</div>

Hi @JPlou

Thank you for your answer. Is it technically possible to make colors/textures on black meshed result ? I try to estimate if it is get it return my labor to coding for colors/textures feature.

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [November 22, 2023, 10:58am UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/6 "2023-11-22T10:58:43Z")

</div>

Hey @davide

I think so, the resulting mesh is “just” a ply file.  
I did a quick test and generated one with spatial mapping fusion. I was able to paint the vertices and export the resulting mesh to .ply from Blender, and it appeared colored in Meshlab afterward.

It should be very doable with code, I don’t have directions to give to merge the textures though.

---

<div class="post-metadata">

**Author:** ![davide](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@davide](https://community.stereolabs.com/u/davide)\
**Post date:** [November 24, 2023, 11:40am UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/7 "2023-11-24T11:40:53Z")

</div>

Hi again @JPlou ,

I’ve tested again. I received good shape of object. I have measured the acquired object using 3rd party point cloud viewer the lenght of object absolutely correct but width and height is not match the real measurment. The camera was looking the object 45 degree pitch, can pitch effect the height ? I dont think so but I could not understand what was effected to height measurment. The object shape is exactly match acquired point cloud ?

---

<div class="post-metadata">

**Author:** ![JPlou](https://community.stereolabs.com/user_avatar/community.stereolabs.com/jplou/32/1012_2.png) [@JPlou](https://community.stereolabs.com/u/JPlou)\
**Post date:** [November 24, 2023, 4:25pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/8 "2023-11-24T16:25:25Z")

</div>

Hi @davide,

The quality of the point cloud and the mesh are affected by the environment. The pitch might affect the detection if it prevents the camera from seeing enough points. Having the camera see the object from other angles will help (though I understand the 5m long stick is probably part of a constraining setup)  
If you’re able to provide metrics and reproducing steps, I’d be happy to help further.

That would be:

- SVOs of your object capture
- ZED360 calibration file of your setup
- ground truth of the object’s dimensions
- please also include a [ZED Diagnostic result file](https://support.stereolabs.com/hc/en-us/articles/360010101213-What-do-I-do-if-my-ZED-ZED-Mini-ZED2-ZED2i-is-not-working-), it will give us more info on your system.

You can send them to [support@stereolabs.com](mailto:support@stereolabs.com) if you don’t want to put it here.

---

<div class="post-metadata">

**Author:** ![davide](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@davide](https://community.stereolabs.com/u/davide)\
**Post date:** [November 25, 2023, 9:53pm UTC](https://community.stereolabs.com/t/multi-camera-spatial-mapping/4015/9 "2023-11-25T21:53:47Z")

</div>

Hi @JPlou ,

Thank you for your answer. Let me share obj file with you. spatial mapping and multi spatial mapping exports. You can see the big difference. I got calibration file zed360. I will share svo also.

 ![fused](https://community.stereolabs.com/uploads/default/original/2X/6/6708dc17b5656c6e58ac1cd561aa38fd7af6e52f.png)  
 ![merged](https://community.stereolabs.com/uploads/default/original/2X/b/ba23a9a242ddce11da6030b5bd56362033d31ecc.png)
