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

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

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 把滑块半透明叠加到匹配位置,验证直观效果。