python+opencv实现去掉合同试卷印章笔迹效果代码
代码语言:python
所属分类:其他
代码描述:python+opencv实现去掉合同试卷印章笔迹效果代码,通过灰度图和阀值,过滤掉铅笔的痕迹。使用提取红色通道及阀值,过滤掉红色的批改痕迹。再将两个图做一次“或”,就实现去掉印章和笔迹了。
代码标签: python opencv 去掉 合同 试卷 印章 笔迹
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/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, ds.........完整代码请登录后点击上方下载按钮下载查看
网友评论0