# Fit theoretical dartboard in image containing dartboard

**URL:** <https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123>\
**Category:** Uncategorized\
**Created:** [January 13, 2022, 10:20am UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123 "2022-01-13T10:20:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HJAM24](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@HJAM24](https://forum.opencv.org/u/HJAM24)\
**Post date:** [January 13, 2022, 10:20am UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/1 "2022-01-13T10:20:53Z")

</div>

Hi all,

I have the following processed image:

![dartboard](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/7/702e6bc0aea65dab5ac3446869fece9688083e5a.png)

Next, I want to know the orientation and scale of this particular dartboard. I know that a _theoretical dartboard_ can be constructed as:

```auto
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

```

I cannot share the output of the function because I can only include 1 image in this topic.

How can I “fit” the theoretical dartboard in the real image? Clearly, there is a mismatch in orientation and scale. Thank you

---

<div class="post-metadata">

**Author:** ![HJAM24](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@HJAM24](https://forum.opencv.org/u/HJAM24)\
**Post date:** [January 13, 2022, 10:21am UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/2 "2022-01-13T10:21:26Z")

</div>

original image

![dartboard_original](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/4f9e9fdfb41b988825f771a20e78f23700a88e28.png)

---

<div class="post-metadata">

**Author:** ![HJAM24](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@HJAM24](https://forum.opencv.org/u/HJAM24)\
**Post date:** [January 13, 2022, 10:21am UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/3 "2022-01-13T10:21:57Z")

</div>

theoretical dartboard:

![dartboard_theoretical](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/c/c196be6898bde54306a2050f3d1c371e7110fc4c.png)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [January 13, 2022, 12:11pm UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/4 "2022-01-13T12:11:58Z")

</div>

what produced the first image ?

---

<div class="post-metadata">

**Author:** ![HJAM24](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@HJAM24](https://forum.opencv.org/u/HJAM24)\
**Post date:** [January 13, 2022, 12:15pm UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/5 "2022-01-13T12:15:31Z")

</div>

My own image processing function. Basically I threshold for black pixels, use morphological operations in the form of closing and smoothing

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 13, 2022, 12:53pm UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/6 "2022-01-13T12:53:14Z")

</div>

try feature matching and homography.

should work on the binary black-and-white images.

you can also try it on grayscale images. I don’t remember if SIFT will work on color images as is.

be sure that the model drawing’s proportions match the real thing well. it’s not a rough sketch. overlaid (with perspective correction) it needs to match fairly well.

play with `samples/python/find_obj.py`

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 13, 2022, 1:39pm UTC](https://forum.opencv.org/t/fit-theoretical-dartboard-in-image-containing-dartboard/7123/7 "2022-01-13T13:39:36Z")

</div>

related:

> <https://stackoverflow.com/questions/70695114/fit-theoretical-dartboard-in-image-containing-dartboard>
