From eeae81e9039c181e22f0f9bf5df256c729cf7976 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Fri, 3 Apr 2015 13:54:49 +0300 Subject: [PATCH] fixing confusing variable naming in a sample code --- .../doc/reading_and_writing_images_and_video.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/highgui/doc/reading_and_writing_images_and_video.rst b/modules/highgui/doc/reading_and_writing_images_and_video.rst index 89859f9d5a..316012a279 100644 --- a/modules/highgui/doc/reading_and_writing_images_and_video.rst +++ b/modules/highgui/doc/reading_and_writing_images_and_video.rst @@ -154,13 +154,14 @@ It is possible to store PNG images with an alpha channel using this function. To void createAlphaMat(Mat &mat) { + CV_Assert(mat.channels() == 4); for (int i = 0; i < mat.rows; ++i) { for (int j = 0; j < mat.cols; ++j) { - Vec4b& rgba = mat.at(i, j); - rgba[0] = UCHAR_MAX; - rgba[1] = saturate_cast((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); - rgba[2] = saturate_cast((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); - rgba[3] = saturate_cast(0.5 * (rgba[1] + rgba[2])); + Vec4b& bgra = mat.at(i, j); + bgra[0] = UCHAR_MAX; // Blue + bgra[1] = saturate_cast((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green + bgra[2] = saturate_cast((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red + bgra[3] = saturate_cast(0.5 * (bgra[1] + bgra[2])); // Alpha } } }