22 : DepthCameraPlugin(), lastImage(NULL)
41 DepthCameraPlugin::Load(_sensor, _sdf);
45 this->
width_ = this->width;
47 this->
depth_ = this->depth;
49 this->
camera_ = this->depthCamera;
53 catch(gazebo::common::Exception &_e)
55 gzerr <<
"Error loading UnderwaterCameraROSPlugin" << std::endl;
61 gzerr <<
"Not loading UnderwaterCameraROSPlugin since ROS has not " 62 <<
" been properly initialized." << std::endl;
66 lastImage =
new unsigned char[this->width * this->height * this->depth];
69 GetSDFParam<float>(_sdf,
"attenuationR", this->
attenuation[0], 1.f / 30.f);
70 GetSDFParam<float>(_sdf,
"attenuationG", this->attenuation[1], 1.f / 30.f);
71 GetSDFParam<float>(_sdf,
"attenuationB", this->attenuation[2], 1.f / 30.f);
74 this->background[1] = (
unsigned char)0;
75 this->background[2] = (
unsigned char)0;
77 if (_sdf->HasElement(
"backgroundR"))
78 this->background[0] = (
unsigned char)_sdf->GetElement(
79 "backgroundR")->Get<
int>();
80 if (_sdf->HasElement(
"backgroundG"))
81 this->background[1] = (
unsigned char)_sdf->GetElement(
82 "backgroundG")->Get<
int>();
83 if (_sdf->HasElement(
"backgroundB"))
84 this->background[2] = (
unsigned char)_sdf->GetElement(
85 "backgroundB")->Get<
int>();
87 #if GAZEBO_MAJOR_VERSION >= 7 88 ignition::math::Angle hfov = ignition::math::Angle(this->depthCamera->HFOV().Radian());
89 ignition::math::Angle vfov = ignition::math::Angle(this->depthCamera->VFOV().Radian());
91 ignition::math::Angle hfov = this->depthCamera->GetHFOV();
92 ignition::math::Angle vfov = this->depthCamera->GetVFOV();
95 double fx = (0.5*this->width) / tan(0.5 * hfov.Radian());
96 double fy = (0.5*this->height) / tan(0.5 * vfov.Radian());
99 double cx = 0.5 * this->width;
100 double cy = 0.5 * this->height;
105 for (
int v = 0; v < this->height; v++)
107 double y_z = (v - cy)/fy;
108 for (
int u = 0; u < this->width; u++)
110 double x_z = (u - cx)/fx;
115 *(lutPtr++) = sqrt(1.0 + x_z*x_z + y_z*y_z);
122 unsigned int _width,
unsigned int _height,
unsigned int _depth,
123 const std::string &_format)
131 unsigned int _width,
unsigned int _height,
unsigned int _depth,
132 const std::string &_format)
137 unsigned int _width,
unsigned int _height,
unsigned int _depth,
138 const std::string& _format)
142 const cv::Mat input(_height, _width, CV_8UC3,
143 const_cast<unsigned char*>(_image));
144 const cv::Mat depth(_height, _width, CV_32FC1,
147 cv::Mat output(_height, _width, CV_8UC3,
lastImage);
154 #if GAZEBO_MAJOR_VERSION >= 7 160 if (!this->parentSensor->IsActive())
165 this->parentSensor->SetActive(
true);
177 const cv::Mat& _inputDepth, cv::Mat& _outputImage)
180 for (
unsigned int row = 0; row < this->height; row++)
182 const cv::Vec3b* inrow = _inputImage.ptr<cv::Vec3b>(row);
183 const float* depthrow = _inputDepth.ptr<
float>(row);
184 cv::Vec3b* outrow = _outputImage.ptr<cv::Vec3b>(row);
186 for (
int col = 0; col < this->width; col++)
189 float r = *(lutPtr++)*depthrow[col];
190 const cv::Vec3b& in = inrow[col];
191 cv::Vec3b& out = outrow[col];
196 for (
int c = 0; c < 3; c++)
void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)
Load plugin and its configuration from sdf.
common::Time sensor_update_time_
float attenuation[3]
Attenuation constants per channel (RGB)
ROSCPP_DECL bool isInitialized()
void Load(sensors::SensorPtr _parent, sdf::ElementPtr _sdf, const std::string &_camera_name_suffix="")
UnderwaterCameraROSPlugin()
Class constructor.
boost::shared_ptr< int > image_connect_count_
unsigned char background[3]
Background constants per channel (RGB)
virtual void OnNewRGBPointCloud(const float *_pcd, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
Update the controller.
virtual void SimulateUnderwater(const cv::Mat &_inputImage, const cv::Mat &_inputDepth, cv::Mat &_outputImage)
Add underwater light damping to image.
float * depth2rangeLUT
Depth to range lookup table (LUT)
virtual void OnNewDepthFrame(const float *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
virtual void OnNewImageFrame(const unsigned char *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format)
void PutCameraData(const unsigned char *_src)
rendering::CameraPtr camera_
unsigned char * lastImage
Latest simulated image.
virtual ~UnderwaterCameraROSPlugin()
Class destructor.
const float * lastDepth
Temporarily store pointer to previous depth image.
sensors::SensorPtr parentSensor_