目标检测中图像增加手段

处理不清晰的扫描件进行内部红章等检测时,往往需要增强图片进行检测,可以有效地提高得到地准确率和confidence。经实验表明,对比度增强和锐化往往能提高OCR、检测等精度。

from PIL import Image
from PIL import ImageEnhance
import numpy as np
import os

path = 'xxx'
for i in os.listdir(path):
    p_ = path + i
    img = Image.open(p_).convert('RGB')
    img_gray = Image.open(p_).convert('L')
    mean_gray = np.mean(img_gray) 
    w_old, h_old = img.size
    min_wid = min(w_old, h_old)
    throld_resize = xxx
    if min_wid<throld_resize:
        w_new, h_new = int(w_old/min_wid *throld_resize), int(h_old/min_wid *throld_resize)
        img = img.resize((w_new, h_new))
    if mean_gray>throld_resize : 
        """ #亮度增强
        enh_bri = ImageEnhance.Brightness(img)
        brightness = 1.0
        image_brightened = enh_bri.enhance(brightness)
        
        #色度增强
        enh_col = ImageEnhance.Color(image_brightened)
        color = 1.0
        image_colored = enh_col.enhance(color) """

        #对比度增强
        enh_con = ImageEnhance.Contrast(img)
        contrast = 2.5 #1.2
        image_contrasted = enh_con.enhance(contrast)
        #image_contrasted.show()
        image_contrasted.save('xxxx')

        #锐度增强
        enh_sha = ImageEnhance.Sharpness(image_contrasted)
        sharpness = 1.5 #2.5
        image_sharped = enh_sha.enhance(sharpness)
        #image_sharped.show()
        image_sharped.save('xxxx')
        img = image_sharped
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值