From 0ce985ccdbc514c5e43b4b15258bc51397d0f5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Tue, 10 Sep 2024 11:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E9=81=93=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/2024,9,10/set_alpha.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/2024,9,10/set_alpha.py diff --git a/test/2024,9,10/set_alpha.py b/test/2024,9,10/set_alpha.py new file mode 100644 index 0000000..24227a3 --- /dev/null +++ b/test/2024,9,10/set_alpha.py @@ -0,0 +1,16 @@ +import cv2 as cv + +# read image +img=cv.imread("opencv_logo.png",cv.IMREAD_UNCHANGED) +# concert to rgba +img_rgba=cv.cvtColor(img,cv.COLOR_BGR2BGRA) +# split alpha channel +blue,green,red,alpha = cv.split(img_rgba) +#set alpha channel +alpha[int(alpha.shape[0]/2):alpha.shape[0],int(alpha.shape[1]/2):alpha.shape[1]]=0 +# remix alpha to img_rgba +img_rgba=cv.merge((blue,green,red,alpha)) +# show +cv.imshow("changed",img_rgba) +cv.waitKey(0) +cv.destroyAllWindows() \ No newline at end of file