Python OpenCV魔术橡皮擦类实现
使用Python和OpenCV库封装一个类,通过cv2.floodFill实现类似PS的魔术橡皮擦功能,要求使用种子点坐标的颜色进行填充,并处理数据类型以避免报错。
npx skills add ECNU-ICALK/AutoSkill --skill python-opencv魔术橡皮擦类实现 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 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 魔术橡皮擦 - 实现魔术棒工具填充种子点颜色
- Prompt
- Triggers
What does the Python OpenCV魔术橡皮擦类实现 skill do?
使用Python和OpenCV库封装一个类,通过cv2.floodFill实现类似PS的魔术橡皮擦功能,要求使用种子点坐标的颜色进行填充,并处理数据类型以避免报错。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill python-opencv魔术橡皮擦类实现 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
