-Updated CameraModel and StereoCameraModel so that a stereo camera model can be initialization from know intrinsics and extrinsics

-CreateSimpleCalibrationDialog updated to create mono/stereo calibration files with advanced option (setting intrinsics of each camera + extrinsics between them). Rectification R and new camera P matrices are then automatically computed.
-Added GeodeticCoords class for convience conversion between GPS values (latitude/longitude/altitude) to local coordinate (ENU).
-Added support of Malaga Urban and St Lucia ground truths.
-CameraImages: added option to debayer images. Timestamps file: added support of "sec millisec" format.
-Added UException class: exceptions are sent instead of exiting the application on UASSERT or UFATAL.
This commit is contained in:
matlabbe
2016-01-19 17:43:33 -05:00
parent 72e66605e4
commit 7bfd76e747
29 changed files with 1739 additions and 702 deletions
+203 -46
View File
@@ -46,16 +46,49 @@ CreateSimpleCalibrationDialog::CreateSimpleCalibrationDialog(
savingFolder_(savingFolder),
cameraName_(cameraName)
{
if(cameraName_.isEmpty())
{
cameraName_ = "calib";
}
ui_ = new Ui_createSimpleCalibrationDialog();
ui_->setupUi(this);
connect(ui_->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(saveCalibration()));
connect(ui_->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui_->comboBox_advanced, SIGNAL(currentIndexChanged(int)), ui_->stackedWidget, SLOT(setCurrentIndex(int)));
connect(ui_->checkBox_stereo, SIGNAL(stateChanged(int)), this, SLOT(updateStereoView()));
connect(ui_->checkBox_stereo, SIGNAL(stateChanged(int)), this, SLOT(updateSaveStatus()));
connect(ui_->comboBox_advanced, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fx, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fy, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fx_l, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fy_l, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_cx_l, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_cy_l, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->lineEdit_D_l, SIGNAL(textEdited(const QString &)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fx_r, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_fy_r, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_cx_r, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_cy_r, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->lineEdit_D_r, SIGNAL(textEdited(const QString &)), this, SLOT(updateSaveStatus()));
connect(ui_->spinBox_width, SIGNAL(valueChanged(int)), this, SLOT(updateSaveStatus()));
connect(ui_->spinBox_height, SIGNAL(valueChanged(int)), this, SLOT(updateSaveStatus()));
connect(ui_->doubleSpinBox_baseline, SIGNAL(valueChanged(double)), this, SLOT(updateSaveStatus()));
connect(ui_->lineEdit_RT, SIGNAL(textEdited(const QString &)), this, SLOT(updateSaveStatus()));
ui_->stackedWidget->setCurrentIndex(ui_->comboBox_advanced->currentIndex());
ui_->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
updateStereoView();
}
CreateSimpleCalibrationDialog::~CreateSimpleCalibrationDialog()
@@ -63,29 +96,189 @@ CreateSimpleCalibrationDialog::~CreateSimpleCalibrationDialog()
delete ui_;
}
void CreateSimpleCalibrationDialog::updateStereoView()
{
bool checked = ui_->checkBox_stereo->isChecked();
ui_->doubleSpinBox_baseline->setVisible(checked);
ui_->label_baseline->setVisible(checked);
ui_->label_right->setVisible(checked);
ui_->doubleSpinBox_fx_r->setVisible(checked);
ui_->doubleSpinBox_fy_r->setVisible(checked);
ui_->doubleSpinBox_cx_r->setVisible(checked);
ui_->doubleSpinBox_cy_r->setVisible(checked);
ui_->lineEdit_D_r->setVisible(checked);
ui_->groupBox_stereo_extrinsics->setVisible(checked);
ui_->label_left->setVisible(checked);
}
void CreateSimpleCalibrationDialog::updateSaveStatus()
{
ui_->buttonBox->button(QDialogButtonBox::Save)->setEnabled(ui_->doubleSpinBox_fx->value() > 0.0 && ui_->doubleSpinBox_fy->value() > 0.0);
bool valid = false;
if(ui_->comboBox_advanced->currentIndex() == 0 &&
ui_->doubleSpinBox_fx->value() > 0.0 &&
ui_->doubleSpinBox_fy->value() > 0.0 &&
(!ui_->checkBox_stereo->isChecked() || ui_->doubleSpinBox_baseline->value() != 0.0))
{
// basic
valid = true;
}
else if(ui_->comboBox_advanced->currentIndex() == 1 &&
ui_->doubleSpinBox_fx_l->value() > 0.0 &&
ui_->doubleSpinBox_fy_l->value() > 0.0 &&
ui_->doubleSpinBox_cx_l->value() > 0.0 &&
ui_->doubleSpinBox_cy_l->value() > 0.0 &&
(!ui_->checkBox_stereo->isChecked() || ui_->doubleSpinBox_fx_r->value() > 0.0) &&
(!ui_->checkBox_stereo->isChecked() || ui_->doubleSpinBox_fy_r->value() > 0.0) &&
(!ui_->checkBox_stereo->isChecked() || ui_->doubleSpinBox_cx_r->value() > 0.0) &&
(!ui_->checkBox_stereo->isChecked() || ui_->doubleSpinBox_cy_r->value() > 0.0) &&
ui_->spinBox_width->value() > 0 &&
ui_->spinBox_height->value() > 0 &&
!ui_->lineEdit_D_l->text().isEmpty() &&
(!ui_->checkBox_stereo->isChecked() || !ui_->lineEdit_D_r->text().isEmpty()) &&
(!ui_->checkBox_stereo->isChecked() || !ui_->lineEdit_RT->text().isEmpty()))
{
//advanced
QStringList distorsionsStrListL = ui_->lineEdit_D_l->text().trimmed().split(' ');
QStringList distorsionsStrListR = ui_->lineEdit_D_r->text().trimmed().split(' ');
if((distorsionsStrListL.size() == 4 || distorsionsStrListL.size() == 5 || distorsionsStrListL.size() == 8) &&
(!ui_->checkBox_stereo->isChecked() || distorsionsStrListL.size() == 4 || distorsionsStrListL.size() == 5 || distorsionsStrListL.size() == 8) &&
(!ui_->checkBox_stereo->isChecked() || Transform::canParseString(ui_->lineEdit_RT->text().trimmed().toStdString())))
{
valid = true;
}
}
ui_->buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
}
void CreateSimpleCalibrationDialog::saveCalibration()
{
if(ui_->doubleSpinBox_baseline->value()==0)
QString filePath = QFileDialog::getSaveFileName(this, tr("Save"), savingFolder_+"/"+cameraName_+".yaml", "*.yaml");
QString name = QFileInfo(filePath).baseName();
QString dir = QFileInfo(filePath).absoluteDir().absolutePath();
if(!filePath.isEmpty())
{
QString filePath = QFileDialog::getSaveFileName(this, tr("Save"), savingFolder_+"/"+cameraName_+".yaml", "*.yaml");
QString name = QFileInfo(filePath).baseName();
QString dir = QFileInfo(filePath).absoluteDir().absolutePath();
if(!filePath.isEmpty())
cameraName_ = name;
CameraModel modelLeft;
float width = ui_->spinBox_width->value();
float height = ui_->spinBox_height->value();
if(ui_->comboBox_advanced->currentIndex() == 0)
{
cameraName_ = name;
CameraModel model(
//basic
modelLeft = CameraModel(
name.toStdString(),
ui_->doubleSpinBox_fx->value(),
ui_->doubleSpinBox_fy->value(),
ui_->doubleSpinBox_cx->value(),
ui_->doubleSpinBox_cy->value());
UASSERT(model.isValid());
if(model.save(dir.toStdString()))
UASSERT(modelLeft.isValid());
}
else
{
//advanced
cv::Mat K = cv::Mat::eye(3, 3, CV_64FC1);
K.at<double>(0,0) = ui_->doubleSpinBox_fx_l->value();
K.at<double>(1,1) = ui_->doubleSpinBox_fy_l->value();
K.at<double>(0,2) = ui_->doubleSpinBox_cx_l->value();
K.at<double>(1,2) = ui_->doubleSpinBox_cy_l->value();
cv::Mat R = cv::Mat::eye(3, 3, CV_64FC1);
cv::Mat P = cv::Mat::zeros(3, 4, CV_64FC1);
K.copyTo(cv::Mat(P, cv::Range(0,3), cv::Range(0,3)));
QStringList distorsionCoeffs = ui_->lineEdit_D_l->text().trimmed().split(' ');
UASSERT(distorsionCoeffs.size() == 4 || distorsionCoeffs.size() == 5 || distorsionCoeffs.size() == 8);
cv::Mat D = cv::Mat::zeros(1, distorsionCoeffs.size(), CV_64FC1);
bool ok;
for(int i=0; i<distorsionCoeffs.size(); ++i)
{
D.at<double>(i) = distorsionCoeffs.at(i).toDouble(&ok);
if(!ok)
{
QMessageBox::warning(this, tr("Save"), tr("Error parsing left distorsion coefficients \"%1\".").arg(ui_->lineEdit_D_l->text()));
return;
}
}
modelLeft = CameraModel(name.toStdString(), cv::Size(width,height), K, D, R, P);
UASSERT(modelLeft.isValidForRectification());
}
if(ui_->checkBox_stereo->isChecked())
{
StereoCameraModel stereoModel;
if(ui_->comboBox_advanced->currentIndex() == 0)
{
CameraModel modelRight(
name.toStdString(),
ui_->doubleSpinBox_fx->value(),
ui_->doubleSpinBox_fy->value(),
ui_->doubleSpinBox_cx->value(),
ui_->doubleSpinBox_cy->value(),
Transform::getIdentity(),
ui_->doubleSpinBox_baseline->value()*-ui_->doubleSpinBox_fx->value());
UASSERT(modelRight.isValid());
stereoModel = StereoCameraModel(name.toStdString(), modelLeft, modelRight, Transform());
}
else if(ui_->comboBox_advanced->currentIndex() == 1)
{
CameraModel modelRight;
cv::Mat K = cv::Mat::eye(3, 3, CV_64FC1);
K.at<double>(0,0) = ui_->doubleSpinBox_fx_r->value();
K.at<double>(1,1) = ui_->doubleSpinBox_fy_r->value();
K.at<double>(0,2) = ui_->doubleSpinBox_cx_r->value();
K.at<double>(1,2) = ui_->doubleSpinBox_cy_r->value();
cv::Mat R = cv::Mat::eye(3, 3, CV_64FC1);
cv::Mat P = cv::Mat::zeros(3, 4, CV_64FC1);
K.copyTo(cv::Mat(P, cv::Range(0,3), cv::Range(0,3)));
QStringList distorsionCoeffs = ui_->lineEdit_D_r->text().trimmed().split(' ');
UASSERT(distorsionCoeffs.size() == 4 || distorsionCoeffs.size() == 5 || distorsionCoeffs.size() == 8);
cv::Mat D = cv::Mat::zeros(1, distorsionCoeffs.size(), CV_64FC1);
bool ok;
for(int i=0; i<distorsionCoeffs.size(); ++i)
{
D.at<double>(i) = distorsionCoeffs.at(i).toDouble(&ok);
if(!ok)
{
QMessageBox::warning(this, tr("Save"), tr("Error parsing right distorsion coefficients \"%1\".").arg(ui_->lineEdit_D_l->text()));
return;
}
}
modelRight = CameraModel(name.toStdString(), cv::Size(width,height), K, D, R, P);
UASSERT(modelRight.isValidForRectification());
UASSERT(Transform::canParseString(ui_->lineEdit_RT->text().trimmed().toStdString()));
stereoModel = StereoCameraModel(name.toStdString(), modelLeft, modelRight, Transform::fromString(ui_->lineEdit_RT->text().toStdString()));
}
std::string base = (dir+QDir::separator()+name).toStdString();
std::string leftPath = base+"_left.yaml";
std::string rightPath = base+"_right.yaml";
if(stereoModel.save(dir.toStdString(), ui_->comboBox_advanced->currentIndex() != 1))
{
if(ui_->comboBox_advanced->currentIndex() == 0)
{
QMessageBox::information(this, tr("Save"), tr("Calibration files saved:\n \"%1\"\n \"%2\".").
arg(leftPath.c_str()).arg(rightPath.c_str()));
}
else
{
std::string posePath = base+"_pose.yaml";
QMessageBox::information(this, tr("Save"), tr("Calibration files saved:\n \"%1\"\n \"%2\"\n \"%3\".").
arg(leftPath.c_str()).arg(rightPath.c_str()).arg(posePath.c_str()));
}
this->accept();
}
else
{
QMessageBox::warning(this, tr("Save"), tr("Error saving \"%1\" and \"%2\"").arg(leftPath.c_str()).arg(rightPath.c_str()));
}
}
else
{
if(modelLeft.save(dir.toStdString()))
{
QMessageBox::information(this, tr("Save"), tr("Calibration file saved to \"%1\".").arg(filePath));
this->accept();
@@ -96,42 +289,6 @@ void CreateSimpleCalibrationDialog::saveCalibration()
}
}
}
else
{
QString filePath = QFileDialog::getSaveFileName(this, tr("Save"), savingFolder_ + "/" + cameraName_, "*.yaml");
QString name = QFileInfo(filePath).baseName();
QString dir = QFileInfo(filePath).absoluteDir().absolutePath();
if(!name.isEmpty())
{
cameraName_ = name;
std::string base = (dir+QDir::separator()+name).toStdString();
std::string leftPath = base+"_left.yaml";
std::string rightPath = base+"_right.yaml";
std::string posePath = base+"_pose.yaml";
StereoCameraModel model(
name.toStdString(),
ui_->doubleSpinBox_fx->value(),
ui_->doubleSpinBox_fy->value(),
ui_->doubleSpinBox_cx->value(),
ui_->doubleSpinBox_cy->value(),
ui_->doubleSpinBox_baseline->value());
UASSERT(model.left().isValid() &&
model.right().isValid()&&
model.baseline() > 0.0);
if(model.save(dir.toStdString(), true))
{
QMessageBox::information(this, tr("Save"), tr("Calibration files saved:\n \"%1\"\n \"%2\"\n \"%3\".").
arg(leftPath.c_str()).arg(rightPath.c_str()).arg(posePath.c_str()));
this->accept();
}
else
{
QMessageBox::warning(this, tr("Save"), tr("Error saving \"%1\" and \"%2\"").arg(leftPath.c_str()).arg(rightPath.c_str()));
}
}
}
}
}