From 3b6fdfe17f735054c2642f90dd83b82730973716 Mon Sep 17 00:00:00 2001 From: sophie22 Date: Thu, 29 Feb 2024 14:28:03 +0000 Subject: [PATCH] lower minRadius if no circles are found with default params --- hazenlib/ACRObject.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hazenlib/ACRObject.py b/hazenlib/ACRObject.py index ec61eadc..82abf325 100644 --- a/hazenlib/ACRObject.py +++ b/hazenlib/ACRObject.py @@ -154,16 +154,28 @@ def find_phantom_center(img, dx, dy): img_blur = cv2.GaussianBlur(img, (1, 1), 0) img_grad = cv2.Sobel(img_blur, 0, dx=1, dy=1) - detected_circles = cv2.HoughCircles( - img_grad, - cv2.HOUGH_GRADIENT, - 1, - param1=50, - param2=30, - minDist=int(180 / dy), - minRadius=int(180 / (2 * dy)), - maxRadius=int(200 / (2 * dx)), - ).flatten() + try: + detected_circles = cv2.HoughCircles( + img_grad, + cv2.HOUGH_GRADIENT, + 1, + param1=50, + param2=30, + minDist=int(180 / dy), + minRadius=int(180 / (2 * dy)), + maxRadius=int(200 / (2 * dx)), + ).flatten() + except AttributeError: + detected_circles = cv2.HoughCircles( + img_grad, + cv2.HOUGH_GRADIENT, + 1, + param1=50, + param2=30, + minDist=int(180 / dy), + minRadius=80, + maxRadius=200, + ).flatten() centre_x = round(detected_circles[0]) centre_y = round(detected_circles[1])