opencv通过灰度图和阀值,过滤掉铅笔的痕迹。使用提取红色通道及阀值,过滤掉红色的批改痕迹。再将两个图做一次“或”,就实现去掉印章和笔迹了。
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
# -*- encoding: utf-8 -*-
import cv2
import numpy as np
class SealRemove(object):
def remove_red_seal(self, image):
# 获得红色通道
blue_c, green_c, red_c = cv2.split(image)
# 多传入一个参数cv2.THRESH_OTSU,并且把阈值thresh设为0,算法会找到最优阈值
thresh, ret = cv2.threshold(red_c, 210, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# 实测调整为95%效果好一些
filter_condition = int(thresh * 0.99)
nominator_thresh, red_thresh = cv2.threshold(red_c, filter_condition, 255, cv2.THRESH_BINARY)
return red_thresh
def shijuanqingli(self, image):
# img = cv2.imread(image, 0)
thresh, dst1 = cv2.threshold(image,210, 255, cv2.THRESH_BINARY)
dst1_without_pen = dst1
return dst1_without_pen
def join_image(self, img_without_red, dst1_without_pen):
ret = cv2.bitwise_or(img_without_red, dst1_without_pen)
return ret
if __name__ == '__main__':
src = r'/data/wwwroot/default/asset/testsign2.png'
image0 = cv2.imread(src)
seal_rm = SealRemove()
image_0 = seal_rm.remove_red_seal(image0)
# image_0_1 = cv2.cvtColor(image_0, cv2.COLOR_BGR2GRAY)
print("<img src='/asset/testsign2.png' />")
image1 = cv2.imread(src, 0)
image_1 = seal_rm.shijuanqingli(image1)
image_result = seal_rm.join_image(image_0, image_1)
# cv2.imshow('new image', image_result)
#cv2.waitKey(0)
#cv2.destroyAllWindows()
#src_temp = src.split(r'.')
src_result = '/data/wwwroot/default/Data/newsign.png'
cv2.imwrite(src_result,image_result)
print("<img src='/Data/newsign.png' />")
网友回复
python如何调用openai的api实现知识讲解类动画讲解视频的合成?
html如何直接调用openai的api实现海报可视化设计及文本描述生成可编辑海报?
f12前端调试如何找出按钮点击事件触发的那段代码进行调试?
abcjs如何将曲谱播放后导出mid和wav格式音频下载?
python如何将曲子文本生成音乐mp3或wav、mid文件
python中mp3、wav音乐如何转成mid格式?
js在HTML中如何将曲谱生成音乐在线播放并下载本地?
python如何实现在windows上通过键盘来模拟鼠标操作?
python如何给win10电脑增加文件或文件夹右键自定义菜单?
python如何将音乐mp3文件解析获取曲调数据?