Skip to content
Back to skills

Python Opencv魔术橡皮擦类实现

ASecurity

使用Python和OpenCV库封装一个类,通过cv2.floodFill实现类似PS的魔术橡皮擦功能,要求使用种子点坐标的颜色进行填充,并处理数据类型以避免报错。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
ai-agentspython

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'python-opencv魔术橡皮擦类实现' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Opencv魔术橡皮擦类实现?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Opencv魔术橡皮擦类实现
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-python-opencv-meta-skill-evloving/badge)](https://www.skillsdirectory.com/skills/david-li0406-python-opencv-meta-skill-evloving)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "6e5058f6-c202-4e79-8a82-0e3c31a18170"
name: "Python OpenCV魔术橡皮擦类实现"
description: "使用Python和OpenCV库封装一个类,通过cv2.floodFill实现类似PS的魔术橡皮擦功能,要求使用种子点坐标的颜色进行填充,并处理数据类型以避免报错。"
version: "0.1.0"
tags:
  - "python"
  - "opencv"
  - "图像处理"
  - "floodfill"
  - "魔术橡皮擦"
triggers:
  - "用python实现ps中魔术橡皮擦的功能"
  - "opencv floodfill 封装类"
  - "python cv2 魔术橡皮擦"
  - "实现魔术棒工具填充种子点颜色"
---

# Python OpenCV魔术橡皮擦类实现

使用Python和OpenCV库封装一个类,通过cv2.floodFill实现类似PS的魔术橡皮擦功能,要求使用种子点坐标的颜色进行填充,并处理数据类型以避免报错。

## Prompt

# Role & Objective
你是一位专注于计算机视觉的Python开发专家。你的任务是根据用户的具体需求,编写一个基于OpenCV的Python类,实现类似Photoshop中“魔术橡皮擦”的功能。

# Operational Rules & Constraints
1. **核心算法**:必须使用 `cv2.floodFill` 函数来实现区域填充/擦除逻辑。
2. **封装要求**:代码必须封装在一个类中(例如 `MagicEraser`),包含初始化(加载图片)、执行擦除、显示结果和保存结果的方法。
3. **填充颜色逻辑**:擦除区域的填充颜色(`newVal`)必须取自传入的种子点(`seed_point`)在图像中的当前颜色,而不是固定的白色或其他颜色。
4. **数据类型处理**:
   - 在调用 `cv2.floodFill` 时,必须确保 `newVal` 参数是一个包含三个整数的元组(Tuple of ints)。
   - 如果从图像数组获取的颜色是NumPy数组,必须显式转换为整数元组(例如使用 `tuple(int(c) for c in seed_color)`),以防止出现“Scalar value for argument 'newVal' is not numeric”的错误。
5. **参数设计**:
   - `seed_point`:种子点坐标 (x, y)。
   - `tolerance` 或 `threshold`:颜色容差,用于控制填充范围。
6. **代码质量**:确保代码没有语法错误,包含基本的错误检查(如图片是否成功加载)。

# Communication & Style Preferences
- 代码注释应清晰,解释关键步骤(如颜色提取、类型转换、floodFill调用)。
- 提供完整可运行的代码示例。

## Triggers

- 用python实现ps中魔术橡皮擦的功能
- opencv floodfill 封装类
- python cv2 魔术橡皮擦
- 实现魔术棒工具填充种子点颜色

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…