python之使用cv2.matchTemplate识别缺口滑块验证码---实现最佳图像匹配

一、滑块验证码

案例图片,自行下载


二、识别代码

pip install opencv-python

python 复制代码
import cv2

# 读取背景图和滑块图
bg_img = cv2.imread("static/capBg.png")     # 背景图
# bg_img_gray = cv2.imread("static/capBg.png",0)     # 背景图_黑白
tpl_img = cv2.imread("static/capPiece.png")        # 滑块图
# tpl_img_gray = cv2.imread("static/capPiece.png",0)        # 滑块图_黑白
h,w = tpl_img.shape[:2]   # 获取滑块宽高

# 模板匹配
result = cv2.matchTemplate(bg_img, tpl_img, cv2.TM_CCOEFF_NORMED)
minVal,maxVal,minLoc,maxLoc = cv2.minMaxLoc(result)

# 写识别红框
lowerright = (maxLoc[0]+w,maxLoc[1]+h)
img_result = cv2.rectangle(bg_img.copy(),maxLoc,lowerright,(0,0,255),1)  # 在原图上画出模板匹配出的区域

cv2.imshow('img_result',img_result)
cv2.waitKey(0)
cv2.destroyAllWindows()

三、效果展示

相关推荐
微学AI1 小时前
内网穿透的应用-服务器日志出现异常怎么办?Python监控、钉钉告警与远程处理教程
服务器·python·钉钉
_Jimmy_9 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
SamChan9011 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步201511 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
阿_旭11 小时前
【分割实战】三种图像分割方法实战对比:Mask R-CNN + GrabCut + OpenCV【附源码】
opencv·图像分割
颜酱11 小时前
09 | 重构项目结构
人工智能·python·langchain
kisloy12 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python
Sisphusssss13 小时前
香橙派5plus GPIO
linux·python·ubuntu
颜酱13 小时前
08 | 把维度值同步到 Elasticsearch(生成阶段)
人工智能·python·langchain
久久学姐14 小时前
基础转码学 AI:Java+Python 双语言入门,3 个月可落地实战项目
java·python·ai·转码·实战项目