How to detect the outer Ellipse of the Dartboard

i want to write a program which detects the Positon of a Dart on a Dartboard, to cout it automatically. Therefore i need a calibration program, to detect the exact position of the Dartboard. To do so, i want to detect the outer Ellipse, and two Segment Lines which cross in the middle of the Bullseye. Here is the Code i have written so far, with the result with a test picture:

import cv2                   #open cv2
import cv2 as cv          #open cv
import numpy as np
from threading import Thread
from threading import Event
from im2figure import *
from numpy.linalg import inv
from MathFunctions import *
from Classes import *
from Draw import *

image_proc_img = cv.imread('/Users/johannesbohmer/Documents/5. Semester/Entwicklungsprojekt/Python/Test_2/Bilder/Foto am 09.11.22 um 16.09 (1).jpg')

imCalHSV = cv2.cvtColor(image_proc_img, cv2.COLOR_BGR2HSV)
kernel = np.ones((5, 5), np.float32) / 25
blur = cv2.filter2D(imCalHSV, -1, kernel)
h, s, imCal = cv2.split(blur)

ret, thresh = cv2.threshold(imCal, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

kernel = np.ones((5, 5), np.uint8)
thresh2 = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
thresh3 = cv2.Canny(thresh2, 250, 255)
cv2.imshow("thresh2", thresh3)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))

rows = thresh3.shape[0]
circles = cv.HoughCircles(thresh3, cv.HOUGH_GRADIENT, 1, rows / 8,
                               param1=100, param2=30,
                               minRadius=300, maxRadius=1000)
if circles is not None:
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            center = (i[0], i[1])
            # circle center
  , center, 1, (0, 100, 100), 3)
            # circle outline
            radius = i[2]
  , center, radius, (255, 0, 255), 3)
cv.imshow("detected circles", image_proc_img)

cv2.imshow('thresh', thresh)
cv2.imshow('image', image_proc_img)

hough circles is for circles, not ellipses.

ellipse detection is more complex.

you don’t want to find ellipses though. you want to find the dart board. I’d recommend training either an object detector or a semantic segmentation network. you can easily use synthetic data for this.

do you even need to locate the board automatically? if the camera is fixed, manually pick (click on and record) relevant coordinates on the picture of the board.

take a look at opencv_contrib/ at 4.x · opencv/opencv_contrib · GitHub

i think cv.ximgproc.EdgeDrawing.detectEllipses() is the best option available to find ellipses.

also see GitHub - hanneshoettinger/opencv-steel-darts: Automatic scoring system for steel darts using OpenCV, a Raspberry Pi 3 Model B and two webcams.


thank you very much. You are right it has’t to be done automatically. Witch picking the points manually its way easier. That helped me out a lot.

How about use this function? It directly detect the ellipse in image and return the parameters of ellipse.