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()

三、效果展示

相关推荐
山沐与山1 分钟前
【设计模式】Python状态模式:从入门到实战
python·设计模式·状态模式
Swizard5 分钟前
别让你的密钥在互联网上“裸奔”!用 python-dotenv 优雅管理你的敏感配置
python
无心水8 分钟前
【Stable Diffusion 3.5 FP8】8、生产级保障:Stable Diffusion 3.5 FP8 伦理安全与问题排查
人工智能·python·安全·docker·stable diffusion·ai镜像开发·镜像实战开发
深蓝海拓13 分钟前
PySide6从0开始学习的笔记(十八) MVC(Model-View-Controller)模式的图形渲染体系
笔记·python·qt·学习·pyqt
一招定胜负17 分钟前
杂记:cv2.imshow显示中文乱码解决过程
python·opencv
唐叔在学习20 分钟前
Pyinstaller进阶之构建管理大杀器-SPEC文件
后端·python·程序员
爱吃山竹的大肚肚22 分钟前
在Java中,从List A中找出List B没有的数据(即求差集)
开发语言·windows·python
weixin_4624462324 分钟前
【原创实践】Python 将 Markdown 文件转换为 Word(docx)完整实现
开发语言·python·word
智航GIS35 分钟前
ArcGIS大师之路500技---048计算流水号
python·arcgis
yongche_shi36 分钟前
第九十九篇:Python在其他领域的应用:游戏开发、物联网、AIoT简介
开发语言·python·物联网·游戏开发·aiot