diff --git a/CMakeLists.txt b/CMakeLists.txt index 090a1ac8..408e20a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -603,6 +603,7 @@ IF(WITH_ALICE_VISION) ENDIF(${AliceVision_VERSION} VERSION_LESS_EQUAL "2.2") SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};/usr/local/lib/cmake/modules") find_package(Geogram REQUIRED QUIET) + find_package(assimp QUIET) add_definitions("-DRTABMAP_ALICE_VISION_MAJOR=${AliceVision_VERSION_MAJOR}") add_definitions("-DRTABMAP_ALICE_VISION_MINOR=${AliceVision_VERSION_MINOR}") add_definitions("-DRTABMAP_ALICE_VISION_PATCH=${AliceVision_VERSION_PATCH}") diff --git a/corelib/include/rtabmap/core/util3d_surface.h b/corelib/include/rtabmap/core/util3d_surface.h index f8d782dc..3e71a5aa 100644 --- a/corelib/include/rtabmap/core/util3d_surface.h +++ b/corelib/include/rtabmap/core/util3d_surface.h @@ -283,12 +283,13 @@ RTABMAP_DEPRECATED(bool RTABMAP_EXP multiBandTexturing( * @param dbDriver Should be set if images and memory are not set. * @param textureSize Output texture size 1024, 2048, 4096, 8192, 16384. * @param textureDownscale Downscaling to 4 or 8 will reduce the texture quality but speed up the computation time. Set Texture Downscale to 1 instead of 2 to get the maximum possible resolution with the resolution of your images. The output texture size will be divided by this value, e.g., with texture size of 8192 and downscale value of 2, the output will be 4096. + * @param nbContrib number of contributions per frequency band for the multi-band blending (should be 4 values) * @param textureFormat Output texture format: "png" or "jpg". * @param gains Optional output of {@link #mergeTextures()}. * @param blendingGains Optional output of {@link #mergeTextures()}. * @param contrastValues Optional output of {@link #mergeTextures()}. * @param gainRGB Apply gain compensation on each RGB channels separately, otherwise it is apply equally to all channels. - * @param unwrapMethod Method to unwrap input mesh if it does not have UV coordinates Basic (> 600k faces) fast and simple. Can generate multiple atlases LSCM (<= 600k faces): optimize space. Generates one atlas ABF (<= 300k faces): optimize space and stretch. Generates one atlas. + * @param unwrapMethod Method to unwrap input mesh if it does not have UV coordinates 0=Basic (> 600k faces) fast and simple. Can generate multiple atlases 2=LSCM (<= 600k faces): optimize space. Generates one atlas 1=ABF (<= 300k faces): optimize space and stretch. Generates one atlas. * @param fillHoles Fill Texture holes with plausible values True/False. * @param padding Texture edge padding size in pixel (0-100). * @param bestScoreThreshold 0.0 to disable filtering based on threshold to relative best score (0.0-1.0). @@ -307,6 +308,7 @@ bool RTABMAP_EXP multiBandTexturing( const DBDriver * dbDriver = 0, unsigned int textureSize = 8192, unsigned int textureDownscale = 2, + const std::string & nbContrib = "1 5 10 0", const std::string & textureFormat = "jpg", const std::map > & gains = std::map >(), const std::map > & blendingGains = std::map >(), diff --git a/corelib/src/util3d_surface.cpp b/corelib/src/util3d_surface.cpp index 1a39ec8f..f529c78f 100644 --- a/corelib/src/util3d_surface.cpp +++ b/corelib/src/util3d_surface.cpp @@ -2244,6 +2244,7 @@ bool multiBandTexturing( dbDriver, textureSize, 2, + "1 5 10 0", textureFormat, gains, blendingGains, @@ -2263,6 +2264,7 @@ bool multiBandTexturing( const DBDriver * dbDriver, unsigned int textureSize, unsigned int textureDownScale, + const std::string & nbContrib, const std::string & textureFormat, const std::map > & gains, const std::map > & blendingGains, @@ -2312,11 +2314,26 @@ bool multiBandTexturing( #endif texturing.texParams.textureSide = textureSize; texturing.texParams.downscale = textureDownScale; + std::vector multiBandNbContrib; + std::list values = uSplit(nbContrib, ' '); + for(std::list::iterator iter=values.begin(); iter!=values.end(); ++iter) + { + multiBandNbContrib.push_back(uStr2Int(*iter)); + } + if(multiBandNbContrib.size() != 4) + { + UERROR("multiband: Wrong number of nb of contribution (vaue=\"%s\", should be 4), using default values instead.", nbContrib.c_str()); + } + else + { + texturing.texParams.multiBandNbContrib = multiBandNbContrib; + } texturing.texParams.padding = padding; texturing.texParams.fillHoles = fillHoles; texturing.texParams.bestScoreThreshold = bestScoreThreshold; texturing.texParams.angleHardThreshold = angleHardThreshold; texturing.texParams.forceVisibleByAllVertices = forceVisibleByAllVertices; + texturing.texParams.visibilityRemappingMethod = mesh::EVisibilityRemappingMethod::Pull; for(size_t i=0;isecond * model.localTransform(); - Eigen::Matrix m = (t.inverse()).toEigen3d().matrix().block<3,4>(0, 0); + Transform t = (iter->second * model.localTransform()).inverse(); + Eigen::Matrix m = t.toEigen3d().matrix().block<3,4>(0, 0); sfmData::CameraPose pose(geometry::Pose3(m), true); sfmData.setAbsolutePose((IndexT)viewId, pose); + UDEBUG("%d %d %f %f %f %f", imageSize.width, imageSize.height, model.fx(), model.fy(), model.cx(), model.cy()); std::shared_ptr camPtr = std::make_shared( +#if RTABMAP_ALICE_VISION_MAJOR > 2 || (RTABMAP_ALICE_VISION_MAJOR==2 && RTABMAP_ALICE_VISION_MINOR>=4) + //https://github.com/alicevision/AliceVision/commit/9fab5c79a1c65595fe5c5001267e1c5212bc93f0#diff-b0c0a3c30de50be8e4ed283dfe4c8ae4a9bc861aa9a83bd8bfda8182e9d67c08 + // [all] the camera principal point is now defined as an offset relative to the image center + imageSize.width, imageSize.height, model.fx(), model.fy(), model.cx() - double(imageSize.width) * 0.5, model.cy() - double(imageSize.height) * 0.5); +#else imageSize.width, imageSize.height, model.fx(), model.cx(), model.cy()); +#endif sfmData.intrinsics.insert(std::make_pair((IndexT)viewId, camPtr)); std::string imagePath = tmpImageDirectory+uFormat("/%d.jpg", viewId); @@ -2507,14 +2531,18 @@ bool multiBandTexturing( mvsUtils::MultiViewParams mp(sfmData); - UINFO("Unwrapping..."); + UINFO("Unwrapping (method=%d=%s)...", unwrapMethod, mesh::EUnwrapMethod_enumToString((mesh::EUnwrapMethod)unwrapMethod).c_str()); texturing.unwrap(mp, (mesh::EUnwrapMethod)unwrapMethod); UINFO("Unwrapping done. %fs", timer.ticks()); // save final obj file std::string baseName = uSplit(UFile::getName(outputOBJPath), '.').front(); +#if RTABMAP_ALICE_VISION_MAJOR > 2 || (RTABMAP_ALICE_VISION_MAJOR==2 && RTABMAP_ALICE_VISION_MINOR>=4) + texturing.saveAs(outputDirectory, baseName, aliceVision::mesh::EFileType::OBJ, imageIO::EImageFileType::PNG); +#else texturing.saveAsOBJ(outputDirectory, baseName); - UINFO("Saved %s. %fs", outputOBJPath, timer.ticks()); +#endif + UINFO("Saved %s. %fs", outputOBJPath.c_str(), timer.ticks()); // generate textures UINFO("Generating textures..."); @@ -2576,7 +2604,9 @@ bool multiBandTexturing( UINFO("Rename/convert textures... done. %fs", timer.ticks()); #if RTABMAP_ALICE_VISION_MAJOR > 2 || (RTABMAP_ALICE_VISION_MAJOR==2 && RTABMAP_ALICE_VISION_MINOR>=3) + UINFO("Cleanup sfmdata..."); sfmData.clear(); + UINFO("Cleanup sfmdata... done. %fs", timer.ticks()); #endif return true; diff --git a/guilib/src/ExportCloudsDialog.cpp b/guilib/src/ExportCloudsDialog.cpp index 8d4e0f5e..4cdce554 100644 --- a/guilib/src/ExportCloudsDialog.cpp +++ b/guilib/src/ExportCloudsDialog.cpp @@ -233,6 +233,7 @@ ExportCloudsDialog::ExportCloudsDialog(QWidget *parent) : connect(_ui->checkBox_multiband, SIGNAL(stateChanged(int)), this, SIGNAL(configChanged())); connect(_ui->checkBox_multiband, SIGNAL(stateChanged(int)), this, SLOT(updateReconstructionFlavor())); connect(_ui->spinBox_multiband_downscale, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged())); + connect(_ui->lineEdit_multiband_nbcontrib, SIGNAL(textChanged(const QString &)), this, SIGNAL(configChanged())); connect(_ui->comboBox_multiband_unwrap, SIGNAL(currentIndexChanged(int)), this, SIGNAL(configChanged())); connect(_ui->checkBox_multiband_fillholes, SIGNAL(stateChanged(int)), this, SIGNAL(configChanged())); connect(_ui->spinBox_multiband_padding, SIGNAL(valueChanged(int)), this, SIGNAL(configChanged())); @@ -450,6 +451,7 @@ void ExportCloudsDialog::saveSettings(QSettings & settings, const QString & grou settings.setValue("mesh_textureBlendingDecimation", _ui->comboBox_blendingDecimation->currentIndex()); settings.setValue("mesh_textureMultiband", _ui->checkBox_multiband->isChecked()); settings.setValue("mesh_textureMultibandDownScale", _ui->spinBox_multiband_downscale->value()); + settings.setValue("mesh_textureMultibandNbContrib", _ui->lineEdit_multiband_nbcontrib->text()); settings.setValue("mesh_textureMultibandUnwrap", _ui->comboBox_multiband_unwrap->currentIndex()); settings.setValue("mesh_textureMultibandFillHoles", _ui->checkBox_multiband_fillholes->isChecked()); settings.setValue("mesh_textureMultibandPadding", _ui->spinBox_multiband_padding->value()); @@ -624,6 +626,7 @@ void ExportCloudsDialog::loadSettings(QSettings & settings, const QString & grou _ui->comboBox_blendingDecimation->setCurrentIndex(settings.value("mesh_textureBlendingDecimation", _ui->comboBox_blendingDecimation->currentIndex()).toInt()); _ui->checkBox_multiband->setChecked(settings.value("mesh_textureMultiband", _ui->checkBox_multiband->isChecked()).toBool()); _ui->spinBox_multiband_downscale->setValue(settings.value("mesh_textureMultibandDownScale", _ui->spinBox_multiband_downscale->value()).toInt()); + _ui->lineEdit_multiband_nbcontrib->setText(settings.value("mesh_textureMultibandNbContrib", _ui->lineEdit_multiband_nbcontrib->text()).toString()); _ui->comboBox_multiband_unwrap->setCurrentIndex(settings.value("mesh_textureMultibandUnwrap", _ui->comboBox_multiband_unwrap->currentIndex()).toInt()); _ui->checkBox_multiband_fillholes->setChecked(settings.value("mesh_textureMultibandFillHoles", _ui->checkBox_multiband_fillholes->isChecked()).toBool()); _ui->spinBox_multiband_padding->setValue(settings.value("mesh_textureMultibandPadding", _ui->spinBox_multiband_padding->value()).toInt()); @@ -789,6 +792,7 @@ void ExportCloudsDialog::restoreDefaults() _ui->comboBox_blendingDecimation->setCurrentIndex(0); _ui->checkBox_multiband->setChecked(false); _ui->spinBox_multiband_downscale->setValue(2); + _ui->lineEdit_multiband_nbcontrib->setText("1 5 10 0"); _ui->comboBox_multiband_unwrap->setCurrentIndex(0); _ui->checkBox_multiband_fillholes->setChecked(false); _ui->spinBox_multiband_padding->setValue(5); @@ -4476,6 +4480,7 @@ void ExportCloudsDialog::saveTextureMeshes( _dbDriver, textureSize, _ui->spinBox_multiband_downscale->value(), + _ui->lineEdit_multiband_nbcontrib->text().toStdString(), _ui->comboBox_meshingTextureFormat->currentText().toStdString(), gains, blendingGains, diff --git a/guilib/src/ui/exportCloudsDialog.ui b/guilib/src/ui/exportCloudsDialog.ui index 966d78e0..2cc5e43e 100644 --- a/guilib/src/ui/exportCloudsDialog.ui +++ b/guilib/src/ui/exportCloudsDialog.ui @@ -23,9 +23,9 @@ 0 - -3479 + -3537 998 - 5642 + 5673 @@ -2770,17 +2770,36 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - + + - + Texture edge padding size in pixel. + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - + - Unwrap method. Method to unwrap input mesh if it does not have UV coordinates Basic (> 600k faces) fast and simple. Can generate multiple atlases LSCM (<= 600k faces): optimize space. Generates one atlas ABF (<= 300k faces): optimize space and stretch. Generates one atlas. + Unwrap method: 0=basic (default, >600k faces, fast), 1=ABF (<=300k faces, generate 1 atlas), 2=LSCM (<=600k faces, optimize space). + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + Force visible by all vertices. Triangle visibility is based on the union of vertices visibility. true @@ -2800,20 +2819,26 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - - - Texture edge padding size in pixel. - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - + + + + + Basic + + + + + ABF + + + + + LSCM + + - + Angle hard threshold. 0 to disable angle hard threshold filtering. @@ -2826,20 +2851,7 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - - - 1 - - - 180.000000000000000 - - - 90.000000000000000 - - - - + Best score threshold. 0 to disable filtering based on threshold to relative best score. @@ -2852,7 +2864,14 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - + + + + + + + + 1.000000000000000 @@ -2863,16 +2882,26 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - - 100 - - - 5 + + + - + + + + 1 + + + 180.000000000000000 + + + 90.000000000000000 + + + + Fill Texture holes with plausible values. @@ -2885,29 +2914,20 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - - - - Basic - - - - - LSCM - - - - - ABF - - + + + + 100 + + + 5 + - - + + - Force visible by all vertices. Triangle visibility is based on the union of vertices visibility. + Number of contributions per frequency band for the multi-band blending. Should be 4 values. true @@ -2917,10 +2937,10 @@ By Node ID and Camera Index: NodeID*10+CameraIndex - - + + - + 1 5 10 0 diff --git a/tools/Export/main.cpp b/tools/Export/main.cpp index 8ed3c83c..296d762a 100644 --- a/tools/Export/main.cpp +++ b/tools/Export/main.cpp @@ -63,7 +63,7 @@ void showUsage() " --mesh Create a mesh.\n" " --texture Create a mesh with texture.\n" " --texture_size # Texture size 1024, 2048, 4096, 8192, 16384 (default 8192).\n" - " --texture_count # Maximum textures generated (default 1).\n" + " --texture_count # Maximum textures generated (default 1). Ignored by --multiband option (adjust --multiband_contrib instead).\n" " --texture_range # Maximum camera range for texturing a polygon (default 0 meters: no limit).\n" " --texture_depth_error # Maximum depth error between reprojected mesh and depth image to texture a face (-1=disabled, 0=edge length is used, default=0).\n" " --texture_d2c Distance to camera policy.\n" @@ -91,7 +91,8 @@ void showUsage() " --high_gain # High brightness gain 0-100 (default 10).\n" " --multiband Enable multiband texturing (AliceVision dependency required).\n" " --multiband_downscale # Downscaling reduce the texture quality but speed up the computation time (default 2).\n" - " --multiband_unwrap # Method to unwrap input mesh: 0=basic (default, >600k faces, fast), 1=LSCM (<=600k faces, optimize space), 2=ABF (<=300k faces, generate 1 atlas).\n" + " --multiband_contrib \"# # # # \" Number of contributions per frequency band for the multi-band blending, should be 4 values! (default \"1 5 10 0\").\n" + " --multiband_unwrap # Method to unwrap input mesh: 0=basic (default, >600k faces, fast), 1=ABF (<=300k faces, generate 1 atlas), 2=LSCM (<=600k faces, optimize space).\n" " --multiband_fillholes Fill Texture holes with plausible values.\n" " --multiband_padding # Texture edge padding size in pixel (0-100) (default 5).\n" " --multiband_scorethr # 0 to disable filtering based on threshold to relative best score (0.0-1.0). (default 0.1).\n" @@ -153,6 +154,7 @@ int main(int argc, char * argv[]) bool distanceToCamPolicy = false; bool multiband = false; int multibandDownScale = 2; + std::string multibandNbContrib = "1 5 10 0"; int multibandUnwrap = 0; bool multibandFillHoles = false; int multibandPadding = 5; @@ -373,6 +375,23 @@ int main(int argc, char * argv[]) showUsage(); } } + else if(std::strcmp(argv[i], "--multiband_contrib") == 0) + { + ++i; + if(i