forked from ter-s/Beijing_Daxuexi_Simple
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.idea/ | ||
/__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from io import BytesIO | ||
from PIL import Image | ||
|
||
def dn(cap): | ||
img = Image.open(BytesIO(cap)) | ||
_STEPS_LAYER_1 = ((1,1),(1,0),(1,-1),(0,1),(0,-1),(-1,1),(-1,0),(-1,-1)) | ||
STEPS8 = _STEPS_LAYER_1 | ||
_PX_WHITE=(250,250,250) | ||
def _denoise(img, steps, threshold, repeat): | ||
for _ in range(repeat): | ||
for j in range(img.width): | ||
for i in range(img.height): | ||
px = img.getpixel((j,i)) | ||
if px == _PX_WHITE: # 自身白 | ||
continue | ||
count = 0 | ||
if px[0]<px[1]+px[2]: | ||
count=2 | ||
for x, y in steps: | ||
j2 = j + y | ||
i2 = i + x | ||
if 0 <= j2 < img.width and 0 <= i2 < img.height: # 边界内 | ||
if img.getpixel((j2,i2)) == _PX_WHITE: # 周围白 | ||
count += 1 | ||
else: # 边界外全部视为黑 | ||
count += 1 | ||
if count >= threshold: | ||
img.putpixel((j,i), _PX_WHITE) | ||
|
||
return img | ||
|
||
def denoise8(img, steps=STEPS8, threshold=7, repeat=2): | ||
""" 考虑外一周的降噪 """ | ||
return _denoise(img, steps, threshold, repeat) | ||
|
||
buf = BytesIO() | ||
denoise8(img).save(buf, format='PNG') | ||
byte_im = buf.getvalue() | ||
return byte_im |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
建议配置运行频率一周2次(默认为3天一次),没有成功会出错,默认配置下Github会向邮箱推送,所以没有推送功能 | ||
|
||
|
||
更新:优化了验证码识别和验证码失败的反馈 | ||
|
||
|
||
# How to use | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
ddddocr | ||
requests | ||
pycryptodome | ||
ddddocr~=1.0.6 | ||
requests~=2.26.0 | ||
pycryptodome | ||
Pillow~=8.4.0 |