Skip to content
Snippets Groups Projects
Commit c971d703 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Potentially working calibration code

parent 5a25f2ba
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ endif (WIN32)
if (UNIX)
add_definitions(-DUNIX)
set(FTL_CONFIG_ROOT "$ENV{HOME}/.config/ftl")
set(FTL_CONFIG_ROOT "\"$ENV{HOME}/.config/ftl\"")
set(FTL_CACHE_ROOT "$ENV{HOME}/.cache/ftl")
set(FTL_DATA_ROOT "$ENV{HOME}/.local/share/ftl")
endif (UNIX)
......
......@@ -4,13 +4,70 @@
#include <opencv2/opencv.hpp>
#include <ftl/local.hpp>
#include <string>
#include <vector>
namespace cv {
class FileStorage;
class FileNode;
};
namespace ftl {
class Calibrate {
public:
class Settings {
public:
Settings() : goodInput(false) {}
enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };
enum InputType { INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST };
void write(cv::FileStorage& fs) const;
void read(const cv::FileNode& node);
void validate();
//Mat nextImage();
static bool readStringList( const std::string& filename, std::vector<std::string>& l );
static bool isListOfImages( const std::string& filename);
public:
cv::Size boardSize; // The size of the board -> Number of items by width and height
Pattern calibrationPattern; // One of the Chessboard, circles, or asymmetric circle pattern
float squareSize; // The size of a square in your defined unit (point, millimeter,etc).
int nrFrames; // The number of frames to use from the input for calibration
float aspectRatio; // The aspect ratio
int delay; // In case of a video input
bool writePoints; // Write detected feature points
bool writeExtrinsics; // Write extrinsic parameters
bool writeGrid; // Write refined 3D target grid points
bool calibZeroTangentDist; // Assume zero tangential distortion
bool calibFixPrincipalPoint; // Fix the principal point at the center
bool flipVertical; // Flip the captured images around the horizontal axis
std::string outputFileName; // The name of the file where to write
bool showUndistorsed; // Show undistorted images after calibration
std::string input; // The input ->
bool useFisheye; // use fisheye camera model for calibration
bool fixK1; // fix K1 distortion coefficient
bool fixK2; // fix K2 distortion coefficient
bool fixK3; // fix K3 distortion coefficient
bool fixK4; // fix K4 distortion coefficient
bool fixK5; // fix K5 distortion coefficient
int cameraID;
std::vector<std::string> imageList;
size_t atImageList;
//cv::VideoCapture inputCapture;
InputType inputType;
bool goodInput;
int flag;
private:
std::string patternToUse;
};
public:
Calibrate(ftl::LocalSource *s, const std::string &cal);
bool recalibrate(const std::string &conf);
bool recalibrate();
bool undistort(cv::Mat &l, cv::Mat &r);
bool rectified(cv::Mat &l, cv::Mat &r);
......@@ -19,11 +76,25 @@ class Calibrate {
private:
bool runCalibration(cv::Mat &img, cv::Mat &cam);
bool _recalibrate(size_t cam);
cv::Mat _nextImage(size_t cam);
private:
ftl::LocalSource *local_;
Settings settings_;
bool calibrated_;
std::vector<cv::Mat> map1_;
std::vector<cv::Mat> map2_;
};
};
/*static inline void read(const cv::FileNode& node, ftl::Calibrate::Settings& x, const ftl::Calibrate::Settings& default_value = ftl::Calibrate::Settings())
{
if(node.empty())
x = default_value;
else
x.read(node);
}*/
#endif // _FTL_CALIBRATION_HPP_
......@@ -14,8 +14,8 @@ class LocalSource {
LocalSource();
LocalSource(const std::string &vid);
//bool left(cv::Mat &m);
//bool right(cv::Mat &m);
bool left(cv::Mat &m);
bool right(cv::Mat &m);
bool get(cv::Mat &l, cv::Mat &r);
//void setFramerate(float fps);
......
This diff is collapsed.
......@@ -68,6 +68,67 @@ LocalSource::LocalSource(const string &vid): timestamp_(0.0) {
}
}
bool LocalSource::left(cv::Mat &l) {
if (!camera_a_) return false;
if (!camera_a_->grab()) {
LOG(ERROR) << "Unable to grab from camera A";
return false;
}
// Record timestamp
timestamp_ = duration_cast<duration<double>>(
high_resolution_clock::now().time_since_epoch()).count();
if (camera_b_ || !stereo_) {
if (!camera_a_->retrieve(l)) {
LOG(ERROR) << "Unable to read frame from camera A";
return false;
}
} else {
Mat frame;
if (!camera_a_->retrieve(frame)) {
LOG(ERROR) << "Unable to read frame from video";
return false;
}
int resx = frame.cols / 2;
l = Mat(frame, Rect(0,0,resx,frame.rows));
}
return true;
}
bool LocalSource::right(cv::Mat &r) {
if (camera_b_ && !camera_b_->grab()) {
LOG(ERROR) << "Unable to grab from camera B";
return false;
}
// Record timestamp
timestamp_ = duration_cast<duration<double>>(
high_resolution_clock::now().time_since_epoch()).count();
if (camera_b_ || !stereo_) {
if (camera_b_ && !camera_b_->retrieve(r)) {
LOG(ERROR) << "Unable to read frame from camera B";
return false;
}
} else {
Mat frame;
if (!camera_a_) return false;
if (!camera_a_->retrieve(frame)) {
LOG(ERROR) << "Unable to read frame from video";
return false;
}
int resx = frame.cols / 2;
r = Mat(frame, Rect(resx,0,frame.cols-resx,frame.rows));
}
return true;
}
bool LocalSource::get(cv::Mat &l, cv::Mat &r) {
if (!camera_a_) return false;
......@@ -102,7 +163,7 @@ bool LocalSource::get(cv::Mat &l, cv::Mat &r) {
int resx = frame.cols / 2;
l = Mat(frame, Rect(0,0,resx,frame.rows));
r = Mat(frame, Rect(resx,0,frame.cols,frame.rows));
r = Mat(frame, Rect(resx,0,frame.cols-resx,frame.rows));
}
return true;
......
......@@ -13,7 +13,7 @@ using cv::Mat;
static vector<string> OPTION_peers;
static vector<string> OPTION_channels;
static string OPTION_calibration_config;
static string OPTION_calibration_config = FTL_CONFIG_ROOT "/calibration.xml";
static string OPTION_config;
static bool OPTION_display = false;
static bool OPTION_calibrate = false;
......@@ -73,6 +73,8 @@ int main(int argc, char **argv) {
Calibrate calibrate(lsrc, OPTION_calibration_config);
if (!calibrate.isCalibrated()) calibrate.recalibrate();
while (true) {
Mat l, r;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment