Tuesday, 18 January 2022

Fit theoretical dartboard in image containing dartboard

I have the following image containing a dartboard

enter image description here

After processing the image looks as follows:

enter image description here

In addition, I have a function that creates a theoretical dartboard:

import cv2
import numpy as np

def draw_dartboard():
        IMG = np.ones((400, 400), 'uint8') * 255
        center = (int(IMG.shape[0] // 2), int(IMG.shape[1] // 2))
        size_dartboard = int(340)
        r_board = int(170)
        r_db = int(6.35)
        r_sb = int(15.9)
        r_doubles = int(162)
        r_triples = int(99)
        width_rings = int(8)

        cv2.circle(IMG, center, r_doubles + width_rings, (0,0,0), -1)
        cv2.circle(IMG, center, r_doubles, (255,255,255), -1)
        cv2.circle(IMG, center, r_triples + width_rings, (0,0,0), -1)
        cv2.circle(IMG, center, r_triples, (255,255,255), -1)
        
        thetas_min = np.radians([(18 * t - 9) for t in range(20)])
        thetas_max = np.radians([(18 * t + 9) for t in range(20)])
        
        for idx, (theta_min, theta_max) in enumerate(zip(thetas_min, thetas_max)):            
            if (idx % 2) == 0: 
                x_min = int(center[0] + r_board * np.cos(theta_min))
                y_min = int(center[1] + r_board * np.sin(theta_min))
                x_max = int(center[0] + r_board * np.cos(theta_max))
                y_max = int(center[1] + r_board * np.sin(theta_max))
                cv2.fillPoly(IMG, np.array([(center, (x_min,y_min), (x_max,y_max))]), (0,0,0))
           
        cv2.circle(IMG, center, r_sb, (0,0,0), -1)
        
        return IMG

The output of this image looks as follows:

enter image description here

How can I “fit” the theoretical dartboard in the real image? Clearly, there is a mismatch in orientation and scale. What's the best way to do this?



from Fit theoretical dartboard in image containing dartboard

No comments:

Post a Comment