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

All force no stereo

parent b9af9f0f
No related branches found
No related tags found
No related merge requests found
......@@ -11,8 +11,8 @@ namespace cv {
namespace ftl {
class LocalSource {
public:
LocalSource(bool flip=false);
LocalSource(const std::string &vid, bool flip=false);
LocalSource(bool flip=false, bool nostereo=false);
LocalSource(const std::string &vid, bool flip=false, bool nostereo=false);
bool left(cv::Mat &m);
bool right(cv::Mat &m);
......@@ -30,6 +30,7 @@ class LocalSource {
bool stereo_;
//float fps_;
bool flip_;
bool nostereo_;
cv::VideoCapture *camera_a_;
cv::VideoCapture *camera_b_;
};
......
......@@ -321,15 +321,18 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
//view = _nextImage(cam);
LOG(INFO) << "Grabbing calibration image...";
if (view[0].empty() || view[1].empty() || imagePoints[0].size() >= (size_t)settings_.nrFrames) {
if (view[0].empty() || (local_->isStereo() && view[1].empty()) || imagePoints[0].size() >= (size_t)settings_.nrFrames) {
settings_.outputFileName = FTL_CONFIG_ROOT "/cam0.xml";
bool r = runCalibrationAndSave(settings_, imageSize[0],
cameraMatrix[0], distCoeffs[0], imagePoints[0],
grid_width, release_object);
settings_.outputFileName = FTL_CONFIG_ROOT "/cam1.xml";
r &= runCalibrationAndSave(settings_, imageSize[1],
cameraMatrix[1], distCoeffs[1], imagePoints[1],
grid_width, release_object);
if (local_->isStereo()) {
settings_.outputFileName = FTL_CONFIG_ROOT "/cam1.xml";
r &= runCalibrationAndSave(settings_, imageSize[1],
cameraMatrix[1], distCoeffs[1], imagePoints[1],
grid_width, release_object);
}
if (!r && view[0].empty()) {
LOG(ERROR) << "Not enough frames to calibrate";
......@@ -351,7 +354,7 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
bool found1,found2;
found1 = findChessboardCorners( view[0], settings_.boardSize, pointBuf[0], chessBoardFlags);
found2 = findChessboardCorners( view[1], settings_.boardSize, pointBuf[1], chessBoardFlags);
found2 = !local_->isStereo() || findChessboardCorners( view[1], settings_.boardSize, pointBuf[1], chessBoardFlags);
if (found1 && found2) // If done with success,
{
......@@ -360,23 +363,25 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints,
cvtColor(view[0], viewGray, COLOR_BGR2GRAY);
cornerSubPix( viewGray, pointBuf[0], Size(winSize,winSize),
Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 ));
imagePoints[0].push_back(pointBuf[0]);
if (local_->isStereo()) {
cvtColor(view[1], viewGray, COLOR_BGR2GRAY);
cornerSubPix( viewGray, pointBuf[1], Size(winSize,winSize),
Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.0001 ));
imagePoints[0].push_back(pointBuf[0]);
imagePoints[1].push_back(pointBuf[1]);
imagePoints[1].push_back(pointBuf[1]);
}
// Draw the corners.
drawChessboardCorners( view[0], settings_.boardSize, Mat(pointBuf[0]), found1 );
drawChessboardCorners( view[1], settings_.boardSize, Mat(pointBuf[1]), found2 );
if (local_->isStereo()) drawChessboardCorners( view[1], settings_.boardSize, Mat(pointBuf[1]), found2 );
} else {
LOG(WARNING) << "No calibration pattern found";
}
imshow("Left", view[0]);
imshow("Right", view[1]);
if (local_->isStereo()) imshow("Right", view[1]);
char key = (char)waitKey(settings_.delay);
if( key == 27 )
......
......@@ -13,22 +13,23 @@ using cv::Rect;
using std::string;
using namespace std::chrono;
LocalSource::LocalSource(bool flip) : timestamp_(0.0), flip_(flip) {
LocalSource::LocalSource(bool flip, bool nostereo) : timestamp_(0.0), flip_(flip), nostereo_(nostereo) {
// Use cameras
camera_a_ = new VideoCapture((flip) ? 1 : 0);
camera_b_ = new VideoCapture((flip) ? 0 : 1);
if (!nostereo) camera_b_ = new VideoCapture((flip) ? 0 : 1);
else camera_b_ = nullptr;
if (!camera_a_->isOpened()) {
delete camera_a_;
delete camera_b_;
if (camera_b_) delete camera_b_;
camera_a_ = nullptr;
camera_b_ = nullptr;
LOG(FATAL) << "No cameras found";
return;
}
if (!camera_b_->isOpened()) {
delete camera_b_;
if (!camera_b_ || !camera_b_->isOpened()) {
if (camera_b_) delete camera_b_;
camera_b_ = nullptr;
stereo_ = false;
LOG(WARNING) << "Not able to find second camera for stereo";
......@@ -37,7 +38,7 @@ LocalSource::LocalSource(bool flip) : timestamp_(0.0), flip_(flip) {
}
}
LocalSource::LocalSource(const string &vid, bool flip): timestamp_(0.0), flip_(flip) {
LocalSource::LocalSource(const string &vid, bool flip, bool nostereo): timestamp_(0.0), flip_(flip), nostereo_(nostereo) {
if (vid == "") {
LOG(FATAL) << "No video file specified";
camera_a_ = nullptr;
......@@ -191,6 +192,6 @@ double LocalSource::getTimestamp() const {
}
bool LocalSource::isStereo() const {
return stereo_;
return stereo_ && !nostereo_;
}
......@@ -20,6 +20,7 @@ static string OPTION_config;
static bool OPTION_display = false;
static bool OPTION_calibrate = false;
static bool OPTION_flip = false;
static bool OPTION_nostereo = false;
void handle_options(char ***argv, int *argc) {
while (*argc > 0) {
......@@ -44,6 +45,8 @@ void handle_options(char ***argv, int *argc) {
OPTION_display = true;
} else if (cmd.find("--flip") == 0) {
OPTION_flip = true;
} else if (cmd.find("--no-stereo") == 0) {
OPTION_nostereo = true;
}
(*argc)--;
......@@ -64,10 +67,10 @@ int main(int argc, char **argv) {
if (argc) {
// Load video file
lsrc = new LocalSource(argv[0], OPTION_flip);
lsrc = new LocalSource(argv[0], OPTION_flip, OPTION_nostereo);
} else {
// Use cameras
lsrc = new LocalSource(OPTION_flip);
lsrc = new LocalSource(OPTION_flip, OPTION_nostereo);
}
auto sync = new SyncSource(); // TODO Pass protocol object
......@@ -108,7 +111,7 @@ int main(int argc, char **argv) {
cv::imshow("Left",l);
if (lsrc->isStereo()) cv::imshow("Right",r);
if(cv::waitKey(10000) == 27){
if(cv::waitKey(100) == 27){
//exit if ESC is pressed
break;
}
......
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