Created
August 8, 2018 10:55
-
-
Save deysumitkr/df1c07ec61885750dd52b5e2357ec756 to your computer and use it in GitHub Desktop.
Pointer access to opencv Mat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat img = imread("filename.jpg",CV_LOAD_IMAGE_COLOR); | |
unsigned char *input = (unsigned char*)(img.data); | |
int 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]; | |
} | |
} | |
if (I.isContinuous()){ | |
uchar* p = I.data; | |
// grayscale | |
for( unsigned int i =0; i < ncol*nrows; ++i){ | |
*p++ = table[*p]; | |
} | |
// BGR | |
for(unsigned int i=0; i<I.rows; i++){ | |
for(unsigned int j=0; j<I.cols; j++){ | |
uint8_t b = *p++; | |
uint8_t g = *p++; | |
uint8_t r = *p++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment