思路比较简单:
1、对图片进行锐化处理;
2、设(r_h, g_h, b_h)为支付宝遮罩黑条的RGB值,以此为中心,查找半径为Diff_radius的范围内所有的色值;
3、对每一行符合步骤2的像素点个数进行计数,若该数值超过某个临界值(如:图片宽度的一半),将其所在行替换为上一行非遮罩数据;
4、对处理后的图片高斯滤镜。
以下是python代码:
from PIL import Image,ImageFilter
Diff_radius = 500
diff_min = 150
r_h, g_h, b_h = 43, 55, 66
image = Image.open('test.png')
image_width = image.size[0]
image_height = image.size[1]
rgb_im = image.convert('RGB')
img_sharpen = image.filter(ImageFilter.SHARPEN)
img_new = Image.new('RGBA', image.size, (255,255,255,255))
img_copy = img_sharpen.crop((0,0,image_width,image_height))
img_new.paste(img_copy, (0,0,image_width,image_height))
y_tmp = 0
for y in range(image_height):
#y_is_black = 0
current_line_flag_acc = 0
for x in range(image_width):
r, g, b = rgb_im.getpixel((x, y))
if ((r_h-r)**2 + (g_h-g)**2 + (b_h-b)**2) < Diff_radius :
current_line_flag_acc = current_line_flag_acc + 1
if current_line_flag_acc > diff_min :
#y_is_black = 1
img1 = img_new.crop((0,y_tmp-2,image_width,y_tmp-1))
img_new.paste(img1, (0,y,image_width,y+1))
# print('y_tmp:%d -> y:%d'%(y_tmp,y))
else:
y_tmp = y
# img_save = img_new.filter(ImageFilter.GaussianBlur(radius=1.5))
img_new.save('test_1.png')
print("done!")
对于不同的图片,可能需要修改3、4、5行的参数。
目前测试过几组照片,发现给出的线索图片越复杂,这种方法处理后能被识别的成功率越高,尤其是对人脸,简单的处理后基本都可以识别。
识别成功的:
识别失败的: