11 #include "base/camera_models.h"
12 #include "feature/extraction.h"
13 #include "ui/options_widget.h"
14 #include "ui/qt_utils.h"
15 #include "util/misc.h"
16 #include "util/option_manager.h"
26 virtual void Run() = 0;
47 std::string import_path_;
51 : OptionsWidget(parent),
58 AddOptionDirPath(&options->image_reader->mask_path,
"mask_path");
59 AddOptionFilePath(&options->image_reader->camera_mask_path,
62 AddOptionInt(&options->sift_extraction->max_image_size,
"max_image_size");
63 AddOptionInt(&options->sift_extraction->max_num_features,
65 AddOptionInt(&options->sift_extraction->first_octave,
"first_octave", -5);
66 AddOptionInt(&options->sift_extraction->num_octaves,
"num_octaves");
67 AddOptionInt(&options->sift_extraction->octave_resolution,
69 AddOptionDouble(&options->sift_extraction->peak_threshold,
"peak_threshold",
70 0.0, 1e7, 0.00001, 5);
71 AddOptionDouble(&options->sift_extraction->edge_threshold,
73 AddOptionBool(&options->sift_extraction->estimate_affine_shape,
74 "estimate_affine_shape");
75 AddOptionInt(&options->sift_extraction->max_num_orientations,
76 "max_num_orientations");
77 AddOptionBool(&options->sift_extraction->upright,
"upright");
78 AddOptionBool(&options->sift_extraction->domain_size_pooling,
79 "domain_size_pooling");
80 AddOptionDouble(&options->sift_extraction->dsp_min_scale,
"dsp_min_scale",
81 0.0, 1e7, 0.00001, 5);
82 AddOptionDouble(&options->sift_extraction->dsp_max_scale,
"dsp_max_scale",
83 0.0, 1e7, 0.00001, 5);
84 AddOptionInt(&options->sift_extraction->dsp_num_scales,
"dsp_num_scales",
87 AddOptionInt(&options->sift_extraction->num_threads,
"num_threads", -1);
88 AddOptionBool(&options->sift_extraction->use_gpu,
"use_gpu");
89 AddOptionText(&options->sift_extraction->gpu_index,
"gpu_index");
96 if (
options_->database_path->empty()) {
97 QMessageBox::critical(
this,
"",
98 tr(
"Database path is not set. Please set it in "
99 "Project settings."));
103 if (
options_->image_path->empty()) {
104 QMessageBox::critical(
this,
"",
105 tr(
"Image path is not set. Please set it in "
106 "Project settings."));
110 if (!ExistsDir(*
options_->image_path)) {
111 QMessageBox::critical(
113 tr(
"Image path does not exist: %1")
114 .arg(QString::fromStdString(*
options_->image_path)));
119 const std::string database_dir = GetParentDir(*
options_->database_path);
120 if (!ExistsDir(database_dir)) {
121 QMessageBox::critical(
123 tr(
"Database directory does not exist: %1")
124 .arg(QString::fromStdString(database_dir)));
128 ImageReaderOptions reader_options = *
options_->image_reader;
129 reader_options.database_path = *
options_->database_path;
130 reader_options.image_path = *
options_->image_path;
133 if (!reader_options.Check()) {
134 QMessageBox::critical(
this,
"", tr(
"Invalid image reader options."));
139 if (!
options_->sift_extraction->Check()) {
140 QMessageBox::critical(
this,
"", tr(
"Invalid SIFT extraction options."));
144 Thread* extractor =
new SiftFeatureExtractor(reader_options,
152 AddOptionDirPath(&import_path_,
"import_path");
158 if (!ExistsDir(import_path_)) {
159 QMessageBox::critical(
this,
"", tr(
"Path is not a directory"));
163 ImageReaderOptions reader_options = *
options_->image_reader;
164 reader_options.database_path = *
options_->database_path;
165 reader_options.image_path = *
options_->image_path;
167 Thread* importer =
new FeatureImporter(reader_options, import_path_);
173 : parent_(parent), options_(options) {
177 setWindowTitle(
"Feature extraction");
179 QGridLayout* grid =
new QGridLayout(
this);
181 grid->addWidget(CreateCameraModelBox(), 0, 0);
183 tab_widget_ =
new QTabWidget(
this);
185 QScrollArea* extraction_widget =
new QScrollArea(
this);
186 extraction_widget->setAlignment(Qt::AlignHCenter);
188 tab_widget_->addTab(extraction_widget, tr(
"Extract"));
190 QScrollArea* import_widget =
new QScrollArea(
this);
191 import_widget->setAlignment(Qt::AlignHCenter);
193 tab_widget_->addTab(import_widget, tr(
"Import"));
195 grid->addWidget(tab_widget_);
197 QPushButton* extract_button =
new QPushButton(tr(
"Extract"),
this);
198 connect(extract_button, &QPushButton::released,
this,
199 &FeatureExtractionWidget::Extract);
200 grid->addWidget(extract_button, grid->rowCount(), 0);
203 QGroupBox* FeatureExtractionWidget::CreateCameraModelBox() {
204 camera_model_ids_.clear();
206 camera_model_cb_ =
new QComboBox(
this);
208 #define CAMERA_MODEL_CASE(CameraModel) \
209 camera_model_cb_->addItem(QString::fromStdString( \
210 CameraModelIdToName(CameraModel::model_id))); \
211 camera_model_ids_.push_back(static_cast<int>(CameraModel::model_id));
215 #undef CAMERA_MODEL_CASE
217 camera_params_exif_rb_ =
new QRadioButton(tr(
"Parameters from EXIF"),
this);
218 camera_params_exif_rb_->setChecked(
true);
220 camera_params_custom_rb_ =
new QRadioButton(tr(
"Custom parameters"),
this);
222 camera_params_info_ =
new QLabel(tr(
""),
this);
223 QPalette pal = QPalette(camera_params_info_->palette());
224 pal.setColor(QPalette::WindowText, QColor(130, 130, 130));
225 camera_params_info_->setPalette(pal);
227 camera_params_text_ =
new QLineEdit(
this);
228 camera_params_text_->setEnabled(
false);
230 single_camera_cb_ =
new QCheckBox(
"Shared for all images",
this);
231 single_camera_cb_->setChecked(
false);
233 single_camera_per_folder_cb_ =
new QCheckBox(
"Shared per sub-folder",
this);
234 single_camera_per_folder_cb_->setChecked(
false);
236 QGroupBox* box =
new QGroupBox(tr(
"Camera model"),
this);
238 QVBoxLayout* vbox =
new QVBoxLayout(box);
239 vbox->addWidget(camera_model_cb_);
240 vbox->addWidget(camera_params_info_);
241 vbox->addWidget(single_camera_cb_);
242 vbox->addWidget(single_camera_per_folder_cb_);
243 vbox->addWidget(camera_params_exif_rb_);
244 vbox->addWidget(camera_params_custom_rb_);
245 vbox->addWidget(camera_params_text_);
248 box->setLayout(vbox);
250 SelectCameraModel(camera_model_cb_->currentIndex());
252 connect(camera_model_cb_,
253 (
void(QComboBox::*)(
int)) & QComboBox::currentIndexChanged,
this,
254 &FeatureExtractionWidget::SelectCameraModel);
255 connect(camera_params_exif_rb_, &QRadioButton::clicked, camera_params_text_,
256 &QLineEdit::setDisabled);
257 connect(camera_params_custom_rb_, &QRadioButton::clicked,
258 camera_params_text_, &QLineEdit::setEnabled);
263 void FeatureExtractionWidget::showEvent(QShowEvent*
event) {
264 parent_->setDisabled(
true);
268 void FeatureExtractionWidget::hideEvent(QHideEvent*
event) {
269 parent_->setEnabled(
true);
273 void FeatureExtractionWidget::ReadOptions() {
274 const auto camera_code =
275 CameraModelNameToId(options_->image_reader->camera_model);
276 for (
size_t i = 0; i < camera_model_ids_.size(); ++i) {
277 if (camera_model_ids_[i] == camera_code) {
278 SelectCameraModel(i);
279 camera_model_cb_->setCurrentIndex(i);
283 single_camera_cb_->setChecked(options_->image_reader->single_camera);
284 single_camera_per_folder_cb_->setChecked(
285 options_->image_reader->single_camera_per_folder);
286 camera_params_text_->setText(
287 QString::fromStdString(options_->image_reader->camera_params));
290 void FeatureExtractionWidget::WriteOptions() {
291 options_->image_reader->camera_model = CameraModelIdToName(
292 camera_model_ids_[camera_model_cb_->currentIndex()]);
293 options_->image_reader->single_camera = single_camera_cb_->isChecked();
294 options_->image_reader->single_camera_per_folder =
295 single_camera_per_folder_cb_->isChecked();
296 options_->image_reader->camera_params =
297 camera_params_text_->text().toUtf8().constData();
300 void FeatureExtractionWidget::SelectCameraModel(
const int idx) {
301 const int code = camera_model_ids_[idx];
302 camera_params_info_->setText(QString::fromStdString(
304 CameraModelParamsInfo(code).c_str())));
307 void FeatureExtractionWidget::Extract() {
310 const auto old_camera_params_text = camera_params_text_->text();
311 if (!camera_params_custom_rb_->isChecked()) {
312 camera_params_text_->setText(
"");
317 if (!ExistsCameraModelWithName(options_->image_reader->camera_model)) {
318 QMessageBox::critical(
this,
"", tr(
"Camera model does not exist"));
322 const std::vector<double> camera_params =
323 CSVToVector<double>(options_->image_reader->camera_params);
324 const auto camera_code =
325 CameraModelNameToId(options_->image_reader->camera_model);
327 if (camera_params_custom_rb_->isChecked() &&
328 !CameraModelVerifyParams(camera_code, camera_params)) {
329 QMessageBox::critical(
this,
"", tr(
"Invalid camera parameters"));
334 static_cast<QScrollArea*
>(tab_widget_->currentWidget())->widget();
335 static_cast<ExtractionWidget*
>(widget)->
Run();
337 camera_params_text_->setText(old_camera_params_text);
int Run(int argc, const char *argv[])
std::string StringPrintf(const char *format,...)
Generic file read and write utility for python interface.
colmap::OptionManager OptionManager