Ask Your Question

Revision history [back]

Mat img = imread("filename.jpg",CV_LOAD_IMAGE_COLOR);
unsigned char *input = (unsigned char*)(img.data);
int i,j,r,g,b;
for(int i = 0;i < img.cols;i++){
    for(int j = 0;j < img.rows;j++){
         b = input[img.cols * j + i ] ;
         g = input[img.cols * j + i + 1];
         r = input[img.cols * j + i + 2];
     }
 }

Here, g will give the green color. For more info Read this.

This might help.

Mat img = imread("filename.jpg",CV_LOAD_IMAGE_COLOR);
unsigned char *input = (unsigned char*)(img.data);
int i,j,r,g,b;
for(int i = 0;i < img.cols;i++){
    for(int j = 0;j < img.rows;j++){
         b = input[img.cols * j + i ] ;
         g = input[img.cols * j + i + 1];
         r = input[img.cols * j + i + 2];
     }
 }

Here, g will give the green color. For more info Read this.

This might help.

Mat img = imread("filename.jpg",CV_LOAD_IMAGE_COLOR);
unsigned char *input = (unsigned char*)(img.data);
int i,j,r,g,b;
for(int i = 0;i < img.cols;i++){
    for(int j = 0;j < img.rows;j++){
         b = input[img.cols * j + i ] ;
         g = input[img.cols * j + i + 1];
         r = input[img.cols * j + i + 2];
     }
 }

Here, g will give the green color. color for Row - i, Column -j . For more info Read this.