Opencv输出图像函数-imwrite

来源:互联网 发布:qq群优化软件怎么用 编辑:程序博客网 时间:2024/05/21 10:34
#include<opencv2/opencv.hpp>#include<iostream>#include<vector>using namespace std;using namespace cv;void creatAlphaMat(Mat &mat){for (int i = 0; i < mat.rows; i++){for (int j = 0; j < mat.cols; j++){Vec4b &rgba = mat.at<Vec4b>(i, j);rgba[0] = UCHAR_MAX;rgba[1] = saturate_cast<uchar>((float (mat.cols - j)) / (static_cast<float>(mat.cols)) * UCHAR_MAX);rgba[2] = saturate_cast<uchar>((float(mat.rows - i)) / (static_cast<float>(mat.rows)) * UCHAR_MAX);rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2]));}}}int main(){Mat mat(480, 640, CV_8UC4);creatAlphaMat(mat);vector<int>compression_params;compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);compression_params.push_back(9);imwrite("透明图.png", mat, compression_params);imshow("测试图", mat);waitKey(0);}



0 0
原创粉丝点击