Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Error in imwrite code specified in the opencv api reference

$
0
0
I am very new to opencv and started using OPENCV 3.0 I have run code taken from imwrite in the OPENCV API reference documentation as it is from [link text](http://docs.opencv.org/3.0-beta/modules/imgcodecs/doc/reading_and_writing_images.html) and got the following error: error: ‘CV_IMWRITE_PNG_COMPRESSION’ was not declared in this scope compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION); and the code is as follows: #include #include #include 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(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])); } } } int main(int argv, char **argc) { // Create mat with alpha channel Mat mat(480, 640, CV_8UC4); createAlphaMat(mat); vector compression_params; compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION); compression_params.push_back(9); try { imwrite("alpha.png", mat, compression_params); } catch (runtime_error& ex) { fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what()); return 1; } fprintf(stdout, "Saved PNG file with alpha data.\n"); return 0; } Can someone help me in debugging this?

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>