the codes and sample image from https://www.pyimagesearch.com/2016/02/01/opencv-center-of-contour/ cpp compile: g++ cvcontour.cpp pkg-config opencv --libs