Alpha channel in OpenCV

后端 未结 3 358
遥遥无期
遥遥无期 2020-12-10 09:19

does OpenCV support alpha-channel? Or is there any way to work with transparent png? I need to merge two images, where the first one is background and the second one is imag

3条回答
  •  囚心锁ツ
    2020-12-10 09:24

    Here is a bash script that I threw together that will perform the ImageMagick conversion given by ypnos on all of the png files in a directory. You can make it recursive by replacing the * in the third line with a find command.

    #!/bin/bash
    
    for file in *
    do
        if [[ $file =~ (.+)-mask\.png ]]; then
            echo "Ignoring mask $file"
        elif [[ $file =~ (.+)\.png ]]; then
            echo "Generating mask for $file"
            basefn=${BASH_REMATCH[1]}
            convert "$basefn.png" -channel Alpha -negate -separate "$basefn-mask.png"
        fi
    done
    

提交回复
热议问题