File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -56,11 +56,28 @@ ColorSubscriber::Filter& ColorSubscriber::getFilter() const {
5656}
5757
5858void ColorSubscriber::fillInput (const Image& img, ImageInputPacket& packet) const {
59- try {
60- packet.color = cv_bridge::toCvCopy (img, sensor_msgs::image_encodings::RGB8)->image ;
61- } catch (const cv_bridge::Exception& e) {
62- LOG (ERROR) << " Failed to convert color image: " << e.what ();
59+ // Allow also mono images to be converted to grayscale.
60+ if (sensor_msgs::image_encodings::isColor (img.encoding )) {
61+ try {
62+ packet.color =
63+ cv_bridge::toCvCopy (img, sensor_msgs::image_encodings::RGB8)->image ;
64+ return ;
65+ } catch (const cv_bridge::Exception& e) {
66+ LOG (ERROR) << " Failed to convert mono image as color input: " << e.what ();
67+ return ;
68+ }
69+ } else if (sensor_msgs::image_encodings::isMono (img.encoding )) {
70+ try {
71+ cv::Mat mono =
72+ cv_bridge::toCvCopy (img, sensor_msgs::image_encodings::MONO8)->image ;
73+ cv::cvtColor (mono, packet.color , cv::COLOR_GRAY2RGB);
74+ return ;
75+ } catch (const cv_bridge::Exception& e) {
76+ LOG (ERROR) << " Failed to convert color image: " << e.what ();
77+ return ;
78+ }
6379 }
80+ LOG (ERROR) << " Failed to convert color image: unsupported encoding: " << img.encoding ;
6481}
6582
6683DepthSubscriber::DepthSubscriber () = default ;
You can’t perform that action at this time.
0 commit comments