7/24/2021

yolo data coordinate format, draw rectangle by cv2

yolo v5 data coordinate format


 




ex)

str_v = "32 0.262 0.7878 0.314 0.385"



#read image

cvmat = cv2.imread(img_path)



#get height, width

h,w,_ = cvmat.shape



#extract x1, y1 <- center, width, height

x1 = int( float(str_v.split(' ')[1]) * w )

y1 = int( float(str_v.split(' ')[2]) * h )

xw = int( float(str_v.split(' ')[3]) * w /2)

yw = int( float(str_v.split(' ')[4]) * h /2)



#make x1,y1, x2,y2

start_point = (x1 - xw, y1 - yw )

end_point = (x1 + xw, y1 + yw )



#draw rectangle

cvmat = cv2.rectangle(cvmat, start_point, end_point, (255, 0, 0), 2)



Thank you.

https://study.marearts.com


No comments:

Post a Comment