用 Claude Code 把任意照片变成 3D ASCII 视频 Claude 从照片中提取深度图,将其重建为 3D 场景,再用 ASCII 着色器处理每一帧。摄像机真的会在场景中移动:樱花树从身边掠过,Fuji 留在原处,花瓣在前景飘落 不需要视频模型。只用 three.js、一个在本地运行的小型深度模型,以及一个着色器 提示词在下面。放入你自己的照片,让我看看你做出了什么 把我的图片(input.png——任意照片、插画或截图)变成一段 12 秒、60 fps 的动态 3D ASCII 视频。横向输入输出 1920x1080,纵向输入输出 1080x1920(居中裁剪以填满画面)。 1. 深度:运行 Depth Anything V2 small(onnx-community/depth-anything-v2-small,使用 onnxruntime 在 CPU 上运行,518px 输入,ImageNet 归一化)→ 深度图,1 = 近处。 2. 用 Python(numpy + PIL)预处理,全自动,不针对单张图片调参: - 背景:取宽度为 3% 的边缘条带的颜色中位数。如果边缘颜色均匀(与该颜色的距离中位数 < 0.08)且不是黑色,则密度 = 每个像素与背景的差异程度(|L - bgL|*1.4 + 颜色距离*0.8),这样白色或彩色背景就会变成空白空间。否则,密度 = 亮度 max(r,g,b)。 - 局部对比度:d = d + 0.9*(d - gaussian_blur(d, 18px)) - 自动色阶:将第 30 百分位映射到 0,第 99.5 百分位映射到 1,然后应用 gamma 1.15,让画面中大约三分之一成为空的暗色网格 - 平坦且遥远的区域(局部方差低,且深度处于最远的 25%:天空、墙壁、摄影棚背景)x0.3 - 色调 = rgb / max(rgb),饱和度 x1.6 - 保存 photo.png = 色调 * 密度、depth.png,以及 cfg.json,其中包含一个 "dust" 颜色(最亮的 500 个高饱和度像素的平均色调) 3. three.js:一个 480x270 的平面,每个顶点都位于对应的摄像机射线上,距离为 1/(d*(1/7 - 1/70) + 1/70),fov 40。设置 frustumCulled = false。摄像机在 12 s 内向前推进 1.8 个单位,同时沿横向缓缓划出弧线,让近处物体相对于远处物体滑过(真实视差)。160 个微小的 "dust" 色尘埃点在前景向上漂浮,启用深度测试,并淡入淡出。 4. 将其渲染到分辨率为字符网格 4x 的半浮点渲染目标中,再应用全屏 ASCII 着色器: - 单元格为 8x12 px,背景为 # 03040a,每个单元格都有一条 1 px 的 # 090a0f 网格线,空单元格也不例外 - 字符梯度 " .'`,:;!ot%SX8@#",将 Geist Mono 以 8x 分辨率烘焙到字形图集中,确保边缘清晰 - 每个单元格:对 4 个采样取平均,密度 = max(rgb),颜色 = rgb / max - 每个字形都放在独立的色块上,色块填充为该字形颜色的暗色版本;密度最高的两个字形使用浅色色块搭配深色字形 - 为每个单元格的密度加入缓慢变化的噪声(不闪烁),单元格字形变化时进行柔和的交叉淡化 - 开场:在最初的 1.4 s 内,图像以波浪形式从中心向外逐渐显现 5. 确定性:每一帧只取决于 t(使用带种子的随机数,不使用 Date. now,不使用 CSS 或 requestAnimationFrame 动画)。暴露 window.renderFrame(t),用无头 Chrome(puppeteer)捕获每一帧,再用 ffmpeg 编码:H.264、yuv420p、+faststart,无音频。 在完整渲染前,把 0.7 s、6 s 和 11.5 s 的画面与输入图片并排展示给我。检查:主体一眼就能辨认,背景大部分为空白,没有任何区域变成由相同字形组成的一整块平面
看原文
Turn any photo into a 3D ASCII video with Claude Code Claude pulls a depth map out of the photo, rebuilds it as a 3D scene and runs every frame through an ASCII shader. The camera actually moves through it: the cherry trees slide past, Fuji stays put, petals fall in front No video model. Just three.js, a small depth model running locally and a shader Prompt is below. Drop in your own photo and show me what you get Turn my image (input.png — any photo, illustration or screenshot) into a 12-second 60 fps animated 3D ASCII video. Output 1920x1080 for landscape input, 1080x1920 for portrait (center-crop to fill). 1. Depth: run Depth Anything V2 small (onnx-community/depth-anything-v2-small, onnxruntime on CPU, 518px input, ImageNet normalization) → depth map, 1 = near. 2. Prep in Python (numpy + PIL), all automatic, no per-image tuning: - background: median color of a 3% border strip. If the border is uniform (median distance to that color < 0.08) and not black, density = how different each pixel is from the background (|L - bgL|*1.4 + color distance*0.8), so a white or colored backdrop turns into empty space. Otherwise density = brightness max(r,g,b). - local contrast: d = d + 0.9*(d - gaussian_blur(d, 18px)) - auto levels: map the 30th percentile to 0 and the 99.5th to 1, then gamma 1.15, so roughly a third of the frame is empty dark grid - flat + far regions (low local variance and depth in the farthest 25%: sky, walls, studio backdrops) x0.3 - hue = rgb / max(rgb) with saturation x1.6 - save photo.png = hue * density, depth.png, and cfg.json with a "dust" color (the average hue of the 500 brightest saturated pixels) 3. three.js: a 480x270 plane where every vertex sits on its camera ray at distance 1/(d*(1/7 - 1/70) + 1/70), fov 40. Set frustumCulled = false. Camera dollies forward 1.8 units with a gentle sideways arc over 12 s, so near things slide past far things (real parallax). 160 tiny dust points in the "dust" color drift upward in front, depth-tested, fading in and out. 4. Render that into a half-float render target at 4x the cell grid, then a fullscreen ASCII shader: - cells 8x12 px, background # 03040a, a 1 px # 090a0f grid line on every cell, even empty ones - ramp " .'`,:;!ot%SX8@#", Geist Mono baked into a glyph atlas at 8x for crisp edges - per cell: average 4 samples, density = max(rgb), color = rgb / max - every glyph sits on its own tile filled with a dark version of its color; the two densest glyphs get a light tile with a dark glyph - slow per-cell noise on density (no flicker) and a soft crossfade when a cell's glyph changes - intro: the image resolves from the center outward as a wave over the first 1.4 s 5. Deterministic: frames depend only on t (seeded random, no Date. now, no CSS or requestAnimationFrame animation). Expose window.renderFrame(t), capture every frame with headless Chrome (puppeteer), encode with ffmpeg: H.264, yuv420p, +faststart, no audio. Before the full render, show me frames at 0.7 s, 6 s and 11.5 s next to the input. Check: the main subject reads instantly, the background is mostly empty, nothing is one flat blob of identical glyphs