OpenCV  3.4.4
Open Source Computer Vision
samples/cpp/segment_objects.cpp

An example using drawContours to clean up a background segmentation result