Files
AnyImage/docs/internals/operators/perspective-tool.md
nan e7aeeb21d4 Add tools and tests for AnyImage model management and documentation
- Implement sync_models.py for preparing and uploading ONNX artifacts.
- Create build_node.py for building and validating Blender scripts.
- Add docs.py for building and previewing documentation with Mike or MkDocs.
- Introduce model_exports.py for exporting PyTorch models to ONNX format.
- Develop pack.py for packaging the project with dependencies for different platforms.
- Add test_sync_models.py to validate sync_models functionality.
- Add test_tool_commands.py to ensure repository tools have correct command scripts.
- Initialize tools package with __init__.py.
2026-08-31 15:15:33 +08:00

1.8 KiB
Raw Blame History

Perspective Tool

Perspective Tool 从图片上的四个角点建立透视四边形,把其中内容重采样为指定宽高比的矩形并写回当前 Image Empty。

执行过程

flowchart TD
    Click["点击四个角点"] --> Quad["规范为凸四边形"]
    Quad --> Preview["生成 512 × 512 预览"]
    Preview --> Ratio["调整目标宽高比"]
    Ratio --> Size["计算受限输出尺寸"]
    Size --> Warp["全分辨率 Homography"]
    Warp --> Crop["按可见 Alpha 紧裁切"]
    Crop --> Write["Pack 并写回 Empty"]

第四点确认后生成预览,拖动鼠标调整目标宽高比,用户确认后执行全分辨率 Warp。整个流程在 Blender 进程内完成。

节点说明

采集并规范四个角点

operators/perspective_tool/__init__.py 导出注册类型,交互和计算集中在 edit_perspective.py。ImagePerspectiveTool 启动 EditImagePerspective,后者接受任意顺序的四个图片角点,再根据源图 X/Y 方向整理成不交错的凸 Quad。

图片坐标投射和首次点击选择复用 common/image_interaction.py。四个角点在该流程中统一表示为 Quad。

预览并调整比例

第四点确定后,edit_perspective.py 创建 512 × 512 预览纹理。鼠标移动更新目标宽高比和 HUD,并可吸附到常用比例。

输出尺寸根据 Quad 边长和目标比例计算,最长边不超过 8192 px,总像素不超过 16,777,216。

执行 Homography

确认后,edit_perspective.py 计算 Homography,并按 256 行分块处理全分辨率像素。插值使用预乘 Alpha,避免透明边缘混入黑色。

裁切并写回

Warp 结果按可见 Alpha 紧裁切,再通过 common/image_data.py 创建 Packed Image 并替换当前 Empty。写回时保持中心和覆盖尺度近似一致。