9#include <iCub/CamCalibModule.h>
12using namespace yarp::os;
13using namespace yarp::sig;
26 portImgOut=_portImgOut;
35void CamCalibPort::onRead(ImageOf<PixelRgb> &yrpImgIn)
41 yarp::sig::ImageOf<PixelRgb> &yrpImgOut=portImgOut->prepare();
44 yDebug(
"received input image after %g [s] ... ",t-t0);
46 double t1=Time::now();
50 calibTool->
apply(yrpImgIn,yrpImgOut);
52 for (
int r =0; r <yrpImgOut.height(); r++)
54 for (
int c=0; c<yrpImgOut.width(); c++)
56 unsigned char *pixel = yrpImgOut.getPixelAddress(c,r);
57 double mean = (1.0/3.0)*(pixel[0]+pixel[1]+pixel[2]);
59 for(
int i=0; i<3; i++)
61 double s=pixel[i]-mean;
70 pixel[i]=(
unsigned char)sn;
76 yDebug(
"calibrated in %g [s]\n",Time::now()-t1);
83 yDebug(
"just copied in %g [s]\n",Time::now()-t1);
87 yarp::os::Stamp stamp;
88 BufferedPort<ImageOf<PixelRgb> >::getEnvelope(stamp);
89 portImgOut->setEnvelope(stamp);
91 portImgOut->writeStrict();
108 string str = rf.check(
"name", Value(
"/camCalib"),
"module name (string)").asString();
109 setName(str.c_str());
112 Bottle botConfig(rf.toString());
115 if(botConfig.check(
"group", valGroup,
"Configuration group to load module options from (string)."))
117 string strGroup = valGroup->asString();
119 if (botConfig.check(strGroup)){
120 Bottle &group=botConfig.findGroup(strGroup,
"Loading configuration from group " + strGroup);
121 botConfig.fromString(group.toString());
124 yError() <<
"Group " << strGroup <<
" not found.";
130 yError (
"There seem to be an error loading parameters (group section missing), stopping module");
134 string calibToolName = botConfig.check(
"projection",
136 "Projection/mapping applied to calibrated image [pinhole|spherical] (string).").asString();
139 if (_calibTool!=NULL) {
140 bool ok = _calibTool->
open(botConfig);
148 if (yarp::os::Network::exists(getName(
"/in")))
150 yWarning() <<
"port " << getName(
"/in") <<
" already in use";
152 if (yarp::os::Network::exists(getName(
"/out")))
154 yWarning() <<
"port " << getName(
"/out") <<
" already in use";
156 if (yarp::os::Network::exists(getName(
"/conf")))
158 yWarning() <<
"port " << getName(
"/conf") <<
" already in use";
160 _prtImgIn.
setSaturation(rf.check(
"saturation",Value(1.0)).asFloat64());
161 _prtImgIn.open(getName(
"/in"));
164 _prtImgIn.useCallback();
165 _prtImgOut.open(getName(
"/out"));
166 _configPort.open(getName(
"/conf"));
178 if (_calibTool != NULL){
187 _prtImgIn.interrupt();
188 _prtImgOut.interrupt();
189 _configPort.interrupt();
205 if (command.get(0).asString()==
"quit")
207 reply.addString(
"quitting");
210 else if (command.get(0).asString()==
"sat" || command.get(0).asString()==
"saturation")
212 double satVal = command.get(1).asFloat64();
215 reply.addString(
"ok");
219 yError() <<
"command not known - type help for more info";
virtual bool interruptModule()
virtual bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
virtual bool configure(yarp::os::ResourceFinder &rf)
Passes config on to CalibTool.
virtual bool updateModule()
virtual double getPeriod()
void setSaturation(double satVal)
void setVerbose(const bool sw)
void setPointers(yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > *_portImgOut, ICalibTool *_calibTool)