26 virtual void Run() = 0;
47 std::string import_path_;
70 0.0, 1e7, 0.00001, 5);
74 "estimate_affine_shape");
76 "max_num_orientations");
79 "domain_size_pooling");
81 0.0, 1e7, 0.00001, 5);
83 0.0, 1e7, 0.00001, 5);
97 QMessageBox::critical(
this,
"",
98 tr(
"Database path is not set. Please set it in "
99 "Project settings."));
104 QMessageBox::critical(
this,
"",
105 tr(
"Image path is not set. Please set it in "
106 "Project settings."));
111 QMessageBox::critical(
113 tr(
"Image path does not exist: %1")
121 QMessageBox::critical(
123 tr(
"Database directory does not exist: %1")
124 .arg(QString::fromStdString(database_dir)));
133 if (!reader_options.
Check()) {
134 QMessageBox::critical(
this,
"", tr(
"Invalid image reader options."));
140 QMessageBox::critical(
this,
"", tr(
"Invalid SIFT extraction options."));
159 QMessageBox::critical(
this,
"", tr(
"Path is not a directory"));
173 : parent_(parent), options_(options) {
176 setWindowFlags(Qt::Window);
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 =
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(
286 camera_params_text_->setText(
287 QString::fromStdString(options_->
image_reader->camera_params));
290 void FeatureExtractionWidget::WriteOptions() {
292 camera_model_ids_[camera_model_cb_->currentIndex()]);
293 options_->
image_reader->single_camera = single_camera_cb_->isChecked();
295 single_camera_per_folder_cb_->isChecked();
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(
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(
"");
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 =
327 if (camera_params_custom_rb_->isChecked() &&
329 QMessageBox::critical(
this,
"", tr(
"Invalid camera parameters"));
334 static_cast<QScrollArea*
>(tab_widget_->currentWidget())->widget();
337 camera_params_text_->setText(old_camera_params_text);
int Run(int argc, const char *argv[])
#define CAMERA_MODEL_CASES
std::shared_ptr< std::string > database_path
std::shared_ptr< SiftExtractionOptions > sift_extraction
std::shared_ptr< ImageReaderOptions > image_reader
std::shared_ptr< std::string > image_path
std::string StringPrintf(const char *format,...)
Generic file read and write utility for python interface.
bool ExistsCameraModelWithName(const std::string &model_name)
bool CameraModelVerifyParams(const int model_id, const std::vector< double > ¶ms)
std::string CameraModelIdToName(const int model_id)
bool ExistsDir(const std::string &path)
std::string CameraModelParamsInfo(const int model_id)
std::string GetParentDir(const std::string &path)
int CameraModelNameToId(const std::string &model_name)
std::string database_path