Skip to content

Instantly share code, notes, and snippets.

@SubhiH
Created December 21, 2018 04:48
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/fd7d5d7a2a0c91409a20a7747e2a4fb7 to your computer and use it in GitHub Desktop.
Save SubhiH/fd7d5d7a2a0c91409a20a7747e2a4fb7 to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale using iterator in OpenCV C++
void ImageOperator::to_gray_m1(const cv::Mat &input, cv::Mat &output) {
unsigned char *data_out = (unsigned char*)(output.data);
int ind = 0;
auto end = input.end<cv::Vec3b>();
cv::MatConstIterator_<cv::Vec3b> it = input.begin<cv::Vec3b>();
for (; it != end; ++it) {
const unsigned char &r = (*it)[2];
const unsigned char &g = (*it)[1];
const unsigned char &b = (*it)[0];
data_out[ind] = 0.3*r+0.59*g+0.11*b;
ind++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment