Get center

tomni.contour_operations.get_center(contour: numpy.ndarray) Tuple[int, int][source]

Calculate the center coordinates of a contour.

Parameters

contour (np.ndarray) – An OpenCV contour of a single object.

Returns

A tuple containing the x and y coordinates of the center.

Return type

Tuple[int, int]

Example:

contour = np.array([[[1, 2]], [[2, 3]], [[3, 2]], [[2, 1]]])
get_center(contour)
(2, 2)