Created
December 21, 2018 04:48
-
-
Save SubhiH/fd7d5d7a2a0c91409a20a7747e2a4fb7 to your computer and use it in GitHub Desktop.
Convert RGB image to gray scale using iterator in OpenCV C++
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_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