Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

On my Ubuntu with OpenCV from master I can load 4-channel matrix with correct alpha channel, and I can write it back to the hard drive. But I can see the last attached image if I do imshow for the loaded image. My code for reference is below.

So, it is possible that imshow's behavior is undefined for the cases with alpha. But I'm not sure...

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    Mat image = imread("/tmp/13505817932658911.png", -1);
    cout << image.channels() << endl;
    imshow("image", image); //shows incorrect image in window with orange lines
    waitKey();

    vector<Mat> ch;
    split(image, ch);
    imshow("mask", ch[3]); //shows correct mask
    waitKey();

    imwrite("/tmp/out.png", image); // saves correct image

    return 0;
}