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

三、效果展示

相关推荐
happylifetree7 小时前
Python09:核心语法-数据存储与运算-字面量
python
心之语歌7 小时前
Tkinter 画布基本梳理
运维·服务器·python
Wx-bishekaifayuan8 小时前
django个性化旅游路线推荐平台49005-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
一见已难忘8 小时前
产业AI落地技术解析:边缘部署、工业视觉检测与多传感器融合预警的工程实践(燎原:我看见的智能中国)
人工智能·计算机视觉·视觉检测
小白快快跑哦9 小时前
python-字符串全解(六):正则表达式-量词
python·正则表达式·字符串
禹凕9 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习
ebiobiz11 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
老歌老听老掉牙11 小时前
穿越时空的物流密码:VRP与VRPTW的深度剖析及实战求解
python·物流·vrp
FYKJ_201012 小时前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
ShyanZh12 小时前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式