Skip to content

Commit

Permalink
specify calibration file for vIPT (#136)
Browse files Browse the repository at this point in the history
* Update printing calibration file content.

* use absolute path to find vIPT calibration file

*updated vPreProcess and vFramer to use this new method

Co-authored-by: arrenglover <arren.glover@iit.it>
  • Loading branch information
lunagava and arrenglover authored May 3, 2021
1 parent 6cd11fd commit ff93edf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/include/event-driven/vIPT.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define VIPT_H

#include <opencv2/opencv.hpp>
#include <yarp/os/Bottle.h>
#include <yarp/os/all.h>

namespace ev {

Expand Down Expand Up @@ -51,12 +51,12 @@ class vIPT {

vIPT();


const cv::Mat& getQ();
void setProjectedImageSize(int height, int width);
bool configure(const std::string calibContext, const std::string calibFile, int size_scaler = 2);
bool configure(const std::string &calib_file_path, int size_scaler = 2);
bool showMapProjections(double seconds = 0);
void showMonoProjections(int cam, double seconds);
void printValidCalibrationValues();

bool sparseForwardTransform(int cam, int &y, int &x);
bool sparseReverseTransform(int cam, int &y, int &x);
Expand Down
37 changes: 33 additions & 4 deletions lib/src/vIPT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ vIPT::vIPT()

bool vIPT::importIntrinsics(int cam, Bottle &parameters)
{

if(parameters.isNull()) {
yWarning() << "Could not find camera" << cam <<"parameters";
return false;
Expand Down Expand Up @@ -161,15 +162,14 @@ const cv::Mat& vIPT::getQ(){
return Q;
}

bool vIPT::configure(const string calibContext, const string calibFile, int size_scaler)
bool vIPT::configure(const string &calib_file_path, int size_scaler)

{
ResourceFinder calibfinder;
calibfinder.setVerbose();
calibfinder.setDefaultContext(calibContext);
calibfinder.setDefaultConfigFile(calibFile);
calibfinder.setDefault("from", calib_file_path);
calibfinder.configure(0, 0);


//import intrinsics
bool valid_cam1 = importIntrinsics(0, calibfinder.findGroup("CAMERA_CALIBRATION_LEFT"));
bool valid_cam2 = importIntrinsics(1, calibfinder.findGroup("CAMERA_CALIBRATION_RIGHT"));
Expand Down Expand Up @@ -357,6 +357,35 @@ bool vIPT::showMapProjections(double seconds)
return true;
}

void vIPT::printValidCalibrationValues()
{
yInfo() << "Printing non-empty intrinsic and extrinsic parameters:";
std::stringstream ss;
for(auto i : {0, 1}) {
if(!size_cam[i].empty()) {
ss << "size_cam[" << i << "]" << std::endl;
ss << size_cam[i] << std::endl; yInfo() << ss.str(); ss.str("");
}
if(!cam_matrix[i].empty()) {
ss << "cam_matrix[" << i << "]" << std::endl;
ss << cam_matrix[i] << std::endl; yInfo() << ss.str(); ss.str("");
}
if(!dist_coeff[i].empty()) {
ss << "dist_coeff[" << i << "]" << std::endl;
ss << dist_coeff[i] << std::endl; yInfo() << ss.str(); ss.str("");
}
}

if(!stereo_translation.empty()) {
ss << "stereo_translation" << std::endl;
ss << stereo_translation << std::endl; yInfo() << ss.str(); ss.str("");
}
if(!stereo_rotation.empty()) {
ss << "stereo_rotation" << std::endl;
ss << stereo_rotation << std::endl; yInfo() << ss.str(); ss.str("");
}
}

bool vIPT::sparseForwardTransform(int cam, int &y, int &x)
{
cv::Vec2i p(y, x);
Expand Down
5 changes: 3 additions & 2 deletions src/processing/vFramer/include/vFramerLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class channelInstance : public RateThread {
public:

channelInstance(string channel_name, cv::Size render_size = cv::Size(-1, -1));
bool addFrameDrawer(unsigned int width, unsigned int height);
bool addFrameDrawer(unsigned int width, unsigned int height,
const std::string &calibration_file = "");
bool addDrawer(string drawer_name, unsigned int width,
unsigned int height, unsigned int window_size, double isoWindow, bool flip);

bool threadInit();
void run();
void threadRelease();
Expand Down
5 changes: 3 additions & 2 deletions src/processing/vFramer/src/vFramerLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ string channelInstance::getName()
return channel_name;
}

bool channelInstance::addFrameDrawer(unsigned int width, unsigned int height)
bool channelInstance::addFrameDrawer(unsigned int width, unsigned int height,
const std::string &calibration_file)
{
calib_configured = unwarp.configure("camera", "stefi_calib.ini");
calib_configured = unwarp.configure(calibration_file);
if(!calib_configured)
yWarning() << "Calibration was not configured";

Expand Down
13 changes: 9 additions & 4 deletions src/processing/vPreProcess/src/vPreProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ bool vPreProcess::configure(yarp::os::ResourceFinder &rf) {
yInfo() << "--sf_time <double>: spatial filter time window (sec)";
yInfo() << "--sf_size <int>: spatial filter (half) size (pixels)";
yInfo() << "--tf_time <double>: temporal filter time window (sec)";
yInfo() << "--camera_calibration_file <path>: calibration file to use for undistort";
return false;
}

Expand Down Expand Up @@ -188,10 +189,14 @@ bool vPreProcess::configure(yarp::os::ResourceFinder &rf) {

if(undistort) {

if(calibrator.configure("camera", "atis_calib.ini", 1))
calibrator.showMapProjections(3.0);
else
yWarning() << "Could not correctly configure the cameras";
std::string calib_file_path = rf.check("camera_calibration_file", Value("")).asString();
if(calibrator.configure(calib_file_path, 1)) {
calibrator.printValidCalibrationValues();
//calibrator.showMapProjections(3.0);
} else {
yError() << "Could not correctly configure the cameras";
return false;
}
}

if(vis) {
Expand Down

0 comments on commit ff93edf

Please sign in to comment.