Skip to content
Snippets Groups Projects
Commit 5291fd0c authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

save calibration input to file

parent 576f2fab
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28489 failed
......@@ -412,6 +412,10 @@ public:
void updateCalibration(int c);
void updateCalibration();
/** debug methods */
void saveInput(const std::string& filename);
void loadInput(const std::string& filename);
ftl::calibration::CalibrationData::Calibration calibration(int camera);
void setOptions(ftl::calibration::BundleAdjustment::Options options) { state_.calib.setOptions(options); }
......
......@@ -292,6 +292,14 @@ void ExtrinsicCalibration::stereoRectify(int cl, int cr,
state_.maps2[cr].upload(map2);
}
void ExtrinsicCalibration::saveInput(const std::string& filename) {
state_.calib.points().toFile(filename);
}
void ExtrinsicCalibration::loadInput(const std::string& filename) {
state_.calib.points().fromFile(filename);
}
void ExtrinsicCalibration::run() {
if (running_.exchange(true)) { return; }
......
......@@ -157,6 +157,9 @@ private:
ExtrinsicCalibrationView* view_;
ExtrinsicCalibration* ctrl_;
nanogui::Button* bsave_;
nanogui::Button* bupload_;
nanogui::Button* bcalibrate_;
nanogui::Button* bpause_;
nanogui::Button* bresults_;
......@@ -175,6 +178,26 @@ ExtrinsicCalibrationView::ControlWindow::ControlWindow(nanogui::Widget* parent,
buttons->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Horizontal, nanogui::Alignment::Middle, 0, 0));
bsave_ = new nanogui::Button(buttons, "", ENTYPO_ICON_SAVE);
bsave_->setTooltip("Save input to file (Debug)");
bsave_->setCallback([this](){
ctrl_->saveInput("./calib.bin");
});
bsave_ = new nanogui::Button(buttons, "", ENTYPO_ICON_FOLDER);
bsave_->setTooltip("Load input from file (Debug)");
bsave_->setCallback([this](){
ctrl_->loadInput("./calib.bin");
});
bupload_ = new nanogui::Button(buttons, "", ENTYPO_ICON_UPLOAD);
bupload_->setTooltip("Save input to sources");
bupload_->setCallback([this](){
ctrl_->save();
bupload_->setTextColor(nanogui::Color(32, 192, 32, 255));
bupload_->setEnabled(false);
});
bresults_ = new nanogui::Button(buttons, "Show Calibration");
//bresults_->setEnabled(ctrl_->calib().calibrated());
bresults_->setCallback([view = view_, button = bresults_]{
......@@ -265,24 +288,30 @@ void ExtrinsicCalibrationView::CalibrationWindow::build() {
opts.optimize_intrinsic = !v;
});
auto* ff = new nanogui::CheckBox(wfreeze, "Focal length");
auto* ff = new nanogui::CheckBox(wfreeze, "Fix focal length");
ff->setChecked(opts_.fix_focal);
ff->setCallback([&opts = opts_](bool v) {
opts.fix_focal = v;
});
auto* fpp = new nanogui::CheckBox(wfreeze, "Principal point");
auto* fpp = new nanogui::CheckBox(wfreeze, "Fix principal point");
fpp->setChecked(opts_.fix_principal_point);
fpp->setCallback([&opts = opts_](bool v) {
opts.fix_principal_point = v;
});
auto* fdist = new nanogui::CheckBox(wfreeze, "Distortion coefficients");
auto* fdist = new nanogui::CheckBox(wfreeze, "Fix distortion coefficients");
fdist->setChecked(opts_.fix_distortion);
fdist->setCallback([&opts = opts_](bool v) {
opts.fix_distortion = v;
});
auto* fzdist = new nanogui::CheckBox(wfreeze, "Assume zero distortion");
/*fzdist->setChecked(opts_.fix_distortion);
fzdist->setCallback([&opts = opts_](bool v) {
opts.fix_distortion = v;
});*/
fall->setCallback([wfreeze](bool value){
for (int i = 2; i < wfreeze->childCount(); i++) {
wfreeze->childAt(i)->setEnabled(!value);
......
......@@ -95,7 +95,9 @@ public:
/** Get all points. See Points struct. */
const std::vector<Points>& all() { return points_; }
bool toFile(const std::string& fname);
bool fromFile(const std::string& fname);
protected:
bool hasCamera(unsigned int c);
......
......@@ -4,6 +4,9 @@
#include <ftl/calibration/optimize.hpp>
#include <ftl/calibration/extrinsic.hpp>
#include <fstream>
#include <sstream>
#include <opencv2/calib3d.hpp>
////////////////////////////////////////////////////////////////////////////////
......@@ -228,6 +231,25 @@ std::vector<cv::Point3_<T>> CalibrationPoints<T>::getObject(unsigned int object)
return objects_[object];
}
template<typename T>
bool CalibrationPoints<T>::toFile(const std::string& fname) {
std::ofstream ofs(fname);
msgpack::pack(ofs, *this);
ofs.close();
return true;
}
template<typename T>
bool CalibrationPoints<T>::fromFile(const std::string& fname) {
resetTriangulatedPoints();
std::ifstream ifs(fname);
std::stringstream buf;
buf << ifs.rdbuf();
msgpack::object_handle oh = msgpack::unpack(buf.str().data(), buf.str().size());
oh.get().convert(*this);
return true;
}
template class CalibrationPoints<float>;
template class CalibrationPoints<double>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment