Skip to content
Projekte

ShuaixinHuang/image-multiple-angles-3d-camera

Auf GitHub ansehen

Über uns

🎬 Erzeuge Bilder aus jedem Kamerablickwinkel mit interaktiver 3D-Steuerung. Ziehe die Kamera im 3D-Raum oder lege Azimut, Elevation und Abstand über Schieberegler fest und erzeuge anschließend das Bild. Erstellt mit Three.js + Gradio, mit zweisprachiger Oberfläche auf Chinesisch und Englisch.

Design und Medien

So werden diese Zahlen gemessen

What you can do

  • 🎮 3D 交互控制 Three.js 构建的相机控制器,拖拽彩色手柄即可调整视角,相机模型沿轨道实时飞行。 3D Interactive Control — Three.js camera widget with draggable handles. - 🎯 8×4 视角组合 8 个方位角 × 4 个仰角,距离连续可调(步长 0.05),覆盖常用拍摄角度。 8×4 View Combos — 8 azimuths × 4 elevations, continuous distance.

Gemessener Sternzuwachs

in 24h
+1
in 7 days
+4
in 15 days
+6
in 1 month
+10

Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.

README.md

Original

3D Camera Control Demo

🎬 3D Camera Control · Multi-Angle Image Generation

一键生成任意相机视角的图像 · 中英双语 Web 应用

Python Gradio Three.js License


🎯 通过 3D 交互控件或滑块调整相机方位角 / 仰角 / 距离,一键生成对应视角的新图像。 基于 Three.js 构建,支持中英双语界面切换,默认接入 Qwen-Image-Edit-Plus 后端。

💡 可替换后端 / Pluggable Backend 项目不绑定单一模型——替换 core.py 中的 infer_camera_edit 函数即可接入任意图像编辑模型。 ⚠️ 基于视角 prompt 的精确角度控制是 Qwen-Image-Edit-Plus 的特色能力,其他模型可能无法精确还原指定视角。

📑 目录 / Table of Contents

中文 English
🌱 项目缘起 🌱 Origin
✨ 功能特点 ✨ Features
🎮 相机参数 🎮 Camera Parameters
🚀 快速开始 🚀 Quick Start
📝 使用方法 📝 Usage
🖼️ 效果展示 🖼️ Demo
📦 项目结构 📦 Structure
🗂️ 架构说明 🗂️ Architecture
❓ FAQ ❓ FAQ

🌱 项目缘起 / Origin

市面上已有 AI 相机视角转换产品(如 阿里的 MultipleAngles),却往往设有付费门槛。

MultipleAngles 定价方案 / Pricing

我们相信,好的技术不该被价格挡在门外。这个项目由此而来——基于官方免费 API 额度,复现了同样的 3D 相机视角控制与多角度生成能力。代码透明,自由部署,人人可用。

📖 English

AI camera viewpoint conversion products (e.g. MultipleAngles) already exist — but they often sit behind a paywall.

We believe great technology shouldn't be gated by price. That's why this project exists: built on the official free API quota, it reproduces the same 3D camera viewpoint control and multi-angle generation. Transparent code, self-hostable, free for everyone.


✨ 功能特点 / Features

🎮 3D 交互控制

Three.js 构建的相机控制器,拖拽彩色手柄即可调整视角,相机模型沿轨道实时飞行。

3D Interactive Control — Three.js camera widget with draggable handles.

🎯 8×4 视角组合

8 个方位角 × 4 个仰角,距离连续可调(步长 0.05),覆盖常用拍摄角度。

8×4 View Combos — 8 azimuths × 4 elevations, continuous distance.

⚡ 快捷预设

一键切换前视 / 右视 / 后视 / 左视 / 俯视 / 特写六种常用视角。

Quick Presets — One-click Front / Right / Back / Left / Aerial / Close-up.

🔄 实时预览

上传图片后在 3D 视图中实时贴图,所见即所得。

Live Preview — Uploaded image is textured onto the 3D plane in real time.

🌐 中英双语

同一份核心代码,运行即可切换中英文界面,新增语言只需翻译文案字典。

Bilingual UI — One core, switchable ZH/EN UI; add languages by translating one dict.

📚 历史画廊

独立 Tab 页大图浏览本会话所有生成结果,支持下载与清空。

History Gallery — Dedicated tab with large thumbnails, download & clear.

🔀 批量生成

勾选多个视角,一次批量生成,结果集中展示。

Batch Generation — Select multiple viewpoints and generate them all at once.

📦 开箱即用

API 模式无需 GPU,仅 3 个 pip 包即可启动;可调种子与负向提示词便于复现。

Out-of-the-box — No GPU, 3 pip packages; adjustable seed & negative prompt.

相机控制一致性 / Consistent camera controls

前端预览与 API 提示词共用相机参数定义。方位角按圆周距离吸附,350° 会回到 0° 前视;距离景别按同一组 0.6 / 1.0 / 1.8 参考点选择,避免预览为远景、生成却是中景。 The browser preview and API prompt share camera definitions. Azimuth snaps around the full circle (350° → 0° front view), and both use the same 0.6 / 1.0 / 1.8 shot-distance reference points.

🎮 相机参数 / Camera Parameters

参数 / Param 范围 / Range 说明 / Description
方位角 Azimuth 0° 45° 90° 135° 180° 225° 270° 315° 水平旋转方向 / Horizontal rotation
仰角 Elevation -30° 0° 30° 60° 垂直拍摄角度(不支持正上/正下)/ Vertical angle
距离 Distance 0.6 ~ 1.8 连续(步长 0.05) 镜头远近:特写 / 中景 / 远景 / Shot distance

🚀 快速开始 / Quick Start

方式一:API 调用(推荐)✅

启动快、无需 GPU | Fast startup, no GPU needed 需阿里云账号、按调用计费 | Requires Alibaba Cloud account, pay-per-call

步骤 / Steps

1. 获取 API Key / Get your API Key

访问 阿里云百炼平台 注册并获取。 Register at Alibaba Cloud Bailian.

2. 配置 API Key / Configure the Key

打开 core.py 找到 API_KEY,或设置环境变量 DASHSCOPE_API_KEY:

# Windows PowerShell
$env:DASHSCOPE_API_KEY = "your-api-key"
# Linux / macOS
export DASHSCOPE_API_KEY="your-api-key"

3. 安装依赖 / Install dependencies

pip install -r requirements.txt

4. 运行 / Run

# 中文版 / Chinese UI
python app_zh.py

# 英文版 / English UI
python app_en.py

# 兼容入口 / Unified entry (默认中文,参数 en 切英文)
python app.py            # → 中文
python app.py en         # → English

Windows 用户可直接双击 run_zh.bat(中文)或 run_en.bat(英文)。 Windows users can double-click run_zh.bat / run_en.bat.

5. 访问 / Open

浏览器打开 / Open browser at: http://127.0.0.1:7860


方式二:本地部署(可选)

无需联网、无调用费用 | Offline, no API fee 需下载约 56 GB 模型、NVIDIA GPU(16 GB+ 显存)| ~56 GB download, 16 GB+ VRAM

📖 展开查看本地部署步骤 / Expand for local deployment

硬件要求 / Hardware

  • NVIDIA GPU(建议 RTX 3090+)
  • 16 GB+ 显存 / 60 GB+ 可用磁盘

步骤 / Steps

  1. 安装完整依赖:
pip install -r requirements.txt
pip install gradio diffusers transformers accelerate peft safetensors sentencepiece torchvision
  1. 在 core.py 中替换 infer_camera_edit 为本地推理:
import torch
from diffusers import QwenImageEditPlusPipeline

dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = QwenImageEditPlusPipeline.from_pretrained(
    "Qwen/Qwen-Image-Edit-2511", torch_dtype=dtype
).to(device)

pipe.load_lora_weights(
    "lightx2v/Qwen-Image-Edit-2511-Lightning",
    weight_name="Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors",
    adapter_name="lightning",
)
pipe.load_lora_weights(
    "fal/Qwen-Image-Edit-2511-Multiple-Angles-LoRA",
    weight_name="qwen-image-edit-2511-multiple-angles-lora.safetensors",
    adapter_name="angles",
)
pipe.set_adapters(["lightning", "angles"], adapter_weights=[1.0, 1.0])
  1. 运行 / Run: python app_zh.py 或 python app_en.py

📝 使用方法 / Usage

① 上传图片        ② 调整相机         ③ 生成          ④ 复现
 Upload image  →  Adjust camera  →  Generate  →  Reproduce
                  (3D / 预设 / 滑块)   点击 🚀          固定种子

手柄颜色 / Handle Colors

  • 🟢 绿色 Green — 方位角 Azimuth(绕水平环拖拽 / drag along the horizontal ring)
  • 🩷 粉色 Pink — 仰角 Elevation(沿弧线拖拽 / drag along the arc)

📌 距离通过下方滑块控制(连续微调,步长 0.05),不再使用 3D 手柄。 Distance is controlled via the slider (continuous, step 0.05), not a 3D handle.

💾 保存与复用生成参数 / Save and reuse settings

单次或批量生成成功后,展开「保存 / 复用生成参数」,复制或下载 JSON。 记录包含每张图实际使用的种子、相机参数、尺寸、负向提示词和生成提示词;批量记录顺序与结果画廊一致。 下次上传同一张输入图片,将 JSON 粘贴回来,选择记录编号并点击「应用参数到控件」。 这一步只回填控件,不调用 API;种子随机化会自动关闭。确认后再点击生成。 新的成功生成会替换参数面板内容,请先保存需要保留的记录。

After a successful single or batch generation, expand Save / Reuse Generation Settings and copy or download the JSON. Each entry records its actual seed, camera settings, size, negative prompt and generated prompt, in gallery order. Upload the same input image, paste the JSON, select an entry and click Apply Settings to Controls. Applying does not call the API and disables seed randomization. Click Generate when ready. Save records you need before another successful generation replaces the panel.

参数文件不包含 API Key、输入图片或临时结果地址。重新生成时提示词由相机参数重建。 固定种子现在会真正传给 API,但模型更新及服务端的概率性生成意味着结果不保证逐像素一致。 JSON excludes API keys, input images and temporary result URLs. Prompts are rebuilt from camera settings. Seeds are sent to the API; model updates and probabilistic generation mean identical pixels are not guaranteed.

开发验证(模拟 API 响应,不产生模型调用费用)/ Tests with mocked API responses:

python -m unittest discover -s tests -v

🖼️ 效果展示 / Demo

示例 / Demo

📦 项目结构 / Project Structure

image-multiple-angles-3d-camera/
├── 📄 app.py              # 兼容入口(默认中文,参数 en 切换英文)
├── 📄 app_zh.py           # 中文版入口 / Chinese UI entry
├── 📄 app_en.py           # 英文版入口 / English UI entry
├── 🧠 core.py             # 共享核心(3D 控件 / API / 工具 / CSS / JS)
├── 📐 camera_geometry.py  # 前后端共用相机参数与吸附规则 / Shared camera geometry
├── 📄 generation_recipes.py # 生成参数 JSON 导出、校验与回填 / Settings round-trip
├── 🧪 tests/              # 种子、参数与中英文界面回归 / Regression tests
├── 📋 requirements.txt    # 依赖列表 / Dependencies
├── 📖 README.md           # 本文档 / This file
├── 🖼️ 1.png               # 示例图 / Demo image
├── 🖼️ 2.png               # 封面图 / Cover image
├── ⚡ run_zh.bat          # Windows 中文快捷启动
└── ⚡ run_en.bat          # Windows 英文快捷启动

🗂️ 架构说明 / Architecture

为同时支持中英双语且避免重复维护 3D 控件与 API 逻辑,项目采用分层设计:

        ┌─────────────┐
        │   app.py    │  ← 命令行入口 / CLI entry
        └──────┬──────┘
               │ 选择语言 / pick language
       ┌───────┴───────┐
       ▼               ▼
 ┌──────────┐    ┌──────────┐
 │ app_zh.py│    │ app_en.py│   ← 仅含界面文案与布局 / UI strings + layout
 └─────┬────┘    └─────┬────┘
       └────────┬───────┘
                ▼
          ┌──────────┐
          │ core.py  │       ← 共享核心 / shared core
          │  3D 控件  │
          │  API 调用 │
          │  工具函数 │
          │  CSS / JS │
          └──────────┘

新增一种语言只需复制 app_zh.py 并翻译文案字典 T = { ... },无需改动 core.py。 To add a language, copy app_zh.py and translate the T = { ... } dict — no core.py changes needed.

❓ FAQ

报错 API_ERROR:InvalidApiKey / API key invalid?

检查 core.py 中的 API_KEY 或环境变量 DASHSCOPE_API_KEY 是否正确。 Check API_KEY in core.py or env var DASHSCOPE_API_KEY.

3D 控件不显示 / 3D widget blank?

需联网加载 Three.js CDN,请检查网络。如需离线,可把 THREE_JS_HEAD 中的 CDN 换成本地文件。 Three.js is loaded via CDN; check your network. For offline use, replace the CDN URL with a local file.

生成结果视角不准 / Generated view is inaccurate?

方位角和仰角的 LoRA 仅覆盖 8×4 离散档位,3D 拖拽松手后会自动吸附到最近档位。距离已改为连续滑块,可自由微调。 Azimuth & elevation LoRA covers 8×4 discrete steps; free dragging snaps to the nearest step on release. Distance is now a continuous slider.

如何让生成结果更稳定 / How to make results more stable?

关闭"随机化种子",固定一个表现好的种子。 Turn off "Randomize Seed" and pin a good seed.

支持正上方/正下方视角 / Top / bottom view supported?

不支持。仰角仅覆盖 -30° ~ 60°,与 LoRA 训练范围一致。 No. Elevation is limited to -30° ~ 60°, matching the LoRA training range.

🤝 贡献 / Contributing

欢迎 Issue 和 PR!特别是 / Issues and PRs welcome! Especially:

  • 🌐 新语言界面 / New language UI
  • 🎮 3D 控件交互优化 / 3D widget UX improvements
  • 💻 本地部署模式集成 / Local deployment integration
  • 🖼️ 更多示例图 / More example images

🔗 相关链接 / Related Links

💰 费用说明 / Pricing

API 模式按调用次数计费,新用户有免费额度。详见 阿里云百炼计费说明。

API mode is billed per call; new users get free quota. See Alibaba Cloud Bailian Pricing.

📄 License

MIT License — 可自由使用、修改、分发 | Free to use, modify, and distribute.

作者 / Author: AI指挥官Felix(全网同名)

⭐ 如果这个项目对你有帮助,欢迎 Star | If this project helps you, please consider giving it a star

Ähnliche Projekte entdecken

Wird geladen…