?
最開始的識別思路是通過模板來找到這個(gè)驗(yàn)證碼的滑塊圖像所在的位置,但是使用下來發(fā)現(xiàn)準(zhǔn)確率在90%左右一起提不上去,無論怎么優(yōu)化都無法提高,后來發(fā)現(xiàn)了一個(gè)奇特的思路可用完美解決這個(gè)驗(yàn)證碼的問題,思路寫在了代碼里面,最后返回的結(jié)果是需要移動的滑塊的左上角的坐標(biāo)點(diǎn)位置(本算法思路主要用在電子稅務(wù)網(wǎng)站)其他的類似的驗(yàn)證碼也可以
識別結(jié)果示意圖文章來源:http://www.zghlxwxcb.cn/news/detail-827247.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-827247.html
def slide_comparison( target_bytes):
# ; 微 394467238
alpha_channel = np.ones(target_bytes.shape, dtype=target_bytes.dtype) * 255
# alpha通道每個(gè)像素點(diǎn)區(qū)間為[0,255], 0為完全透明,255是完全不透明
# image = ImageChops.difference(background, target)
# image = ImageChops.difference(alpha_channel, target_bytes)
image = alpha_channel - target_bytes
# background.close()
# target.close()
# image = image.point(lambda x: 255 if x > 20 else 0)
start_y = 0
start_x = 0
# for i in range(0, image.width):
for i in range(0, image.shape[1]):
count = 0
# for j in range(0, image.height):
for j in range(0, image.shape[0]):
# pixel = image.getpixel((i, j))
pixel = image[j, i]
# if pixel != (0, 0, 0):
if pixel != 0:
count += 1
if count >= 5 and start_y == 0:
start_y = j - 5
if count >= 5:
start_x = i + 2
break
return [start_x, start_y] # w,h
def get_long_v2(finame='0.png',pre=''):
# v2 版本;僅僅使用png 的遮罩層就可以得到滑塊的位置了; 微 394467238
print(finame)
bg_img0 = cv2.imread(finame, cv2.IMREAD_UNCHANGED)
res = slide_comparison(bg_img0[:,:,3]) # 左上角點(diǎn)的坐標(biāo) w,h
# th, tw = bg_img0.shape[:2]
# br = (res[0] + tw, res[1] + th)
# cv2.rectangle(bg_img0, res, br, (255, 255, 255), 2) # 繪制矩形
# cv2.imwrite('1.png', bg_img0) # 保存在本地
return res
到了這里,關(guān)于驗(yàn)證碼滑塊識別算法 100% 識別 思路簡單(附算法 python 代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!