Created
March 2, 2016 16:13
-
-
Save mshabunin/4237f1e16ae0a8c84a98 to your computer and use it in GitHub Desktop.
Test code for issue 6198
This file contains 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
#include <vector> | |
#include <stdio.h> | |
#include <opencv2/opencv.hpp> | |
using namespace cv; | |
using namespace std; | |
void createAlphaMat(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)) / ((float)mat.cols) * UCHAR_MAX); | |
rgba[2] = saturate_cast<uchar>((float(mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); | |
rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2])); | |
} | |
} | |
} | |
int main(int argv, char **argc) | |
{ | |
// Create mat with alpha channel | |
Mat mat(480, 640, CV_8UC4); | |
createAlphaMat(mat); | |
vector<int> compression_params; | |
compression_params.push_back(16); | |
compression_params.push_back(9); | |
imwrite("alpha.png", mat, compression_params); | |
fprintf(stdout, "Saved PNG file with alpha data.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment