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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

Lan小站-嗯,不错!

Mac 访达 搜索 如何重建索引 - Lan小站-嗯,不错! 软著通:从灵感到文档,一站式赋能软件创作全流程 - Lan小站-嗯,不错! 【软著通】写一句项目描述,就能生成软著申请材料草稿 - Lan小站-嗯,不错! 【图片极致压缩+去除背景】新做了个工具,支持在线对图片进行压缩,去除背景,转换格式等 - Lan小站-嗯,不错! 【效率工具】软著申请不求人!用 AI 10分钟搞定 60 页代码文档与说明书 荒废太久了,立个Flag,每天用完Codex90刀额度 - Lan小站-嗯,不错! Chrome:此扩展程序不再受支持,因此已停用,Mac解决方案 - Lan小站-嗯,不错! 从 pip 到 uv:一场 Python 包管理的「换引擎」革命 字节跳动旗下火山方舟注册送15元额度 - 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 把滑块半透明叠加到匹配位置,验证直观效果。