代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author: kerlomz <kerlomz@gmail.com>
import cv2
class Pretreatment(object):
def __init__(self, origin):
self.origin = origin
def get(self):
return self.origin
def binarization(self, value, modify=False):
ret, _binarization = cv2.threshold(self.origin, value, 255, cv2.THRESH_BINARY)
if modify:
self.origin = _binarization
return _binarization
def median_blur(self, value, modify=False):
if not value:
return self.origin
value = value + 1 if value % 2 == 0 else value
_smooth = cv2.medianBlur(self.origin, value)
if modify:
self.origin = _smooth
return _smooth
def gaussian_blur(self, value, modify=False):
if not value:
return self.origin
value = value + 1 if value % 2 == 0 else value
_blur = cv2.GaussianBlur(self.origin, (value, value), 0)
if modify:
self.origin = _blur
return _blur
def preprocessing(image, binaryzation=-1, smooth=-1, blur=-1):
pretreatment = Pretreatment(image)
if binaryzation > 0:
pretreatment.binarization(binaryzation, True)
if smooth != -1:
pretreatment.median_blur(smooth, True)
if blur != -1:
pretreatment.gaussian_blur(blur, True)
return pretreatment.get()
if __name__ == '__main__':
pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。