34 #include <boost/make_shared.hpp> 35 #include <boost/version.hpp> 36 #if ((BOOST_VERSION / 100) % 1000) >= 53 37 #include <boost/thread/lock_guard.hpp> 44 #include <dynamic_reconfigure/server.h> 45 #include <image_proc/DebayerConfig.h> 47 #include <opencv2/imgproc/imgproc.hpp> 69 typedef image_proc::DebayerConfig
Config;
78 void imageCb(
const sensor_msgs::ImageConstPtr& raw_msg);
80 void configCb(Config &config, uint32_t level);
99 pub_mono_ =
it_->advertise(
"image_mono", 1, connect_cb, connect_cb);
100 pub_color_ =
it_->advertise(
"image_color", 1, connect_cb, connect_cb);
118 int bit_depth = enc::bitDepth(raw_msg->encoding);
120 if (raw_msg->encoding == enc::YUV422)
126 if (enc::isMono(raw_msg->encoding))
130 if ((bit_depth != 8) && (bit_depth != 16))
133 "Raw image data from topic '%s' has unsupported depth: %d",
138 sensor_msgs::ImagePtr gray_msg;
159 if (enc::isMono(raw_msg->encoding))
166 "Color topic '%s' requested, but raw image data from topic '%s' is grayscale",
169 else if (enc::isColor(raw_msg->encoding))
173 else if (enc::isBayer(raw_msg->encoding)) {
174 int type = bit_depth == 8 ? CV_8U : CV_16U;
175 const cv::Mat bayer(raw_msg->height, raw_msg->width, CV_MAKETYPE(type, 1),
176 const_cast<uint8_t*>(&raw_msg->data[0]), raw_msg->step);
178 sensor_msgs::ImagePtr color_msg = boost::make_shared<sensor_msgs::Image>();
179 color_msg->header = raw_msg->header;
180 color_msg->height = raw_msg->height;
181 color_msg->width = raw_msg->width;
182 color_msg->encoding = bit_depth == 8? enc::BGR8 : enc::BGR16;
183 color_msg->step = color_msg->width * 3 * (bit_depth / 8);
184 color_msg->data.resize(color_msg->height * color_msg->step);
186 cv::Mat color(color_msg->height, color_msg->width, CV_MAKETYPE(type, 3),
187 &color_msg->data[0], color_msg->step);
191 boost::lock_guard<boost::recursive_mutex> lock(
config_mutex_);
195 if (algorithm == Debayer_EdgeAware ||
196 algorithm == Debayer_EdgeAwareWeighted)
199 if (raw_msg->encoding != enc::BAYER_GRBG8)
202 "Falling back to bilinear interpolation.");
203 algorithm = Debayer_Bilinear;
207 if (algorithm == Debayer_EdgeAware)
213 if (algorithm == Debayer_Bilinear ||
214 algorithm == Debayer_VNG)
217 if (raw_msg->encoding == enc::BAYER_RGGB8 ||
218 raw_msg->encoding == enc::BAYER_RGGB16)
219 code = cv::COLOR_BayerBG2BGR;
220 else if (raw_msg->encoding == enc::BAYER_BGGR8 ||
221 raw_msg->encoding == enc::BAYER_BGGR16)
222 code = cv::COLOR_BayerRG2BGR;
223 else if (raw_msg->encoding == enc::BAYER_GBRG8 ||
224 raw_msg->encoding == enc::BAYER_GBRG16)
225 code = cv::COLOR_BayerGR2BGR;
226 else if (raw_msg->encoding == enc::BAYER_GRBG8 ||
227 raw_msg->encoding == enc::BAYER_GRBG16)
228 code = cv::COLOR_BayerGB2BGR;
230 if (algorithm == Debayer_VNG)
231 code += cv::COLOR_BayerBG2BGR_VNG - cv::COLOR_BayerBG2BGR;
233 cv::cvtColor(bayer, color, code);
238 else if (raw_msg->encoding == enc::YUV422)
241 sensor_msgs::ImagePtr color_msg;
252 else if (raw_msg->encoding == enc::TYPE_8UC3)
256 "Raw image topic '%s' has ambiguous encoding '8UC3'. The " 257 "source should set the encoding to 'bgr8' or 'rgb8'.",
image_transport::Publisher pub_color_
boost::recursive_mutex config_mutex_
boost::mutex connect_mutex_
#define NODELET_ERROR_THROTTLE(rate,...)
boost::function< void(const SingleSubscriberPublisher &)> SubscriberStatusCallback
image_transport::Publisher pub_mono_
uint32_t getNumSubscribers() const
ros::NodeHandle & getPrivateNodeHandle() const
std::string getTopic() const
boost::shared_ptr< image_transport::ImageTransport > it_
boost::shared_ptr< ReconfigureServer > reconfigure_server_
PLUGINLIB_EXPORT_CLASS(image_proc::CropNonZeroNodelet, nodelet::Nodelet)
void publish(const sensor_msgs::Image &message) const
#define NODELET_WARN_THROTTLE(rate,...)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
ros::NodeHandle & getNodeHandle() const
void imageCb(const sensor_msgs::ImageConstPtr &raw_msg)
void configCb(Config &config, uint32_t level)
void debayerEdgeAwareWeighted(const cv::Mat &bayer, cv::Mat &color)
void debayerEdgeAware(const cv::Mat &bayer, cv::Mat &color)
image_proc::DebayerConfig Config
image_transport::Subscriber sub_raw_
dynamic_reconfigure::Server< Config > ReconfigureServer
std::string getTopic() const