developer0hye / Yolo_Label

GUI for marking bounded boxes of objects in images for training neural network YOLO
MIT License
490 stars 114 forks source link

How to convert coordinates from decimals? #59

Closed marinafridman closed 1 year ago

marinafridman commented 1 year ago

Hi!

First off many thanks for the amazing tool. Very handy and simple to use.

I feel a bit stupid, but I'm not sure how to convert the decimal coordinates produced by the program into pixel coordinates.

All of the coordinate values in my label .txt files are decimals between 0 and 1, as shown below.

class center_x center_y width height
0 0.499443 0.744048 0.996656 0.500000
1 0.500557 0.254960 0.994426 0.498016

I saw in issue #40 that that user tried to convert the decimals with an int() call... however for me this converts all values to 0.

What am I missing here?

Thanks in advance!

developer0hye commented 1 year ago

Hi! @marinafridman

You must multiply normalized postion and the shape of image before converting int.

It's a python example.

import cv2
import numpy as np

img = cv2.imread("img.jpg")
img_h, img_w = img.shape[:2]

labels = np.loadtxt("label.txt")

for label in labels:
 class_idx, cx, cy, w, h = label
 cx *= img_w
 cy *= img_h
 w *= img_w
 h *= img_h

 cx = int(cx)
 cy = int(cy)
 w = int(w)
 h = int(h)
 # do your process
marinafridman commented 1 year ago

Perfect, thank you so much @developer0hye !