# Translate YOLO annotations

**URL:** <https://forum.opencv.org/t/translate-yolo-annotations/5202>\
**Category:** Python\
**Tags:** cvat\
**Created:** [September 14, 2021, 8:06am UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202 "2021-09-14T08:06:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrcalm](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mrcalm](https://forum.opencv.org/u/mrcalm)\
**Post date:** [September 14, 2021, 8:06am UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/1 "2021-09-14T08:06:24Z")

</div>

Hello good people,

I’m new to opencv and currently training a haar cascade for my first steps. While I’m very aware that I could use the opencv\_annotation tool to, I don’t find it very good. I’ve tried it and it seems to annotate the images with the amount and box and 4 int values - now since I draw boxes I imagine them being (x,y). I also found CVAT, which seemed a lot better. Now the export of it seems only for deep learning networks but when I did the export for YOLO it somewhat had the same structure with the amount and 4 floats normalized from 0.0 - 1.0  
could I translate those numbers to use in training a haar cascade and how would I do so?

---

<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:** [September 14, 2021, 8:52am UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/2 "2021-09-14T08:52:55Z")

</div>

can you show a few lines of the generated yolo annotations ?

also, what are you trying to detect later ?  
(maybe training cascadades for that is a bad idea …)

---

<div class="post-metadata">

**Author:** ![mrcalm](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mrcalm](https://forum.opencv.org/u/mrcalm)\
**Post date:** [September 14, 2021, 9:30am UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/3 "2021-09-14T09:30:29Z")

</div>

```nohighlight
export name-yolo 1.1.zip

include:

-train.txt
-obj.names
-obj.data
--obj_train_data/
--1.txt

```

1.txt example:

```auto
1 0.478464 0.391468 0.015552 0.026509

```

I try to train it on to detect a small logo, with very small changes inside the logo (different numbers from different years) on different backgrounds.

---

<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:** [September 14, 2021, 9:51am UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/4 "2021-09-14T09:51:44Z")

</div>

> [@mrcalm](#):
>
> I try to train it on to detect a small logo, with very small changes inside the logo

yea, might work, gl 🙂

> [@mrcalm](#):
>
> 1.txt example:  
> 1 0.478464 0.391468 0.015552 0.026509

so, that is [classid CX CY w h] (in [0…1] coords)

and you [need to translate](https://docs.opencv.org/master/dc/d88/tutorial_traincascade.html) each txt file to a line like:

```
/path/to/img Nrects L T w h L T w h ....

```

where

```
L = (CX - w/2) * W
T = (CY - h/2) * H 
w = w * W
h = h * H

```

(W,H are the image dims)

---

<div class="post-metadata">

**Author:** ![mrcalm](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mrcalm](https://forum.opencv.org/u/mrcalm)\
**Post date:** [September 14, 2021, 5:29pm UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/5 "2021-09-14T17:29:09Z")

</div>

One more question, since the numbers that come out are floats I have to cut them to ints.  
Since some numbers are rounded up and some are rounded down and they seem to relate to each other, does that create any issue for the algorithm?

---

<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:** [September 14, 2021, 5:41pm UTC](https://forum.opencv.org/t/translate-yolo-annotations/5202/6 "2021-09-14T17:41:00Z")

</div>

> [@mrcalm](#):
>
> does that create any issue for the algorithm?

i dont think so.  
human error while annotating will exceed your rounding errors by far
