import numpy as np
import cv2
img = cv2.imread("C:/Users/Asus/Desktop/yq.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 70, param1=100, param2=25, minRadius=10, maxRadius=50)
# circles = np.uint(np.around(circles))
# for c in circles[0]:
# x, y, r = c;
edged = cv2.Canny(blurred, 75, 200)
contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
center, radius = cv2.minEnclosingCircle(contours[-1])
x = int(np.around(center[0]))
y = int(np.around(center[1]))
cv2.circle(img, (x, y), int(radius), (0, 0, 255), 2)
sp = img.shape
img_x = int(np.around(sp[0] / 2))
img_y = int(np.around(sp[1] / 2))
k = 10 / (2 * int(radius))
d_x = (x - img_x) * k
d_y = (y - img_y) * k
cv2.imshow("img", img)
cv2.waitKey()
cv2.destroyAllWindows()