开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
utils.py 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
edata 提交于 2020年01月07日 23:48 +08:00 . add verification code recogintion note
import numpy as np
from PIL import Image
import cv2
# __all__ = []
def ver_code_rect_split(rect, max_width=50):
"""
验证码中的矩形框切分
:param rect: 矩形框(left, upper, width, height)
:param max_width: 当矩形框超过此值,则会被切分
:return: list(rect)
"""
rect_num = rect[2] // max_width
if rect_num <= 1:
return [rect]
rect_lst = []
rect_width = rect[2] // rect_num
for i in range(rect_num):
rect_temp = list(rect)
rect_temp[0] = rect_temp[0] + i * rect_width
rect_temp[2] = rect_width
rect_lst.append(tuple(rect_temp))
return rect_lst
def ver_code_split(img, out_size=(32, 32), channel_first: bool = True, mode=None):
if isinstance(img, str):
img = Image.open(img)
img_height = 132
img_width = int(img.size[0] * (img_height / img.size[1]))
# 先将图像数据放大,再做高斯滤波和中值滤波,最后二值化处理
img = img.resize((img_width, img_height), resample=Image.BICUBIC).convert('RGB')
img_pro = cv2.GaussianBlur(np.array(img.convert('L')), (3, 3), 0)
img_pro = cv2.medianBlur(img_pro, 11)
ret, img_pro = cv2.threshold(img_pro, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
# 先做边缘检测,再做轮廓检测(只需要外轮廓)
img_pro = cv2.Canny(img_pro, 80, 200, L2gradient=True)
cnts = cv2.findContours(img_pro.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]
# 可过滤一些非常小的轮廓,轮廓小于50的过滤,!注意:这个参数应当随图像尺寸大小变化面变化
cnts = [c for c in cnts if len(c) >= 50]
rects = [cv2.boundingRect(cf) for cf in cnts] # 找出轮廓的外接矩形
# 有的字母连接在一起,矩形会很宽,将其分割开来
filter_rects = []
for rt in rects:
if rt[2] * rt[3] <= 1500: # 矩形面积小于1500的过滤掉
continue
filter_rects.extend(ver_code_rect_split(rt)) # 将大的矩形框分割开
# 将所有矩形内的字母提取出来
letter_lst = []
for x, y, w, h in sorted(filter_rects, key=lambda px: px[0]):
img_temp = img.crop((x, y, x + w, y + h))
if out_size is not None: # 更改尺寸
img_temp = img_temp.resize(out_size)
if mode == "L":
img_array = np.array(img_temp.convert(mode))
else:
img_array = np.array(img_temp)
if channel_first:
img_array = img_array.transpose((2, 0, 1))
letter_lst.append(img_array)
return letter_lst
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Deep Learning and machine learning note and code
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/edata-code/DeepLearning-MachineLearning-Note.git
git@gitee.com:edata-code/DeepLearning-MachineLearning-Note.git
edata-code
DeepLearning-MachineLearning-Note
DeepLearning-MachineLearning-Note
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /