Updated for AliceVision >=2.4.0 compatibility. Export: added --multiband_contrib option.

This commit is contained in:
matlabbe
2021-09-19 20:20:45 -04:00
parent 44b057b0d7
commit 14b56813d3
6 changed files with 150 additions and 72 deletions

View File

@@ -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}")

View File

@@ -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<int, std::map<int, cv::Vec4d> > & gains = std::map<int, std::map<int, cv::Vec4d> >(),
const std::map<int, std::map<int, cv::Mat> > & blendingGains = std::map<int, std::map<int, cv::Mat> >(),

View File

@@ -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<int, std::map<int, cv::Vec4d> > & gains,
const std::map<int, std::map<int, cv::Mat> > & blendingGains,
@@ -2312,11 +2314,26 @@ bool multiBandTexturing(
#endif
texturing.texParams.textureSide = textureSize;
texturing.texParams.downscale = textureDownScale;
std::vector<int> multiBandNbContrib;
std::list<std::string> values = uSplit(nbContrib, ' ');
for(std::list<std::string>::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;i<cloud2.size();++i)
@@ -2479,13 +2496,20 @@ bool multiBandTexturing(
imageRoi = output;
}
Transform t = iter->second * model.localTransform();
Eigen::Matrix<double, 3, 4> m = (t.inverse()).toEigen3d().matrix().block<3,4>(0, 0);
Transform t = (iter->second * model.localTransform()).inverse();
Eigen::Matrix<double, 3, 4> 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<camera::IntrinsicBase> camPtr = std::make_shared<camera::Pinhole>(
#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;

View File

@@ -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,

View File

@@ -23,9 +23,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-3479</y>
<y>-3537</y>
<width>998</width>
<height>5642</height>
<height>5673</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -2770,17 +2770,36 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_multiband_fillholes">
<item row="4" column="1">
<widget class="QLabel" name="label_52">
<property name="text">
<string/>
<string>Texture edge padding size in pixel.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLabel" name="label_50">
<property name="text">
<string>Unwrap method. Method to unwrap input mesh if it does not have UV coordinates Basic (&gt; 600k faces) fast and simple. Can generate multiple atlases LSCM (&lt;= 600k faces): optimize space. Generates one atlas ABF (&lt;= 300k faces): optimize space and stretch. Generates one atlas.</string>
<string>Unwrap method: 0=basic (default, &gt;600k faces, fast), 1=ABF (&lt;=300k faces, generate 1 atlas), 2=LSCM (&lt;=600k faces, optimize space).</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_55">
<property name="text">
<string>Force visible by all vertices. Triangle visibility is based on the union of vertices visibility.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -2800,20 +2819,26 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_52">
<property name="text">
<string>Texture edge padding size in pixel.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
<item row="2" column="0">
<widget class="QComboBox" name="comboBox_multiband_unwrap">
<item>
<property name="text">
<string>Basic</string>
</property>
</item>
<item>
<property name="text">
<string>ABF</string>
</property>
</item>
<item>
<property name="text">
<string>LSCM</string>
</property>
</item>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLabel" name="label_54">
<property name="text">
<string>Angle hard threshold. 0 to disable angle hard threshold filtering.</string>
@@ -2826,20 +2851,7 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBox_multiband_angle">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="value">
<double>90.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLabel" name="label_53">
<property name="text">
<string>Best score threshold. 0 to disable filtering based on threshold to relative best score.</string>
@@ -2852,7 +2864,14 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="7" column="0">
<widget class="QCheckBox" name="checkBox_multiband_forcevisible">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBox_multiband_bestscore">
<property name="maximum">
<double>1.000000000000000</double>
@@ -2863,16 +2882,26 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</widget>
</item>
<item row="3" column="0">
<widget class="QSpinBox" name="spinBox_multiband_padding">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>5</number>
<widget class="QCheckBox" name="checkBox_multiband_fillholes">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="6" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBox_multiband_angle">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="value">
<double>90.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_51">
<property name="text">
<string>Fill Texture holes with plausible values.</string>
@@ -2885,29 +2914,20 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="comboBox_multiband_unwrap">
<item>
<property name="text">
<string>Basic</string>
</property>
</item>
<item>
<property name="text">
<string>LSCM</string>
</property>
</item>
<item>
<property name="text">
<string>ABF</string>
</property>
</item>
<item row="4" column="0">
<widget class="QSpinBox" name="spinBox_multiband_padding">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_55">
<item row="1" column="1">
<widget class="QLabel" name="label_56">
<property name="text">
<string>Force visible by all vertices. Triangle visibility is based on the union of vertices visibility.</string>
<string>Number of contributions per frequency band for the multi-band blending. Should be 4 values.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -2917,10 +2937,10 @@ By Node ID and Camera Index: NodeID*10+CameraIndex</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBox_multiband_forcevisible">
<item row="1" column="0">
<widget class="QLineEdit" name="lineEdit_multiband_nbcontrib">
<property name="text">
<string/>
<string>1 5 10 0</string>
</property>
</widget>
</item>

View File

@@ -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<argc-1)
{
if(uSplit(argv[i], ' ').size() != 4)
{
printf("--multiband_contrib has wrong format! value=\"%s\"\n", argv[i]);
showUsage();
}
multibandNbContrib = argv[i];
}
else
{
showUsage();
}
}
else if(std::strcmp(argv[i], "--multiband_unwrap") == 0)
{
++i;
@@ -1424,7 +1443,7 @@ int main(int argc, char * argv[])
printf("MultiBand texturing (size=%d, downscale=%d, unwrap method=%s, fill holes=%s, padding=%d, best score thr=%f, angle thr=%f, force visible=%s)... \"%s\"\n",
textureSize,
multibandDownScale,
multibandUnwrap==2?"ABF":multibandUnwrap==1?"LSCM":"Basic",
multibandUnwrap==1?"ABF":multibandUnwrap==2?"LSCM":"Basic",
multibandFillHoles?"true":"false",
multibandPadding,
multibandBestScoreThr,
@@ -1442,6 +1461,7 @@ int main(int argc, char * argv[])
0,
textureSize,
multibandDownScale,
multibandNbContrib,
"jpg",
gains,
blendingGains,