Implementing contour detection and drawing.