[Object Detection] YOLO style 로 Bounding Box 값 바꾸기

728x90
반응형



기존 Bounding Box 좌표 값인 (x1, x2, y1, y2) 형식을
Yolo Style인 이미지 크기에 대한 비율 값으로 바꾸고, (centerX, centerY, w, h) 형식으로 바꾸는 소스코드이다.

def convert(size, box):
    dw = 1./size[0]
    dh = 1./size[1]
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

im=Image.open(img_path)
w= int(im.size[0])
h= int(im.size[1])


print(xmin, xmax, ymin, ymax) #define your x,y coordinates
b = (xmin, xmax, ymin, ymax)
bb = convert((w,h), b)



참고자료 :
https://stackoverflow.com/questions/56115874/how-to-convert-bounding-box-x1-y1-x2-y2-to-yolo-style-x-y-w-h

 

How to convert bounding box (x1, y1, x2, y2) to YOLO Style (X, Y, W, H)

I'm training a YOLO model, I have the bounding boxes in this format:- x1, y1, x2, y2 => ex (100, 100, 200, 200) I need to convert it to YOLO format to be something like:- X, Y, W, H => 0.436262 0.4...

stackoverflow.com

728x90
반응형