Skip to content

Commit

Permalink
feat: Support rectTool to export Yolo format data
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinghua123 committed Jun 2, 2022
1 parent 01f641c commit 4b731e6
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/utils/DataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export default class DataTransfer {
},
];
let idString = '';
let ids = '';
/**
* 提取步骤中的配置 - 将 attributeList 同步至 categories
*/
Expand All @@ -311,12 +310,7 @@ export default class DataTransfer {
);
}
categories.forEach((v: any, i: number) => {
if (i === categories.length - 1) {
ids = `${v.id} ${v.value ? v.value : null}`;
} else {
ids = `${v.id} ${v.value ? v.value : null}` + '\n';
}
idString = idString + ids;
idString += `${v.id} ${v.value}` + '\n';
});

return { categories, idString };
Expand All @@ -329,7 +323,6 @@ export default class DataTransfer {
*/
public static transferDefault2Yolo(result: any, categories: any[]) {
let dataString = '';
let data = '';
const width = result?.width ?? 0;
const height = result?.height ?? 0;

Expand All @@ -346,12 +339,12 @@ export default class DataTransfer {
const ratioWidth = (bboxWidth / width).toFixed(6);
const ratioHeight = (bboxHeight / height).toFixed(6);
const labelClass = category.id ?? -1;
if (i === result?.step_1?.result?.length - 1) {
data = `${labelClass} ${ratioX} ${ratioY} ${ratioWidth} ${ratioHeight}`;
} else {
data = `${labelClass} ${ratioX} ${ratioY} ${ratioWidth} ${ratioHeight}` + '\n';
dataString += `${labelClass} ${ratioX} ${ratioY} ${ratioWidth} ${ratioHeight}`;

// 非最后一行都加换行
if (i !== result?.step_1?.result?.length - 1) {
dataString = dataString + '\n';
}
dataString = dataString + data;
});
}

Expand Down

0 comments on commit 4b731e6

Please sign in to comment.