######### It finds area of the shape
if(cv2.contourArea(contours_list[contour_num])) > 10000:
point_x = end_points[0][0][0]
point_y = end_points[0][0][1]
text_color = (0,0,0)
if len(end_points) == 3:
cv2.putText(input_image_copy, 'Triangle', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
elif len(end_points) == 4:
######### If we have 4 end points, shapes might be square or rectangle. To find this we can calculate the ratio of the edges. If ratio is close to 1, shape is probably a square. If ratio is not close to 1, shape is probably a rectangle.
x, y, w, h = cv2.boundingRect(end_points)
aspectRatio = float(w)/h
#print(aspectRatio)
if aspectRatio >= 0.95 and aspectRatio < 1.15:
cv2.putText(input_image_copy, 'Square', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
else:
cv2.putText(input_image_copy, 'Rectangle', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
elif len(end_points) == 5:
cv2.putText(input_image_copy, 'Pentagon', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
elif len(end_points) == 6:
cv2.putText(input_image_copy, 'Hexagon', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
else:
cv2.putText(input_image_copy, 'Circle', (point_x, point_y),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, text_color, 2)
#cv2.imwrite("output.jpeg", output)
cv2.imshow("shapes",output)
cv2.waitKey(0)
cv2.destroyAllWindows()