Ask Your Question

Revision history [back]

Accessing OpenCV colors in Mat Object

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 ???;