ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv_ptr->image is an instance of cv::Mat (http://docs.opencv.org/modules/core/doc/basic_structures.html#mat). There are serveral ways to access the channels, e. g.:

split up to entire image separate images:

std::vector<cv::Mat> channels;
cv::split( cv_ptr->image, channels );

cv::imshow("OpenCV viewer uEye RGB Blue", channels[0] );
cv::imshow("OpenCV viewer uEye RGB Red", channels[1] );
cv::imshow("OpenCV viewer uEye RGB Green", channels[2] );
cv::waitKey(3);

or access one pixel:

cv::Vec3b rgb_pix = cv_ptr->image.at<cv::Vec3b>( 10, 10 );

ROS_INFO_STREAM( "Blue value at pos 10, 10" << static_cast<int>( rgb_pix[0] ) );
ROS_INFO_STREAM( "Green value at pos 10, 10" << static_cast<int>( rgb_pix[1] ) );
ROS_INFO_STREAM( "Red value at pos 10, 10" << static_cast<int>( rgb_pix[2] ) );

or iterate the entire image, manipulating the pixels

cv::MatIterator<cv::Vec3b> iter = cv_ptr->image.begin<cv::Vec3b>();
cv::MatIterator<cv::Vec3b> iter_end = cv_ptr->image.end<cv::Vec3b>();

for ( ; iter != iter_end ; ++iter )
{
   (*iter)[2] = 255; // set red channel to 255, i. e. maxium value, for every pixel
}

 cv::imshow("OpenCV viewer uEye RGB manipulated", cv_ptr->image);
 cv::waitKey(3);

See: http://docs.opencv.org/

cv_ptr->image is an instance of cv::Mat (http://docs.opencv.org/modules/core/doc/basic_structures.html#mat). There are serveral ways to access the channels, e. g.:

split up to entire image separate images:

std::vector<cv::Mat> channels;
cv::split( cv_ptr->image, channels );

cv::imshow("OpenCV viewer uEye RGB Blue", channels[0] );
cv::imshow("OpenCV viewer uEye RGB Red", channels[1] );
cv::imshow("OpenCV viewer uEye RGB Green", channels[2] );
cv::waitKey(3);

or access one pixel:

cv::Vec3b rgb_pix = cv_ptr->image.at<cv::Vec3b>( 10, 10 );

ROS_INFO_STREAM( "Blue value at pos 10, 10" << static_cast<int>( rgb_pix[0] ) );
ROS_INFO_STREAM( "Green value at pos 10, 10" << static_cast<int>( rgb_pix[1] ) );
ROS_INFO_STREAM( "Red value at pos 10, 10" << static_cast<int>( rgb_pix[2] ) );

or iterate the entire image, manipulating the pixels

cv::MatIterator<cv::Vec3b> cv::MatIterator_<cv::Vec3b> iter = cv_ptr->image.begin<cv::Vec3b>();
cv::MatIterator<cv::Vec3b> cv::MatIterator_<cv::Vec3b> iter_end = cv_ptr->image.end<cv::Vec3b>();

for ( ; iter != iter_end ; ++iter )
{
   (*iter)[2] = 255; // set red channel to 255, i. e. maxium value, for every pixel
}

 cv::imshow("OpenCV viewer uEye RGB manipulated", cv_ptr->image);
 cv::waitKey(3);

See: http://docs.opencv.org/