Commit eeae81e9 authored by Andrey Pavlenko's avatar Andrey Pavlenko

fixing confusing variable naming in a sample code

parent f01b2413
...@@ -154,13 +154,14 @@ It is possible to store PNG images with an alpha channel using this function. To ...@@ -154,13 +154,14 @@ It is possible to store PNG images with an alpha channel using this function. To
void createAlphaMat(Mat &mat) void createAlphaMat(Mat &mat)
{ {
CV_Assert(mat.channels() == 4);
for (int i = 0; i < mat.rows; ++i) { for (int i = 0; i < mat.rows; ++i) {
for (int j = 0; j < mat.cols; ++j) { for (int j = 0; j < mat.cols; ++j) {
Vec4b& rgba = mat.at<Vec4b>(i, j); Vec4b& bgra = mat.at<Vec4b>(i, j);
rgba[0] = UCHAR_MAX; bgra[0] = UCHAR_MAX; // Blue
rgba[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); bgra[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green
rgba[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); bgra[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red
rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2])); bgra[3] = saturate_cast<uchar>(0.5 * (bgra[1] + bgra[2])); // Alpha
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment