46 static const int MONO_EITHER =
MONO |
RECT;
48 if (!(flags &
ALL))
return true;
51 const std::string& raw_encoding = raw_image->encoding;
52 int raw_type = CV_8UC1;
53 if (raw_encoding == enc::BGR8 || raw_encoding == enc::RGB8) {
56 }
else if (raw_encoding == enc::TYPE_32FC1) {
59 }
else if (raw_encoding == enc::MONO16) {
64 const cv::Mat raw(raw_image->height, raw_image->width, raw_type,
65 const_cast<uint8_t*>(&raw_image->data[0]), raw_image->step);
72 if (raw_encoding.find(
"bayer") != std::string::npos) {
76 if (raw_encoding == enc::BAYER_RGGB8)
77 code = cv::COLOR_BayerBG2BGR;
78 else if (raw_encoding == enc::BAYER_BGGR8)
79 code = cv::COLOR_BayerRG2BGR;
80 else if (raw_encoding == enc::BAYER_GBRG8)
81 code = cv::COLOR_BayerGR2BGR;
82 else if (raw_encoding == enc::BAYER_GRBG8)
83 code = cv::COLOR_BayerGB2BGR;
85 ROS_ERROR(
"[image_proc] Unsupported encoding '%s'", raw_encoding.c_str());
88 cv::cvtColor(raw, output.
color, code);
91 if (flags & MONO_EITHER)
92 cv::cvtColor(output.
color, output.
mono, cv::COLOR_BGR2GRAY);
95 else if (raw_type == CV_8UC3) {
97 if (flags & MONO_EITHER) {
98 int code = (raw_encoding == enc::BGR8) ? cv::COLOR_BGR2GRAY : cv::COLOR_RGB2GRAY;
99 cv::cvtColor(output.
color, output.
mono, code);
103 else if (raw_encoding == enc::MONO8) {
105 if (flags & COLOR_EITHER) {
111 else if (raw_encoding == enc::TYPE_32FC1 || raw_encoding == enc::MONO16) {
113 if (flags & COLOR_EITHER) {
119 else if (raw_encoding == enc::TYPE_8UC3) {
120 ROS_ERROR(
"[image_proc] Ambiguous encoding '8UC3'. The camera driver " 121 "should set the encoding to 'bgr8' or 'rgb8'.");
126 ROS_ERROR(
"[image_proc] Unsupported encoding '%s'", raw_encoding.c_str());
std::string color_encoding
void rectifyImage(const cv::Mat &raw, cv::Mat &rectified, int interpolation=cv::INTER_LINEAR) const
bool process(const sensor_msgs::ImageConstPtr &raw_image, const image_geometry::PinholeCameraModel &model, ImageSet &output, int flags=ALL) const