Created
December 21, 2018 15:29
-
-
Save SubhiH/31a5f915c26d4fadf2e9b496de339cbf to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale by looping through pixels 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_m2(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; | |
int byte_size = input.channels()*input.rows*input.cols; | |
while(index!=byte_size){ | |
data_out[index/input.channels()] = unsigned(0.11*data_in[index]+0.59*data_in[index+1]+0.3*data_in[index+2]); | |
index+=3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment