使用Python的OpenCV模块识别滑动验证码的缺口(推荐)-创新互联
最近终于找到一个好的方法,使用Python的OpenCV模块识别滑动验证码的缺口,可以将滑动验证码中的缺口识别出来了。


测试使用如下两张图片:

target.jpg

template.png
现在想要通过“template.png”在“target.jpg”中找到对应的缺口,代码实现如下:
# encoding=utf8
import cv2
import numpy as np
def show(name):
cv2.imshow('Show', name)
cv2.waitKey(0)
cv2.destroyAllWindows()
def main():
otemp = 'template.png'
oblk = 'target.jpg'
target = cv2.imread(otemp, 0)
template = cv2.imread(oblk, 0)
w, h = target.shape[::-1]
temp = 'temp.jpg'
targ = 'targ.jpg'
cv2.imwrite(temp, template)
cv2.imwrite(targ, target)
target = cv2.imread(targ)
target = cv2.cvtColor(target, cv2.COLOR_BGR2GRAY)
target = abs(255 - target)
cv2.imwrite(targ, target)
target = cv2.imread(targ)
template = cv2.imread(temp)
result = cv2.matchTemplate(target, template, cv2.TM_CCOEFF_NORMED)
x, y = np.unravel_index(result.argmax(), result.shape)
# 展示圈出来的区域
cv2.rectangle(template, (y, x), (y + w, x + h), (7, 249, 151), 2)
show(template)
if __name__ == '__main__':另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文题目:使用Python的OpenCV模块识别滑动验证码的缺口(推荐)-创新互联
链接地址:http://www.jxjierui.cn/article/djdhje.html


咨询
建站咨询
