Hi Everyone,
I am trying to use the JAVA API to get a dense cloud incrementally.
My strategy to get that is to create chunk pairs align the two chunk together to align the second dense cloud with the first one and then I create a third chunk and I align this chunk with the second aligned chunk and so on.
This strategy works well in metashape GUI but I can't make it works with the JAVA API.
It seems that after the AlignChunks method the aligned chunk is properly aligned but then when I reenter the loop the dense cloud is reset to the non aligned coordinates.
I am certainly doing something wrong when I create the new chunk.
When I enter the loop for i = 2 the dense cloud corresponding to the chunk created for i = 1 is not aligned anymore so the new chunk 2 is aligned against the old coordinates of chunk 1. Is there a way to save the new coordinates of chunk 1 after the AlignChunks ?
Please find my code below for more details :
// creation of the doc with all the chunks
Document doc = new Document();
doc.save("FullProcess.psx", progress);
// Loop to create and align chunks
for (int i = 0; i < 3; i++)
{
// metashape tasks
MatchPhotos match_photos = new MatchPhotos();
AlignCameras align_cameras = new AlignCameras();
BuildDepthMaps build_depth_maps = new BuildDepthMaps();
BuildDenseCloud build_dense_cloud = new BuildDenseCloud();
ExportPoints exp_points = new ExportPoints();
AlignChunks Align = new AlignChunks();
// create new chunk
Chunk chunk = doc.addChunk();
// add names
chunk.addPhotos(names, progress);
// match
match_photos.setDownscale(2);
match_photos.apply(chunk, progress);
match_photos.delete();
// align
align_cameras.apply(chunk, progress);
align_cameras.delete();
// depth
build_depth_maps.setDownscale(4);
build_depth_maps.setFilterMode(FilterMode.MildFiltering);
build_depth_maps.apply(chunk, progress);
build_depth_maps.delete();
// dense cloud
build_dense_cloud.setPointColors(true);
build_dense_cloud.getPointColors();
build_dense_cloud.apply(chunk, progress);
build_dense_cloud.delete();
// if we have more than one chunk we align the current with the previous one
if (i>=1)
{
int idMerge[] = {i -1 , i};
Align.setChunks(idMerge);
Align.apply(doc, progress);
Align.delete();
// export points of the dense cloud
ExportPoints exp_points4 = new ExportPoints();
exp_points4.setFormat(PointsFormat.PointsFormatPLY);
String nameCloudEnd = "chunk"+(i);
exp_points4.setPath("/home/" + nameCloudEnd + ".ply");
exp_points4.apply(doc.getChunk(i).get(), progress);
exp_points4.delete();
}
Thank you very much for your help !
}