签名抠图!python

import cv2
import numpy as np
import time

def gen_sig(img):
    name = str(time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())) + '.png'
    # 设置阈值
    temp = img[:, :, 0]  # 取图像第一个通道
    mmax = np.max(temp)
    mmin = np.min(temp)
    thresh = mmax * 0.5 + mmin * 0.5 - 15

    result = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
    B, G, R, _ = cv2.split(result)

    _, R = cv2.threshold(R, thresh, 255, cv2.THRESH_BINARY)
    _, Alpha = cv2.threshold(R, thresh, 255, cv2.THRESH_BINARY_INV)

    result[:, :, 3] = Alpha

    cv2.imwrite(name, result)

def main(path):
    img = cv2.imread(path)
    gen_sig(img)

if __name__ == '__main__':
    # 载入原图,并转化为灰度图像
    path = r'./2.jpg'
    main(path)

签名抠图小代码,直接转为白色背景插入word,方便得一匹!再也不用花钱抠图啦!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值