Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert YOLO format annotations to x1, y1, x2, y2 coordinates in Python?

I would like to know how to convert annotations in YOLO format (e.g., center_X, center_y, width, height = 0.069824, 0.123535, 0.104492, 0.120117) to x1, y1, x2, y2 coordinates?

like image 643
rolez22 Avatar asked Jan 24 '26 05:01

rolez22


2 Answers

If I recall correctly:

x1 = (center_X-width/2)*image_width
x2 = (center_X+width/2)*image_width
y1 = (center_y-height/2)*image_height
y2 = (center_y+height/2)*image_height
like image 75
joostblack Avatar answered Jan 25 '26 19:01

joostblack


Given that the upper-left corner of the image is [0,0]: For the upper-left corner you have to do [x,y] = [center_X, center_Y] - 1/2 * [width, height] . For the bottom-right corner [x,y] = [center_X, center_Y] + 1/2 * [width, height] .

like image 45
Gabend Avatar answered Jan 25 '26 18:01

Gabend



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!