Lite Any Stereo V2 S for RK3588: stereo disparity and depth
A compiled model (.rnpu) for the Rockchip RK3588 / RK3588S NPU, ready to
load. It is an fp16 build for the NPU stack of
RCDL, a C++17 / Python library for vision
and speech on these boards. RCDL's own compiler made it from ONNX, and its own
runtime runs it by driving the rknpu kernel driver directly. That means no
librknnrt and no rknn-toolkit2, only the rknpu driver the board image already
has. There is no .rknn build of this model. The stack is described in
docs/OPEN_NPU.md.
Upstream: Lite Any Stereo V2, size S. A rectified pair goes in, and the left image's disparity comes out: how many pixels to the left each of its points lies in the right image.
Redistributable, including commercially. Lite Any Stereo is MIT on the code and on the weights. See Licence.
Files
| file | what it is | size |
|---|---|---|
las2_s_640x384_fp16.rnpu |
left, right 640×384 uint8 RGB → disparity [1,1,384,640] |
24.4 MB |
The disparity is in pixels of the 640-wide input, up to 192. The ImageNet
normalisation is inside the model. RCDL's export (scripts/las2_export.py)
writes the correlation volume in 4-D operators the NPU has, so the whole model
runs on the NPU.
Measured
On Middlebury 2014 (8 scenes at 640 wide), the end-point error is the float model's, 1.655 px. The two disparities are 0.026 px apart on average.
| RK3588S | RK3588 | |
|---|---|---|
| model run | 207.59 ms | 192.41 ms |
| pair → disparity | 211.9 ms | 196.6 ms |
On the sample pair in RCDL's repository, the disparity's 1–99% range is
0.3–17.4 px. These numbers are from RCDL 0.3.0 packages on its own NPU runtime,
with one NPU core and NPU driver 0.9.8 (BSP kernels 6.1.118 and 6.1.141), under
the performance CPU governor. Each is a median over nine runs. With the model
on all three NPU cores (rcdl.Engine(path, core=rcdl.NpuCore.ALL)), an RK3588
took 98 ms a pair.
Use it
On the board (linux-aarch64), with RCDL 0.3.1 or newer:
conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-lite-any-stereo/resolve/main/las2_s_640x384_fp16.rnpu
import cv2, numpy as np, rcdl
m = rcdl.Engine("las2_s_640x384_fp16.rnpu").stereo_matcher()
left, right = cv2.imread("left.jpg"), cv2.imread("right.jpg") # rectified, one size
disp = rcdl.match_stereo(m, left, right) # source pixels, at the source size
d = disp.data # (h, w) float32
lo, hi = np.percentile(d, [1, 99])
print(f"{disp.width}x{disp.height} disparity, 1-99% range {lo:.1f}-{hi:.1f} px")
# Depth needs YOUR camera: the focal length in pixels and the baseline.
FOCAL_PX, BASELINE_M = 500.0, 0.12 # placeholders, not this pair's camera
z = rcdl.disparity_to_depth(disp, FOCAL_PX, BASELINE_M).data # metres; 0: no match
ok = z > 0
print(f"{ok.mean():.0%} of pixels matched, median {np.median(z[ok]):.2f} m with these optics")
cv2.imwrite("disparity.png", rcdl.depth_colorize(disp))
RCDL's repository has a rectified sample pair in
data/stereo/
(stereo_left.jpg, stereo_right.jpg, from Lite Any Stereo's repository).
What to know before deploying
Rectified pairs only, one size. Rectify both images with the camera's
calibration first. match_stereo refuses two images of different sizes.
Any size in, source pixels out. Both images are stretched onto the
640×384 input. match_stereo returns the disparity at the source size and in
source pixels. The search reaches 192 pixels of the 640-wide input, so an
object close enough to shift further than that cannot be matched.
Depth is f·B/d. disparity_to_depth(disp, focal_px, baseline) takes the
focal length in pixels, from the calibration, and the baseline. Depth comes out
in the baseline's units, 0 where there is no match. Unlike monocular depth,
there is no scale to guess.
The resize runs on the CPU by default. RGA's upscaling moves the picture by
about a source pixel, and a disparity is sub-pixel geometry. On a pair scaled to
twice the input, the disparity was 0.06 px from the float model's through the
CPU and 0.10 px through RGA. stereo_matcher(backend="auto") lets RGA do it.
This file needs RCDL's NPU stack. It runs on RK3588 / RK3588S under the
Rockchip BSP kernels' rknpu driver (0.9.8). It has been verified on two boards
and two kernels (6.1.118, 6.1.141). The rocket driver of mainline kernels is
not supported. The stack is marked experimental, and the .rnpu format may
still change.
Licence
MIT, on the Lite Any Stereo code and on its weights (Copyright (c) 2025 Junpeng Jing).
RCDL itself is Apache-2.0 and is unrelated to these terms. It is a
general-purpose runtime that loads any .rnpu or .rknn. The licence above
applies to these weights and this compiled file only.
The input contract for every model is in RCDL's
docs/MODELS.md. The
licence status of every model RCDL has verified is in
model_zoo/.
中文说明
简介
这是 Lite Any Stereo V2 S 双目匹配模型为 Rockchip RK3588 / RK3588S NPU 编译
好的文件(.rnpu),下载即可加载。它是 RCDL
自有 NPU 栈的 fp16 构建:由 RCDL 自己的编译器从 ONNX 编译,再由它自己的运行时
直接驱动 rknpu 内核驱动来运行。不需要 librknnrt,也不需要 rknn-toolkit2,只要
板子镜像自带的 rknpu 驱动即可。这个模型没有 .rknn 版本。整套 NPU 栈的介绍见
docs/OPEN_NPU.zh.md。
上游是 Lite Any Stereo V2 的 S 规格。输入一对已校正的左右图,输出左图的视差:左图每个点在右图中向左偏了多少像素。
可以再分发,包括商用。Lite Any Stereo 的代码和权重都是 MIT。
文件
las2_s_640x384_fp16.rnpu(24.4 MB):输入left、right两张 640×384 的 uint8 RGB,输出disparity [1,1,384,640]。
视差以 640 宽输入的像素计,最大 192。ImageNet 归一化已经放进模型。RCDL 的导出脚本
(scripts/las2_export.py)把相关体(correlation volume)改写成 NPU 支持的 4 维
算子,所以整个模型都在 NPU 上运行。
实测
- 在 Middlebury 2014(8 个场景,宽 640)上,端点误差(EPE)与浮点模型相同,为 1.655 px;两者的视差平均只差 0.026 px。
- 模型推理:RK3588S 207.59 ms,RK3588 192.41 ms;一对图到视差:211.9 ms / 196.6 ms。模型放到全部三个 NPU 核心上时,RK3588 每对 98 ms。
- 在 RCDL 仓库自带的样例图对上,视差的 1–99% 分位范围是 0.3–17.4 px。
- 测试条件:RCDL 0.3.0 的 conda 包,自有 NPU 运行时,单个 NPU 核心,NPU 驱动 0.9.8(BSP 内核 6.1.118 和 6.1.141),CPU 调频策略为
performance,取九次运行的中位数。
用法
需要 RCDL 0.3.1 或更新版本,从上面的 conda 频道安装。用法见上面的代码:对
left.jpg、right.jpg 求视差,打印视差范围,再用焦距和基线换算成深度。代码里的
焦距和基线只是占位值,请换成自己相机的标定结果。RCDL 仓库的 data/stereo/ 下有
一对已校正的样例图(stereo_left.jpg、stereo_right.jpg,取自 Lite Any Stereo
的仓库)。
部署前须知
- 只接受已校正、尺寸相同的图对。 先用相机标定结果校正两张图;尺寸不同时
match_stereo会直接报错。 - 任意尺寸输入,按原图像素输出。 两张图都会被拉伸到 640×384 输入,
match_stereo返回原图尺寸、以原图像素计的视差。搜索范围是 640 宽输入上的 192 像素,物体近到视差超出这个范围时就匹配不到。 - 深度 = f·B/d。
disparity_to_depth(disp, focal_px, baseline)需要以像素计的焦距(来自标定)和基线;深度的单位与基线相同,匹配不到的地方为 0。与单目深度不同,这里不需要猜尺度。 - 缩放默认在 CPU 上做。 RGA 放大时会让画面偏移约一个原图像素,而视差本身就是亚像素级的几何量。在放大到两倍输入尺寸的图对上,走 CPU 时视差与浮点模型差 0.06 px,走 RGA 时差 0.10 px。
stereo_matcher(backend="auto")可以让 RGA 来做缩放。 - 这个文件只能在 RCDL 的 NPU 栈上运行。 支持 RK3588 / RK3588S,使用 Rockchip BSP 内核的 rknpu 驱动(0.9.8),已在两块板子、两个内核(6.1.118、6.1.141)上验证;主线内核的
rocket驱动不支持。这套栈仍处于实验阶段,.rnpu格式以后还可能改变。
许可证
Lite Any Stereo 的代码和权重都是 MIT(Copyright (c) 2025 Junpeng Jing)。RCDL
本身是 Apache-2.0,与上述条款无关;上面的许可证只适用于这些权重和这个编译后的
文件。各模型的输入约定见 RCDL 的
docs/MODELS.md,
RCDL 核实过的所有模型的许可证情况见
model_zoo/。
Model tree for ruisv/rcdl-lite-any-stereo
Base model
tomtomtommi/LiteAnyStereoV2