Go to the documentation of this file.00001 #include "image_proc/processor.h"
00002 #include <sensor_msgs/image_encodings.h>
00003 #include <ros/console.h>
00004
00005 namespace image_proc {
00006
00007 namespace enc = sensor_msgs::image_encodings;
00008
00009 bool Processor::process(const sensor_msgs::ImageConstPtr& raw_image,
00010 const image_geometry::PinholeCameraModel& model,
00011 ImageSet& output, int flags) const
00012 {
00013 static const int MONO_EITHER = MONO | RECT;
00014 static const int COLOR_EITHER = COLOR | RECT_COLOR;
00015 if (!(flags & ALL)) return true;
00016
00017
00018 const std::string& raw_encoding = raw_image->encoding;
00019 int raw_type = CV_8UC1;
00020 if (raw_encoding == enc::BGR8 || raw_encoding == enc::RGB8) {
00021 raw_type = CV_8UC3;
00022 output.color_encoding = raw_encoding;
00023 }
00024
00025 const cv::Mat raw(raw_image->height, raw_image->width, raw_type,
00026 const_cast<uint8_t*>(&raw_image->data[0]), raw_image->step);
00027
00029
00031
00032
00033 if (raw_encoding.find("bayer") != std::string::npos) {
00034
00036 int code = 0;
00037 if (raw_encoding == enc::BAYER_RGGB8)
00038 code = CV_BayerBG2BGR;
00039 else if (raw_encoding == enc::BAYER_BGGR8)
00040 code = CV_BayerRG2BGR;
00041 else if (raw_encoding == enc::BAYER_GBRG8)
00042 code = CV_BayerGR2BGR;
00043 else if (raw_encoding == enc::BAYER_GRBG8)
00044 code = CV_BayerGB2BGR;
00045 else {
00046 ROS_ERROR("[image_proc] Unsupported encoding '%s'", raw_encoding.c_str());
00047 return false;
00048 }
00049 cv::cvtColor(raw, output.color, code);
00050 output.color_encoding = enc::BGR8;
00051
00052 if (flags & MONO_EITHER)
00053 cv::cvtColor(output.color, output.mono, CV_BGR2GRAY);
00054 }
00055
00056 else if (raw_type == CV_8UC3) {
00057 output.color = raw;
00058 if (flags & MONO_EITHER) {
00059 int code = (raw_encoding == enc::BGR8) ? CV_BGR2GRAY : CV_RGB2GRAY;
00060 cv::cvtColor(output.color, output.mono, code);
00061 }
00062 }
00063
00064 else if (raw_encoding == enc::MONO8) {
00065 output.mono = raw;
00066 if (flags & COLOR_EITHER) {
00067 output.color_encoding = enc::MONO8;
00068 output.color = raw;
00069 }
00070 }
00071
00072 else if (raw_encoding == enc::TYPE_8UC3) {
00073 ROS_ERROR("[image_proc] Ambiguous encoding '8UC3'. The camera driver "
00074 "should set the encoding to 'bgr8' or 'rgb8'.");
00075 return false;
00076 }
00077
00078 else {
00079 ROS_ERROR("[image_proc] Unsupported encoding '%s'", raw_encoding.c_str());
00080 return false;
00081 }
00082
00084
00086
00089 if (flags & RECT)
00090 model.rectifyImage(output.mono, output.rect, interpolation_);
00091 if (flags & RECT_COLOR)
00092 model.rectifyImage(output.color, output.rect_color, interpolation_);
00093
00094 return true;
00095 }
00096
00097 }