Disparity map colors keep changing when using stereo camera with OpenCV

Hello,
I am a beginner in OpenCV. I am trying to generate a disparity map from a stereo camera and then reconstruct 3D. However, I found that the colors of the disparity map keep changing over time. I have already ruled out the influence of lighting conditions, but the problem still exists.

Screencast from 2025-08-23 15-53-01

Could you please explain what might cause this kind of variation, and how can I eliminate or stabilize it?
Thank you!

details please. a picture of the camera would be helpful. I need to see the camera.

Hello @crackwitz ,

Thank you for your help, here I attached the picture of my camera:

In case you need more details, I also paste the calibration results as follows:

=== Stereo Calibration Results ===
Reprojection Error: 0.13895 pixels

Left Camera Matrix (M_left):
[[479.4291212    0.         330.31338041]
 [  0.         480.7150427  241.54458829]
 [  0.           0.           1.        ]] 

Left Camera Distortion Coefficients (d_left):
[[ 1.79450646e-01  8.25084390e-03  3.12540542e-03  1.12238748e-04
  -7.11490231e-01]] 

Right Camera Matrix (M_right):
[[485.51658385   0.         329.53006856]
 [  0.         487.08884603 266.63387222]
 [  0.           0.           1.        ]] 

Right Camera Distortion Coefficients (d_right):
[[ 0.19862609 -0.13992588  0.00360547 -0.00347255 -0.00710633]] 

Rotation Matrix from Left to Right (R):
[[ 9.99846932e-01 -4.08117174e-04  1.74912842e-02]
 [ 3.53753620e-04  9.99995098e-01  3.11101807e-03]
 [-1.74924681e-02 -3.10435427e-03  9.99842176e-01]] 

Translation Vector from Left to Right (T):
[[-64.92055518]
 [  0.16944623]
 [  2.38617217]] 

Essential Matrix (E):
[[-3.80814981e-03 -2.38668650e+00  1.61996062e-01]
 [ 1.25018618e+00 -2.02510241e-01  6.49520464e+01]
 [-1.92386174e-01 -6.49201678e+01 -2.04932852e-01]] 

Fundamental Matrix (F):
[[ 4.65197210e-09  2.90773719e-06 -7.98759824e-04]
 [-1.52227689e-06  2.45924982e-07 -3.74737691e-02]
 [ 5.18461654e-04  3.73773246e-02  1.00000000e+00]] 

Manual RMS: 0.11898438924507868

and the SGBM parameters:

numDisparities = 16*8  
blockSize = 11        
stereo_left = cv2.StereoSGBM_create(
    numDisparities=numDisparities,
    blockSize=blockSize
)

stereo_right = cv2.ximgproc.createRightMatcher(stereo_left)

wls_filter = xip.createDisparityWLSFilter(matcher_left=stereo_left)
    
wls_filter.setLambda(8000.0)    
wls_filter.setSigmaColor(1.5)  

Thank you again :slight_smile:

so you’ve clamped that PCB in a 3D-printed plastic vise.

I’m sure the PCB is flexing this way and that, depending on temperature and on which way the USB cord is pulling.

depth values from stereo vision are very sensitive near infinity. that is a fact of math. any little disturbance shows up at infinity and “close to” it.

1 Like

Hi @crackwitz

Thank you so much!

I released the cameras based on your answer, then the result became much better. The measurement variation has improved from about ±1 cm to around ±2 mm. I need to reprint a new bracket now :slight_smile: