python opencv2 去小红书水印

去除文件夹内所有.jPg结尾的小红书水印
在这里插入图片描述

在这里插入图片描述
直接上源码

import os
import cv2
import numpy as np

def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        return files

ba=file_name(os.getcwd())
for file in ba:
    if file[-3:] == "jpg":
        print(file)  # 替换的文件名
        # 加载原始图片
        image = cv2.imread(file)  # image :是返回提取到的图片的值
        size = image.shape
        w = size[1]  # 宽度
        h = size[0]  # 高度
        print(w, h)
        cropped_image = image[h - 110:h - 20, w - 300:w - 20]  #
        lower = np.array([200, 200, 200])  # 可以调整
        upper = np.array([255, 255, 255])
        thresh = cv2.inRange(cropped_image, lower, upper)
        k = cv2.getStructuringElement(cv2.MORPH_RECT, (4, 4))
        binary = cv2.dilate(thresh, k)
        size2 = binary.shape
        w2 = size2[1]  # 宽度
        h2 = size2[0]  # 高度
        print(w2, h2)
        # s2=binary[0:h2,0:w2]
        gray0 = np.zeros((h, w), dtype=np.uint8)
        for i in range(h2):  # 获取高度数值
            k = 0
            for j in binary[i]:  # 高度行的数值
                if j == 255:
                    gray0[h - 110 + i, w - 300 + k] = 255
                k = k + 1
        # image 是原始图像
        # gray0 是底图
        dst = cv2.inpaint(image, gray0, 0.1, cv2.INPAINT_TELEA)
        cropped_dst = dst[h - 110:h - 20, w - 300:w - 20]  #
        cv2.imshow("jpg", cropped_dst)
        cv2.waitKey(0)
        cv2.imwrite(str(file), dst)
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值