I want to create image labeling program with opencv c++ to label images for yolo object detector, but i'm struggling in converting rectangle coordinates (x1,y1,x2,y2) to yolo format which is "object-class x_center y_center width height". And according to the documentation x_center and y_center are center of rectangle (are not top-left corner).
I tried this code on already labeled image
double centerX = (x1 + x2) / (2.0 * imageWidth);
double centerY = (y1 + y2) / (2.0 * imageHeight);
double width = double(abs(x2 - x1) / imageWidth);
double height = double(abs(y2- y1) / imageHeight);
and get
0 0.396759 0.278906 0.0109375 0.326852
which is deferent from
0 0.40703125 0.5194444444444445 0.25364583333333335 0.5851851851851851
.
How can i get it to work?