Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial working version of VOC XML import #280

Merged
merged 7 commits into from
Oct 10, 2022
Prev Previous commit
Next Next commit
Cleaner reducer function to not modify
  • Loading branch information
hartmannr76 committed Oct 5, 2022
commit 860b504a1d65c5eb8be61b842ec220f4364caea6
18 changes: 10 additions & 8 deletions src/logic/import/voc/VOCImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ export class VOCImporter extends AnnotationImporter {
const root = document.getElementsByTagName('annotation')[0];
const filename = root.getElementsByTagName('filename')[0].textContent;

const labeledBoxes: LabelRect[] = this.parseAnnotationsFromFileString(document, labelNames);
const [labeledBoxes, newLabelNames] = this.parseAnnotationsFromFileString(document, labelNames);

return {
labelNames,
labelNames: newLabelNames,
fileParseResults: fileParseResults.concat({
filename,
labeledBoxes
}),
};
}

protected static parseAnnotationsFromFileString(document: Document, labelNames: Record<string, LabelName>): LabelRect[] {
return Array.from(document.getElementsByTagName('object')).map(d => {
protected static parseAnnotationsFromFileString(document: Document, labelNames: Record<string, LabelName>):
[LabelRect[], Record<string, LabelName>] {
const newLabelNames: Record<string, LabelName> = Object.assign(labelNames);
return [Array.from(document.getElementsByTagName('object')).map(d => {
const labelName = d.getElementsByTagName('name')[0].textContent;
const bbox = d.getElementsByTagName('bndbox')[0];
const xmin = parseInt(bbox.getElementsByTagName('xmin')[0].textContent);
Expand All @@ -82,14 +84,14 @@ export class VOCImporter extends AnnotationImporter {
width: xmax - xmin,
};

if (!labelNames[labelName]) {
labelNames[labelName] = LabelUtil.createLabelName(labelName);
if (!newLabelNames[labelName]) {
newLabelNames[labelName] = LabelUtil.createLabelName(labelName);
}

const labelId = labelNames[labelName].id;
const labelId = newLabelNames[labelName].id;

return LabelUtil.createLabelRect(labelId, rect);
});
}), newLabelNames];
}

private static mapImageData(): Record<string, ImageData> {
Expand Down