Created
December 21, 2018 16:08
-
-
Save SubhiH/0467753e84961094e342489e08003ebe to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale by looping through pixels (two for loops) using OpenCV
This file contains hidden or 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
void ImageOperator::to_gray_m3(const cv::Mat &input, cv::Mat &output) { | |
unsigned char *data_in = (unsigned char*)(input.data); | |
unsigned char *data_out = (unsigned char*)(output.data); | |
int index = 0; | |
for (int row = 0; row < input.rows; ++row) { | |
for (int col = 0; col < input.cols*input.channels(); col+=input.channels()) { | |
data_out[index]= 0.11*data_in[row*input.step+col]+ | |
0.59*data_in[row*input.step+col+1]+ | |
0.3*data_in[row*input.step+col+2]; | |
index++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment