问题描述
我正在尝试开发一种在格式之间转换注释的方法,很难找到信息,但是这里有:
这是PASCAL VOC
<width>800</width>
<height>450</height>
<depth>3</depth>
<bndBox>
<xmin>474</xmin>
<ymin>2</ymin>
<xmax>726</xmax> <!-- shape_width = 252 -->
<ymax>449</ymax> <!-- shape_height = 447 -->
</bndBox>
转换为 YOLO暗网
2 0.750000 0.501111 0.315000 0.993333
请注意首字母2
是一个类别
解决方法
使用一些数学运算:(对COCO也可能有用)
categ_index [(xmin + xmax) / 2 / image_width] [(ymin + ymax) / 2 / image_height] [(xmax - xmin) / image_width] [(ymax - ymin) / image_height]
在js代码中
const categ_index = 2;
const { width: image_width,height: image_height } = {
width: 800,height: 450,};
const { xmin,ymin,xmax,ymax } = {
xmin: 474,ymin: 2,xmax: 727,ymax: 449,};
const x_coord = (xmin + xmax) / 2 / image_width;
const y_coord = (ymin + ymax) / 2 / image_height;
const shape_width = (xmax - xmin) / image_width;
const shape_height = (ymax - ymin) / image_height;
console.log(`${categ_index} ${x_coord.toFixed(7)} ${y_coord.toFixed(7)} ${shape_width.toFixed(7)} ${shape_height.toFixed(7)}`);