cv_bridge exception: [8UC3] and [32FC1] do not have the same number of channel
cv_bridge exception: [8UC3] and [32FC1] do not have the same number of channel
cv_bridge exception: [mono8] is a color format but [8UC3] is not so they must have the same OpenCV type, CV_8UC3, CV16UC1 ....
今天碰到这个错误。
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::MONO8);
我的image callback:
void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
cv_bridge::CvImagePtr cv_ptr;
printf("imag ge%d\n",__LINE__);
try
{
cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_8UC1);
printf("imag ge%d\n",__LINE__); //convert ROS image to CV image and make copy of it storing in cv_ptr(a pointer)
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
return;
}
}
出现此类错误,是由于从ROS 图像转换为opencv可用的图像时,图像编码不一致导致。
改为
sensor_msgs::image_encodings::TYPE_8UC3
后,代码正常。