Skip to content

Instantly share code, notes, and snippets.

@SubhiH
Created December 21, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SubhiH/31a5f915c26d4fadf2e9b496de339cbf to your computer and use it in GitHub Desktop.
Save SubhiH/31a5f915c26d4fadf2e9b496de339cbf to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale by looping through pixels using OpenCV
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