There are several reasons of colors variation.
1. Actually, colors you see is not actual depth map data. Let's look inside the colorization part of our code (lines 92-94 from stereopi-tutorial, script 6
Code: Select all
92 disparity_grayscale = (disparity-local_min)*(65535.0/(local_max-local_min))
93 disparity_fixtype = cv2.convertScaleAbs(disparity_grayscale, alpha=(255.0/65535.0))
94 disparity_color = cv2.applyColorMap(disparity_fixtype, cv2.COLORMAP_JET)
Line 92 performs normalization. At this place we limit maximum disparity difference (local_max-local_min) by 65535, and minimum became 0 (zero).
Line 93 helps us to do appropriate numbers conversion to the range from 0 to 255. It is a range for the grayscale image.
And in the line 94 we colorize it. The "brighest" points (max disparities) became red, and "darkest" (black) became dark-blue.
That is, if you have a tiny fluctuation in your depth map, and one point with the smaller disparity appears, all colors "shifts" according to this change.
Actually, if you will do a 3D reconstruction, image will be stable, as while reconstruction you did not any normalization we use for colorizing.
There are several approaches to "fix" colors and avoid this small color shifting:
- Fix colorization range. In line 92 we use calculated values disparity-local_min, local_max and local_min. You can estimate them and use fixed values
- Do auto-adjustment on-the-go. We used this approach in our latest code version, stereopi-fisheye-robot, script 6
. In this code we're remember the smallest and the biggest disparity values from the current session, and do color range adjustment.
Notice: actually you can use stereopi-fisheye-robot scripts for non-fisheye cameras, as I described here
on our forum.
2. Actual depth map fluctuation.
Even with the fixed disparity and color range, your actual depth map can fluctuate in some image regions. As a rule, it is a regions with a poor light conditions, or with a very small color gradient. The only way here is to tune your depth map settings. As a rule, you need to decrease all parameters like SWS, prefilter cap and so on.
Here you can get a "trap" of a human perception. You see, with the higher filter values you get more nice-looking, smooth map. And most users prefer this way. But actually your map will be more stable (but not so nice-looking) with the smaller parameters.