python获取透明图

import cv2
import os
import numpy as np

root = "./test"
for file in os.listdir(root):
    # 读取图片
    image = cv2.imread(os.path.join(root, file), cv2.IMREAD_UNCHANGED)
    new = np.zeros((image.shape[0], image.shape[1], image.shape[2]), np.uint8)
    # 检查图片是否为RGBA格式
    print(image.shape)
    if image.shape[2] == 4:
        print("图片是RGBA格式")
        # 获取透明度通道
        new[:, :, :3] = image[:, :, :3]
    else:
        print("图片不是RGBA格式")

    # 广播机制
    new[:, :, 3] = 30
    cv2.imwrite("./test/alpha30.png", new)
    # for i in image.shape[0]:
    #     for j in image.shape[1]:
    #         new[i][j][3] = 30

相关推荐

  1. python获取透明

    2023-12-06 13:42:04       30 阅读
  2. python获取你想要的股票信息,生成走势

    2023-12-06 13:42:04       38 阅读
  3. 将Matlab窗中的可视化保存为背景透明的矢量

    2023-12-06 13:42:04       35 阅读
  4. Python: 获取时间

    2023-12-06 13:42:04       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-06 13:42:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-06 13:42:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-06 13:42:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-06 13:42:04       20 阅读

热门阅读

  1. Docker tag 命令

    2023-12-06 13:42:04       41 阅读
  2. 首例CSDN_AI文章-- K-均值聚类算法

    2023-12-06 13:42:04       37 阅读
  3. 蓝桥杯ACwing习题

    2023-12-06 13:42:04       31 阅读
  4. 基于python实现人脸识别登录系统

    2023-12-06 13:42:04       32 阅读
  5. MySQL四 | 约束

    2023-12-06 13:42:04       39 阅读
  6. 【PyTorch】优化分析

    2023-12-06 13:42:04       32 阅读
  7. PHP常用的正则表达式

    2023-12-06 13:42:04       39 阅读
  8. go语言http协议post方法样例调用

    2023-12-06 13:42:04       39 阅读