UNPKG

@adventurelabs/scout-core

Version:

Core utilities and helpers for Adventure Labs Scout applications

45 lines (44 loc) 1.31 kB
import { SelectionStatus, } from "../types/bounding_boxes"; export function convertManualBoundingBoxToTag(boundingBox, event_id) { const newClassName = boundingBox.label; // try to convert if nan, make it 0 let newId = Number(boundingBox.id); if (isNaN(newId)) { newId = 0; } const newTag = { id: newId, x: boundingBox.xCenterPercentage, y: boundingBox.yCenterPercentage, width: boundingBox.widthPercentage, height: boundingBox.heightPercentage, inserted_at: new Date().toISOString(), conf: 1, observation_type: "manual", class_name: newClassName, event_id: event_id, location: null, }; return newTag; } export function convertTagToBoundingBox(tag, source) { const newBoundingBox = { xCenterPercentage: tag.x, yCenterPercentage: tag.y, widthPercentage: tag.width, heightPercentage: tag.height, label: tag.class_name, id: tag.id ? tag.id.toString() : "0", left: 0, top: 0, width: 0, height: 0, anchorPoint: { x: 0, y: 0 }, status: SelectionStatus.ARCHIVED, source: source, }; return newBoundingBox; } export function formatBoundingBoxLabel(label) { return label; }