10 #include <yarp/cv/Cv.h>
11 #include <iCub/SphericalCalibTool.h>
15 using namespace yarp::os;
16 using namespace yarp::sig;
17 using namespace yarp::cv;
22 _oldImgSize.width = -1;
23 _oldImgSize.height = -1;
32 return configure(config);
37 cvReleaseImage(&_mapX);
40 cvReleaseImage(&_mapY);
47 fprintf(stdout,
"There seem to be an error loading parameters \"%s\", stopping module\n", val.c_str());
53 _calibImgSize.width = config.check(
"w",
55 "Image width for which calibration parameters were calculated (int)").asInt32();
56 _calibImgSize.height = config.check(
"h",
58 "Image height for which calibration parameters were calculated (int)").asInt32();
59 _drawCenterCross = config.check(
"drawCenterCross",
61 "Draw a cross at calibration center (int [0|1]).").asInt32()!=0;
63 _fx = config.check(
"fx", Value(320.0),
"Focal distance (on horizontal pixel size units) (double)").asFloat64();
64 _fy = config.check(
"fy", Value(240.0),
"Focal distance (on vertical pixel size units) (double)").asFloat64();
65 _cx = config.check(
"cx", Value(320.0),
"Image center (on horizontal pixel size units) (double)").asFloat64();
66 _cy = config.check(
"cy", Value(240.0),
"Image center (on vertical pixel size units) (double)").asFloat64();
67 _k1 = config.check(
"k1", Value(0.0),
"Radial distortion (first parameter) (double)").asFloat64();
68 _k2 = config.check(
"k2", Value(0.0),
"Radial distortion (second parameter) (double)").asFloat64();
69 _p1 = config.check(
"p1", Value(0.0),
"Tangential distortion (first parameter) (double)").asFloat64();
70 _p2 = config.check(
"p2", Value(0.0),
"Tangential distortion (second parameter) (double)").asFloat64();
73 if ( !config.check(
"drawCenterCross") ) { stopConfig(
"drawCenterCross");
return false; }
74 if ( !config.check(
"w") ) { stopConfig(
"w");
return false;}
75 if ( !config.check(
"h") ) { stopConfig(
"h");
return false;}
76 if ( !config.check(
"fx") ) { stopConfig(
"fx");
return false;}
77 if ( !config.check(
"fy") ) { stopConfig(
"fy");
return false;}
78 if ( !config.check(
"cx") ) { stopConfig(
"cx");
return false;}
79 if ( !config.check(
"cy") ) { stopConfig(
"cy");
return false;}
80 if ( !config.check(
"k1") ) { stopConfig(
"k1");
return false;}
81 if ( !config.check(
"k2") ) { stopConfig(
"k2");
return false;}
82 if ( !config.check(
"p1") ) { stopConfig(
"p1");
return false;}
83 if ( !config.check(
"p2") ) { stopConfig(
"p2");
return false;}
96 bool SphericalCalibTool::init(CvSize currImgSize, CvSize calibImgSize){
99 cvReleaseImage(&_mapX);
102 cvReleaseImage(&_mapY);
109 if (currImgSize.width != calibImgSize.width ||
110 currImgSize.height != calibImgSize.height){
111 float scaleX = (float)currImgSize.width / (
float)calibImgSize.width;
112 float scaleY = (float)currImgSize.height / (
float)calibImgSize.height;
113 _fx_scaled = _fx * scaleX;
114 _fy_scaled = _fy * scaleY;
115 _cx_scaled = _cx * scaleX;
116 _cy_scaled = _cy * scaleY;
125 _mapX = cvCreateImage(currImgSize, IPL_DEPTH_32F, 1);
126 _mapY = cvCreateImage(currImgSize, IPL_DEPTH_32F, 1);
131 currImgSize.height, currImgSize.width,
132 _fx_scaled, _fy_scaled, _cx_scaled, _cy_scaled,
134 (
float*)_mapX->imageData, (
float*)_mapY->imageData))
143 CvSize inSize = cvSize(in.width(),in.height());
146 if ( inSize.width != _oldImgSize.width ||
147 inSize.height != _oldImgSize.height ||
149 init(inSize,_calibImgSize);
151 out.resize(inSize.width, inSize.height);
153 cv::Mat outMat=toCvMat(
out);
154 cv::remap( toCvMat(
const_cast<ImageOf<PixelRgb>&
>(in)), outMat,
155 cv::cvarrToMat(_mapX), cv::cvarrToMat(_mapY),
157 out=fromCvMat<PixelRgb>(outMat);
160 if (_drawCenterCross){
161 yarp::sig::PixelRgb pix = yarp::sig::PixelRgb(255,255,255);
162 yarp::sig::draw::addCrossHair(
out, pix, (
int)_cx_scaled, (
int)_cy_scaled, 10);
166 _oldImgSize.width = inSize.width;
167 _oldImgSize.height = inSize.height;
bool compute_sp_map(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double k1, double k2, double p1, double p2, float *mapx, float *mapy)