OpenCV (Emgu.CV) — compositing images with alpha

后端 未结 4 2115
刺人心
刺人心 2020-12-31 20:21

I\'m using Emgu.CV to perform some basic image manipulation and composition. My images are loaded as Image.

Question #1:

4条回答
  •  感动是毒
    2020-12-31 21:13

    Before OpenCV 2.4 there was no support of PNGs with alpha channel.

    To verify if your current version supports it, print the number of channels after loading an image that you are certain to be RGBA. If it supports, the application will output the number 4, else it will output number 3 (RGB). Using the C API you would do:

    IplImage* t_img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
    if (!t_img)
    {
        printf("!!! Unable to load transparent image.\n");
        return -1;
    }
    printf("Channels: %d\n", t_img->nChannels);
    

    If you can't update OpenCV:

    • There are some posts around that try to bypass this limitation but I haven't tested them myself;
    • The easiest solution would be to use another API to load the image and blend it, check blImageBlending;
    • Another alternative, not as lightweight, is to use Qt.

    If your version already supports PNGs with RGBA:

    • Take a look at Emulating photoshop’s blending modes in OpenCV. It implements several Photoshop blending modes and I imagine you are capable of converting that code to .Net.

    EDIT:

    I had to deal with this problem recently and I've demonstrated how to deal with it on this answer.

提交回复
热议问题