Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

extract RGB values from ptr[c] = cv::Vec3b(ptr[c][2], ptr[c][1], ptr[c][0]);

I have been trying to modify pixels value using pointers with the code borroweded from https://riptutorial.com/opencv/example/9922/efficient-pixel-access-using-cv--mat--ptr-t--pointer:

  for(int r = 0; r < image.rows; r++) {
    // We obtain a pointer to the beginning of row r
    cv::Vec3b* ptr = image.ptr<cv::Vec3b>(r);

    for(int c = 0; c < image.cols; c++) {
        // We invert the blue and red values of the pixel
        ptr[c] = cv::Vec3b(ptr[c][2]=0, ptr[c][1], ptr[c][0]=0);
    }
}

this works fine and as expected shows the picture as shades of green . Yet I cannot access B, G or R individually to perform a threshold algorithm.

cout <<  "*ptr = "<< *ptr<< std::endl;

returns an array of BGR values *ptr = [0, 65, 0]

What would be the syntax to extract B, G and R from this array individually?