Accessing OpenCV colors in Mat Object

asked 2019-01-30 15:45:03 -0600

bordeo gravatar image

Suppose I have a grayscale integer matrix M. To access this object, I call:

uint8_t * sptr = scale.ptr<uint8_t>(0);
// for the first set of elements (seems to be column, in my case--still new to this library)

Then, I apply a colormap to the grayscale:

cv::applyColorMap(M,colors,cv::SOMECOLORMAP)

Now, what I am trying to do is the following, in pseudo code:

std::cout << "R:" << colors[i][0] << " G:" << colors[i][1] << " B:" << colors[i][2] << "\n"

How do I go about accessing these new, color elements?

 ??? * cptr = colors.ptr< ??? >(0); 

 uint8_t r = cptr ???; 
 uint8_t g = cptr ???;
 uint8_t b = cptr ???;
edit retag flag offensive close merge delete

Comments

use at method

  Vec3b bgr=colors.at<Vec3b>(i);
  cout<< bgr[0]<<" "  <<bgr[1]<<" "  << bgr[2];
LBerger gravatar imageLBerger ( 2019-01-31 01:34:19 -0600 )edit