python 视频加滤镜 moviepy opencv

使用moviepy给视频加上滤镜

        def cyberpunk(image):
            # 反转色相
            image_hls = cv2.cvtColor(image, cv2.COLOR_BGR2HLS)
            image_hls = np.asarray(image_hls, np.float32)
            hue = image_hls[:, :, 0]
            hue[hue < 90] = 180 - hue[hue < 90]
            image_hls[:, :, 0] = hue

            image_hls = np.asarray(image_hls, np.uint8)
            image = cv2.cvtColor(image_hls, cv2.COLOR_HLS2BGR)

            image_lab = cv2.cvtColor(image, cv2.COLOR_BGR2Lab)
            image_lab = np.asarray(image_lab, np.float32)

            # 提高像素亮度,让亮的地方更亮
            light_gamma_high = np.power(image_lab[:, :, 0], 0.8)
            light_gamma_high = np.asarray(light_gamma_high / np.max(light_gamma_high) * 255, np.uint8)

            # 降低像素亮度,让暗的地方更暗
            light_gamma_low = np.power(image_lab[:, :, 0], 1.2)
            light_gamma_low = np.asarray(light_gamma_low / np.max(light_gamma_low) * 255, np.uint8)

            # 调色至偏紫
            dark_b = image_lab[:, :, 2] * (light_gamma_low / 255) * 0.1
            dark_a = image_lab[:, :, 2] * (1 - light_gamma_high / 255) * 0.3

            image_lab[:, :, 2] = np.clip(image_lab[:, :, 2] - dark_b, 0, 255)
            image_lab[:, :, 2] = np.clip(image_lab[:, :, 2] - dark_a, 0, 255)

            image_lab = np.asarray(image_lab, np.uint8)
            # 注意视频存在色差,更改颜色模式为COLOR_Lab2RGB
            return cv2.cvtColor(image_lab, cv2.COLOR_Lab2RGB)

        # 视频帧加入滤镜
        modifiedClip = out_video.fl_image(cyberpunk)

 参考文档:Python 图像处理:滤镜之赛博朋克 - 简书

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值