From f18228747c8508512f2bf68e4b884defcc504c97 Mon Sep 17 00:00:00 2001 From: cefeng06 Date: Mon, 11 Dec 2023 15:37:02 +0800 Subject: [PATCH] feat: export bbox & area for keypoints --- packages/app/src/utils/adapter.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/app/src/utils/adapter.ts b/packages/app/src/utils/adapter.ts index 2b6de38..1e2b671 100644 --- a/packages/app/src/utils/adapter.ts +++ b/packages/app/src/utils/adapter.ts @@ -135,12 +135,25 @@ export const convertToCocoDateset = ( keypoints.push(points[i * 6], points[i * 6 + 1], points[i * 6 + 4]); num_keypoints += 1; } + Object.assign(newAnnotation, { keypoints, num_keypoints, - area: 0, - bbox: [0, 0, 0, 0], }); + + if (annotation.boundingBox) { + const { x, y, width, height } = translateBoundingBoxToRect( + annotation.boundingBox, + { + width: image.width, + height: image.height, + }, + ); + const area = width * height; + const bbox = [x, y, width, height]; + Object.assign(newAnnotation, { area, bbox }); + } + const targetCategory = cocoDataset.categories.find( (item) => item.name === categoryName, );