# Detection

Now, we'll learn how to detect the golf balls position!

We'll use two function blocks, **Show Image** and **Find Object** to detect the position of the golf ball and see the result.

Now:

1. Go to the blocks bar,
2. Under **Detections/Shapes**, go to the **Detectors** section and drag-drop the **Find Object** block into the scenario:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-82e7b55abc017f022a5952b857e52a7e9bf0e2f1%2Fimage-det-1.png?alt=media)

Just like before:

1. Go to the blocks bar,
2. Under **Input/Output**, go to the **Outputs/Exports** section and drag-drop the **Show Image** block into the scenario:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-0b6f8f823d408e10908e7bcf3b91e6c30a3e2a07%2Fimage-det.png?alt=media)

Lastly, connect them just like as below:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-c1bd23b761af62c4671e5e3bba179d85d812489b%2Fimage-det-2.png?alt=media)

Click on <img src="https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-a3f52ba493c19aeed3ed51442d5a3a9713df61ff%2Fplay_step.png?alt=media" alt="run step" data-size="line">_Run Step_ to run the scenario a step and you should see the detection in a red box in the **Show Image** block:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-c7e32bf491995b24c125d3ffd3cced634de7762e%2Fimage-det-3.png?alt=media)

Now, we are set! Go ahead and click <img src="https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-336c18484aa93d35401e4cf66bff9e99257fee93%2Fplay.png?alt=media" alt="run" data-size="line"> _Run_ and watch for 10 seconds how the detection works.

💬 It seems the detection is not working properly. This is due to **Image ROI Select**'s reference changes as the ball moves, and our reference becomes the grass.

To tackle this issue, we'll use the **Image Memory** and **Logic Input** block as shown below:

1. Go to the blocks bar,
2. Under **Image Transformers**, go to the **Analysis** section and drag-drop the **Find Object** block into the scenario:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-311883ec708cc21eb5003b847af553507ab3e3d0%2Fimage-det-memory.png?alt=media)

Again:

1. Go to the blocks bar,
2. Under **Input/Output**, go to the **Data Inputs** section and drag-drop the **Logic Input** block into the scenario:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-fa9fabd7a65b1af440034d252aa94e57bc92f9f0%2Fimage-det-logic.png?alt=media)

Our scenario is a little bit crowded. Let's rearrage the blocks by using our mouse. There are two methods:

1.  Clicking on a block and dragging it:

    ![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-4c374e057396b21afeefe38675a542c206e87ff6%2Fvideo-single-block-move.webp?alt=media)
2.  Clicking on an empty space, selecting multiple blocks and dragging them:

    ![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-c760a3e5ca7c40168cfd4daf3901ee1638c366a8%2Fvideo-multiple-block-move.webp?alt=media)

Now, connect those two blocks just as shown below:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-6af9b5da7e3e5c3843e56023be61c8dc9ffb10b8%2Fimage-det-memory2.png?alt=media)

**Image Memory** block will memorize the frame we need and freeze it. This way, our reference will never change.

To freeze the image, run the scenario for a step, go to the **Logic Input** block and set it to **True**.

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-3e840cab9e11495b83e0a0e65e00e82abab9e08c%2Fvideo-image-memory-save.webp?alt=media)

Lastly, move on to the **Find Object** block and set the _Match Threshold_ to %100 just like below:

<figure><img src="https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-e9c1faacaf06c868c73ca7067b3fc106052f8157%2Fimage-find-object-threshold.png?alt=media" alt="Singing-up" width="450"><figcaption></figcaption></figure>

We are ready to detect the golf ball! Press _Run_ and see the detection work:

![](https://63608322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbH8gla5D8g5pQAK8IzR8%2Fuploads%2Fgit-blob-9d391ca21d42434743e68bf12ddca73c259eb55e%2Fvideo-run-detection.webp?alt=media)

Very good! We are about to be finished with our first project. Move on the next project and let's finish building our first scenario.
