How to load png images with 4 channels?

后端 未结 5 1240
暗喜
暗喜 2020-12-03 00:45

I have been trying to load .png files with transparency channel (RGB and Alph) with no luck. It appears that openCV strips the 4th channel out of the image. Is there any met

5条回答
  •  囚心锁ツ
    2020-12-03 01:19

    If you are using OpenCV 2 or OpenCV 3 you should use IMREAD_* flags (as mentioned at here).

    C++

    using namespace cv;
    Mat image = imread("image.png", IMREAD_UNCHANGED);
    

    Python

    import cv2
    im = cv2.imread("image.png", cv2.IMREAD_UNCHANGED)
    

提交回复
热议问题