基于立体相机的视差图深度重构相关技术问题咨询
doffs in Stereo Depth Calculation Great question—this is a common point of confusion when working with stereo vision pipelines across different tools and datasets. Let’s break this down step by step:
What is doffs?
doffs stands for x-difference of principal points, exactly as defined in the Middlebury dataset: doffs = cx1 - cx0.
The principal point is the pixel coordinate where the camera’s optical axis intersects the image sensor—think of it as the "optical center" of the image. Middlebury includes this term because their raw stereo images aren’t always pre-rectified to align the left and right cameras’ principal points horizontally.
When calculating depth, this offset matters because disparity values represent the horizontal pixel difference between matching points. If the principal points aren’t aligned, the raw disparity doesn’t reflect the true pixel gap relative to each camera’s optical center. Adding doffs corrects for this inherent camera setup offset, ensuring your depth calculation maps accurately to real-world distances.
How to Get doffs from OpenCV Calibration Results
When you calibrate a stereo pair using OpenCV’s cv2.stereoCalibrate function, you’ll receive two camera intrinsic matrices: cameraMatrix1 (left camera) and cameraMatrix2 (right camera).
Each intrinsic matrix follows this structure:
[ [fx, 0, cx], [0, fy, cy], [0, 0, 1] ]
Here, cx is the x-coordinate of the principal point.
To compute doffs:
- Extract
cx0(left camera’s principal x) fromcameraMatrix1[0][2] - Extract
cx1(right camera’s principal x) fromcameraMatrix2[0][2] - Calculate
doffs = cx1 - cx0(matching the Middlebury definition you referenced)
A Quick Rectification Note
If you’ve already run stereo rectification with cv2.stereoRectify and cv2.remap, the rectified images will have their principal points perfectly aligned horizontally. In this case, doffs becomes 0, so you can safely use OpenCV’s simpler depth formula (depth = Baseline*focal_length/disparity) without needing the doffs term. Middlebury’s formula is designed for unrectified camera setups where this offset still exists.
内容的提问来源于stack exchange,提问作者liming0791

