-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPass_RemoveLine.py
More file actions
44 lines (42 loc) · 1.24 KB
/
Pass_RemoveLine.py
File metadata and controls
44 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#coding=utf-8 去除验证码的横线,但是效果一般般
"""
creat time:2015.09.14
"""
# import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image,ImageEnhance,ImageFilter
img_name = '2b.jpg'
#去除干扰线
im = Image.open(img_name)
#图像二值化
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
data = im.getdata()
w,h = im.size
#im.show()
black_point = 0
for x in range(1,w-1):
for y in range(1,h-1):
mid_pixel = data[w*y+x] #中央像素点像素值
if mid_pixel == 0: #找出上下左右四个方向像素点像素值
top_pixel = data[w*(y-1)+x]
left_pixel = data[w*y+(x-1)]
down_pixel = data[w*(y+1)+x]
right_pixel = data[w*y+(x+1)]
#判断上下左右的黑色像素点总个数
if top_pixel == 0:
black_point += 1
if left_pixel == 0:
black_point += 1
if down_pixel == 0:
black_point += 1
if right_pixel == 0:
black_point += 1
if black_point >= 3:
im.putpixel((x,y),0)
#print black_point
black_point = 0
im.save('new'+ img_name)
im.show()