I am using opencv sgmb for stereo disparity computation in order to reconstruct some simple object put on the table. Everything works more or less well, except that on the edges of the object I find some outliers stuck it with the color of the background. The thing is I think that sgbm mismatches this background points which are neighbors to the edges of the object and they get the same disparity value as those edges. This is one example
As you can see some images from the floor are stuck to the object. I am using standard values for sgbm parameters:
int sgbmWinSize = 3;//size of the window to be matched
int numberOfDisparities = 256; //number of different disparity values in pixels
int cn = inputImage1.channels();
sgbm.minDisparity = -128; //minimum possible disparity value in pixels
sgbm.SADWindowSize = sgbmWinSize;
sgbm.numberOfDisparities = numberOfDisparities;
//parameters controling disparity smoothness
//values taken from openCV example
//additional tuning may be needed
sgbm.P1 = 8 * cn*sgbmWinSize*sgbmWinSize;
sgbm.P2 = 32 * cn*sgbmWinSize*sgbmWinSize;
sgbm.uniquenessRatio = 1;
//parameters for speckle filtering
sgbm.speckleWindowSize = 100;
sgbm.speckleRange = 5;
//maximum difference value in left-right disparity check
sgbm.disp12MaxDiff = 1;
//wether to run the full dp algorithm
//if set to true it may consume a lot of memory
sgbm.fullDP = true;
sgbm.preFilterCap = 4;
I have tried changing and tuning the parameters to get better disparity, but no matter what I do some background points are still stuck to the object. Have anyone had similar experience? Does anyone know a way to overcome this issue?
This is perfectly normal for SGBM. You may be able to reduce this effect by tuning the block size, but there is always some noise at the edges of objects. Another common trick is to apply a median filter to the disparity map. There are other disparity algorithms, such as Graph Cuts, which will produce cleaner edges.