OpenCV生成透明的图片

cv::Mat transparentImage(1080, 1920, CV_8UC4);

void createAlphaMat(cv::Mat &mat)

{

#if 1

        for (int i = 0; i < mat.rows; ++i) {

                for (int j = 0; j < mat.cols; ++j) {

                        cv::Vec4b& rgba = mat.at(i, j);

                        rgba[0] = 0;//UCHAR_MAX;

                        rgba[1] = 0;//cv::saturate_cast((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX);

                        rgba[2] = 0;//cv::saturate_cast((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX);

                        rgba[3] = 0;//cv::saturate_cast(0.5 * (rgba[1] + rgba[2]));

                }

        }

#else

memset(mat.data, 0, mat.elemSize() * mat.cols * mat.rows);

#endif

}

你可能感兴趣的:(OpenCV,opencv,python)