how to split channels in opencv using a yuyv usb_camera

asked 2014-04-11 11:49:40 -0500

HXP2 gravatar image

Hello,

I'm using a web_cam which supports only yuyv pixel format with the usb_cam node. The usb_cam launch file looks like:

<launch>
    <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
        <param name="video_device" value="/dev/video0" />
        <param name="image_width" value="640" />
        <param name="image_height" value="480" />
        <param name="pixel_format" value="yuyv" />
        <param name="camera_frame_id" value="usb_cam" />
        <param name="io_method" value="mmap"/>
    </node>
</launch>

next step is to convert the image using cv_bridge with the following callback function:

void imageCb(const sensor_msgs::ImageConstPtr& msg)
    {
        cv_bridge::CvImagePtr cv_ptr;
        try
        {
            cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
        }
        catch (cv_bridge::Exception& e)
        {
            ROS_ERROR("cv_bridge exception: %s", e.what());
            return;
        }

        // Show color image
        cv::imshow("Result", cv_ptr->image);

        // Split RGB Channels
        imageA=cv_ptr->image;
        vector<cv::Mat> layers;
        cv::split(imageA, layers);

        // Show individual channels
        cv::imshow("Channel 1", layers[0]);
        cv::imshow("Channel 2", layers[1]);
        cv::imshow("Channel 3", layers[2]);
    }

The color image is looking ok, but the 3 RGB channel images look all the same (3 grayscale images with no visible difference to me). Does anybody know what I do wrong ?

Thank you HXP2.

edit retag flag offensive close merge delete