惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

Lan小站-嗯,不错! - 学习笔记

Chrome:此扩展程序不再受支持,因此已停用,Mac解决方案 - Lan小站-嗯,不错! 从 pip 到 uv:一场 Python 包管理的「换引擎」革命 在 Django 中实现基于 JA3 指纹的反爬虫策略 纪念一下,FileCodeBox再次进入Github日榜 - Lan小站-嗯,不错! C++ string转CString - Lan小站-嗯,不错! c++的WS2tcpip和thread的bind冲突怎么解决 - Lan小站-嗯,不错! 根据日期对mysql数据分组之后查询每个日期中的不同状态的数量 - Lan小站-嗯,不错! Chrome 下载 http 进度 卡住 Fast-Crud中rowHandle的remove操作点击无效 - Lan小站-嗯,不错!
滑块验证图片匹配 - Lan小站-嗯,不错!
Lan · 2026-03-03 · via Lan小站-嗯,不错! - 学习笔记
    bg_w, bg_h, bg_ch, bg_rows = decode_png(bg_path)
    bk_w, bk_h, bk_ch, bk_rows = decode_png(block_path)
    if bg_ch != 3:
        raise ValueError("background.png 需要是 RGB 图")
    if bk_ch != 4:
        raise ValueError("block.png 需要是 RGBA 图")

    bg_gray = to_gray(bg_rows, bg_ch)
    bk_gray = to_gray(bk_rows, bk_ch)
    bk_mask = alpha_mask(bk_rows, bk_ch)
    tpl_gray, tpl_mask = crop_by_mask(bk_gray, bk_mask)

    bg_edges = edge_map(bg_gray)
    tpl_edges = edge_map(tpl_gray)

    x, y, score = find_best_position(bg_edges, tpl_edges, tpl_mask)

    print(f"背景图尺寸: {bg_w}x{bg_h}")
    print(f"滑块图尺寸: {bk_w}x{bk_h}")
    print(f"缺口左上角坐标: (, {y})")
    print(f"建议滑动距离(像素): ")
    print(f"匹配误差(越小越好): {score:.2f}")


if __name__ == "__main__":
    main()

核心原理

本质是:把滑块图当“模板”,在背景图里滑动对比,找到误差最小的位置。

参考实现都在
main.py

分步骤对应你看到的图片

  1. step_01 灰度化
    把 RGB 转灰度,减少颜色维度干扰,只保留亮度结构。
  2. step_02 Alpha 掩码
    block.png 的透明通道提取有效像素(非透明=1,透明=0),只比较有意义区域。
  3. step_03 背景边缘图
    对背景灰度图做简易梯度(和左/上像素差分),突出轮廓。
  4. step_04 模板边缘图
    对裁剪后的滑块模板做同样边缘处理,保证比较口径一致。
  5. 模板匹配(关键)
    在背景每个候选 (x,y) 上,按掩码点计算 SSE 误差:
    [
    score(x,y)=\frac{1}{N}\sum (bg\_edgey+py-tpl\_edgepy)^2
    ]
    score 最小的位置作为缺口位置。
  6. step_05 / step_06 可视化
    step_05 画匹配框;step_06 把滑块半透明叠加到匹配位置,验证直观效果。