We have previously introduced cv2.approxPolyDP(), which can be used to approximate one contour with another with fewer points using the Douglas-Peucker algorithm. A key parameter in this function is epsilon, which sets the approximation accuracy. In contours_shape_recognition.py, we will make use of cv2.approxPolyDP() in order to recognize the contours (for example, triangle, square, rectangle, pentagon, or hexagon, among others) based on the number of detected vertices in the decimated contour (the output of cv2.approxPolyDP()). In order to decimate the number of points, given a certain contour, we first compute the perimeter of the contour. Based on the perimeter, the epsilon parameter is established. This way, the decimated contour is invariant to scale. The epsilon parameter is calculated as follows:
epsilon = 0.03 * perimeter
The constant 0.03 is established...