label-studio-converter 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1076 -53
- package/dist/bash-complete.cjs +1285 -530
- package/dist/bash-complete.cjs.map +1 -1
- package/dist/bash-complete.js +1278 -524
- package/dist/bash-complete.js.map +1 -1
- package/dist/cli.cjs +1284 -529
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1278 -524
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +864 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +136 -17
- package/dist/index.d.ts +136 -17
- package/dist/index.js +849 -55
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/index.ts","../src/lib/label-studio.ts","../src/lib/ppocr-label.ts","../src/constants.ts"],"sourcesContent":["export * from './label-studio';\nexport * from './ppocr-label';\n","import * as turf from '@turf/turf';\nimport {\n type FullOCRLabelStudio,\n type MinOCRLabelStudio,\n type PPOCRLabel,\n} from '@/lib/schema';\n\nexport const labelStudioToPPOCR = async (\n data: FullOCRLabelStudio,\n baseImageDir?: string,\n): Promise<Map<string, PPOCRLabel>> => {\n const resultMap = new Map<string, PPOCRLabel>();\n\n for (const task of data) {\n // Extract image path from data.ocr (full path with URL) or file_upload (just filename)\n let imagePath = task.file_upload || '';\n if (task.data.ocr) {\n // Extract path from URL: http://localhost:8081/ch/image.jpg -> ch/image.jpg\n const urlPath = task.data.ocr.replace(/^https?:\\/\\/[^/]+\\//, '');\n imagePath = decodeURIComponent(urlPath);\n }\n\n // Apply baseImageDir if provided\n if (baseImageDir) {\n imagePath = `${baseImageDir}/${task.file_upload || imagePath.split('/').pop() || imagePath}`;\n }\n\n const imageAnnotations: PPOCRLabel = [];\n\n // Process each annotation in the task\n for (const annotation of task.annotations) {\n // Group result items by their ID to avoid duplicates\n // (polygon, labels, and textarea share the same ID)\n const groupedById = new Map<string, typeof annotation.result>();\n\n for (const resultItem of annotation.result) {\n const { id } = resultItem;\n if (!groupedById.has(id)) {\n groupedById.set(id, []);\n }\n groupedById.get(id)!.push(resultItem);\n }\n\n // Process each group of result items (with same ID)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for (const [_, resultItems] of groupedById) {\n let points: number[][] | undefined;\n let transcription = '';\n\n // Process all result items in this group to extract points and transcription\n for (const resultItem of resultItems) {\n // Extract points from different value types\n if ('points' in resultItem.value && resultItem.value.points) {\n // Polygon/polyline with percentage points - convert to absolute\n const { points: valuePoints } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n // Convert percentage coordinates to absolute pixels\n points = valuePoints.map(([x, y]) => [\n ((x ?? 0) * original_width) / 100,\n ((y ?? 0) * original_height) / 100,\n ]);\n } else if (\n 'x' in resultItem.value &&\n 'y' in resultItem.value &&\n 'width' in resultItem.value &&\n 'height' in resultItem.value\n ) {\n // Rectangle - convert to 4 corner points\n const { x, y, width, height } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n // Convert normalized values to absolute coordinates\n const absX = (x * original_width) / 100;\n const absY = (y * original_height) / 100;\n const absWidth = (width * original_width) / 100;\n const absHeight = (height * original_height) / 100;\n\n points = [\n [absX, absY],\n [absX + absWidth, absY],\n [absX + absWidth, absY + absHeight],\n [absX, absY + absHeight],\n ];\n }\n\n // Extract transcription from text field\n if (\n 'text' in resultItem.value &&\n Array.isArray(resultItem.value.text)\n ) {\n transcription = resultItem.value.text[0] || '';\n }\n }\n\n // If we have points, create a PPOCRLabel entry\n if (points && points.length > 0) {\n // Calculate dt_score based on polygon area\n let dt_score = 1.0;\n try {\n const firstPoint = points[0];\n if (firstPoint) {\n const polygon = turf.polygon([points.concat([firstPoint])]);\n const area = turf.area(polygon);\n dt_score = Math.min(1.0, Math.max(0.5, area / 10000));\n }\n } catch {\n dt_score = 0.8;\n }\n\n imageAnnotations.push({\n transcription,\n points,\n dt_score,\n });\n }\n }\n }\n\n if (imageAnnotations.length > 0) {\n resultMap.set(imagePath, imageAnnotations);\n }\n }\n\n return resultMap;\n};\n\nexport const minLabelStudioToPPOCR = async (\n data: MinOCRLabelStudio,\n baseImageDir?: string,\n): Promise<Map<string, PPOCRLabel>> => {\n const resultMap = new Map<string, PPOCRLabel>();\n\n for (const item of data) {\n // Extract image path from ocr URL\n let imagePath = item.ocr || '';\n if (imagePath) {\n // Extract path from URL: http://localhost:8081/ch/image.jpg -> ch/image.jpg\n imagePath = decodeURIComponent(\n imagePath.replace(/^https?:\\/\\/[^/]+\\//, ''),\n );\n }\n\n // Apply baseImageDir if provided\n if (baseImageDir) {\n imagePath = `${baseImageDir}/${imagePath.split('/').pop() || imagePath}`;\n }\n\n // Use poly if available, otherwise convert from bbox\n let points: number[][];\n\n if (item.poly.length > 0 && item.poly[0]) {\n const { points: polyPoints } = item.poly[0];\n points = polyPoints;\n } else if (item.bbox.length > 0 && item.bbox[0]) {\n const bbox = item.bbox[0];\n const { x, y, width, height } = bbox;\n\n // Convert bbox to 4 corner points\n points = [\n [x, y],\n [x + width, y],\n [x + width, y + height],\n [x, y + height],\n ];\n } else {\n // Skip if no geometry data\n continue;\n }\n\n // Get transcription text (not the URL)\n const transcription =\n item.transcription.length > 0 ? item.transcription[0] : '';\n\n // Calculate dt_score based on polygon area\n let dt_score = 1.0;\n try {\n const firstPoint = points[0];\n if (firstPoint) {\n const polygon = turf.polygon([points.concat([firstPoint])]);\n const area = turf.area(polygon);\n dt_score = Math.min(1.0, Math.max(0.5, area / 10000));\n }\n } catch {\n dt_score = 0.8;\n }\n\n const annotation = {\n transcription: transcription ?? '',\n points,\n dt_score,\n };\n\n // Group by image path\n if (!resultMap.has(imagePath)) {\n resultMap.set(imagePath, []);\n }\n resultMap.get(imagePath)!.push(annotation);\n }\n\n return resultMap;\n};\n","import { randomUUID } from 'node:crypto';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport sizeOf from 'image-size';\nimport { DEFAULT_LABEL_NAME } from '@/constants';\nimport {\n type FullOCRLabelStudio,\n type MinOCRLabelStudio,\n type PPOCRLabel,\n} from '@/lib/schema';\n\nexport type ToLabelStudioOptions = {\n imagePath: string;\n baseServerUrl: string;\n inputDir?: string;\n toFullJson?: boolean;\n taskId?: number;\n labelName?: string;\n};\n\nexport const ppocrToLabelStudio = async (\n data: PPOCRLabel,\n options: ToLabelStudioOptions,\n): Promise<FullOCRLabelStudio | MinOCRLabelStudio> => {\n const {\n imagePath,\n baseServerUrl,\n inputDir,\n toFullJson = true,\n taskId = 1,\n labelName = DEFAULT_LABEL_NAME,\n } = options || {};\n\n if (toFullJson) {\n return ppocrToFullLabelStudio(\n data,\n imagePath,\n baseServerUrl,\n inputDir,\n taskId,\n labelName,\n );\n } else {\n return ppocrToMinLabelStudio(\n data,\n imagePath,\n baseServerUrl,\n inputDir,\n labelName,\n );\n }\n};\n\nexport const ppocrToFullLabelStudio = (\n data: PPOCRLabel,\n imagePath: string,\n baseServerUrl: string,\n inputDir?: string,\n taskId: number = 1,\n labelName: string = DEFAULT_LABEL_NAME,\n): FullOCRLabelStudio => {\n const newBaseServerUrl =\n baseServerUrl.replace(/\\/+$/, '') + (baseServerUrl === '' ? '' : '/');\n\n const now = new Date().toISOString();\n\n // Get actual image dimensions from the image file\n let original_width = 1920;\n let original_height = 1080;\n\n // Resolve absolute path to image file\n const resolvedImagePath = inputDir ? join(inputDir, imagePath) : imagePath;\n\n if (!existsSync(resolvedImagePath)) {\n throw new Error(`Image file not found: ${resolvedImagePath}`);\n }\n\n const buffer = readFileSync(resolvedImagePath);\n const dimensions = sizeOf(buffer);\n if (!dimensions.width || !dimensions.height) {\n throw new Error(\n `Failed to read image dimensions from: ${resolvedImagePath}`,\n );\n }\n original_width = dimensions.width;\n original_height = dimensions.height;\n\n // Extract filename from imagePath for file_upload (just the filename)\n const fileName = imagePath.split('/').pop() || imagePath;\n\n // Group all PPOCRLabel items into a single task with one annotation\n const result: FullOCRLabelStudio = [\n {\n id: taskId,\n annotations: [\n {\n id: taskId,\n completed_by: 1,\n result: data\n .map((item) => {\n const { points } = item;\n\n // Generate a single ID for all three related annotations\n const annotationId = randomUUID().slice(0, 10);\n const polygonPoints = points.map(([x, y]) => [\n ((x ?? 0) / original_width) * 100,\n ((y ?? 0) / original_height) * 100,\n ]);\n\n // Create result items: polygon, labels, and textarea\n return [\n // 1. Polygon geometry only\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n },\n id: annotationId,\n from_name: 'poly',\n to_name: 'image',\n type: 'polygon',\n origin: 'manual',\n },\n // 2. Labels with polygon geometry\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n labels: [labelName],\n },\n id: annotationId,\n from_name: 'label',\n to_name: 'image',\n type: 'labels',\n origin: 'manual',\n },\n // 3. Textarea with polygon geometry and text\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n text: [item.transcription],\n },\n id: annotationId,\n from_name: 'transcription',\n to_name: 'image',\n type: 'textarea',\n origin: 'manual',\n },\n ];\n })\n .flat(),\n was_cancelled: false,\n ground_truth: false,\n created_at: now,\n updated_at: now,\n draft_created_at: now,\n lead_time: 0,\n prediction: {},\n result_count: data.length * 3,\n unique_id: randomUUID(),\n import_id: null,\n last_action: null,\n bulk_created: false,\n task: taskId,\n project: 1,\n updated_by: 1,\n parent_prediction: null,\n parent_annotation: null,\n last_created_by: null,\n },\n ],\n file_upload: fileName,\n drafts: [],\n predictions: [],\n data: { ocr: `${newBaseServerUrl}${imagePath}` },\n meta: {},\n created_at: now,\n updated_at: now,\n allow_skip: false,\n inner_id: taskId,\n total_annotations: 1,\n cancelled_annotations: 0,\n total_predictions: 0,\n comment_count: 0,\n unresolved_comment_count: 0,\n last_comment_updated_at: null,\n project: 1,\n updated_by: 1,\n comment_authors: [],\n },\n ];\n\n return result;\n};\n\nexport const ppocrToMinLabelStudio = (\n data: PPOCRLabel,\n imagePath: string,\n baseServerUrl: string,\n inputDir?: string,\n labelName: string = 'text',\n): MinOCRLabelStudio => {\n const newBaseServerUrl =\n baseServerUrl.replace(/\\/+$/, '') + (baseServerUrl === '' ? '' : '/');\n\n const now = new Date().toISOString();\n\n // Get actual image dimensions from the image file\n let original_width = 1920;\n let original_height = 1080;\n\n // Resolve absolute path to image file\n const resolvedImagePath = inputDir ? join(inputDir, imagePath) : imagePath;\n\n if (!existsSync(resolvedImagePath)) {\n throw new Error(`Image file not found: ${resolvedImagePath}`);\n }\n\n const buffer = readFileSync(resolvedImagePath);\n const dimensions = sizeOf(buffer);\n if (!dimensions.width || !dimensions.height) {\n throw new Error(\n `Failed to read image dimensions from: ${resolvedImagePath}`,\n );\n }\n original_width = dimensions.width;\n original_height = dimensions.height;\n\n return data.map((item, index) => {\n const { points } = item;\n\n // Calculate bbox from points\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const point of points) {\n const [x, y] = point;\n if (x !== undefined && y !== undefined) {\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n }\n\n const width = maxX - minX;\n const height = maxY - minY;\n\n return {\n ocr: encodeURI(`${newBaseServerUrl}${imagePath}`),\n id: index + 1,\n bbox: [\n {\n x: minX,\n y: minY,\n width,\n height,\n rotation: 0,\n original_width,\n original_height,\n },\n ],\n label: [\n {\n points: points,\n closed: true,\n labels: [labelName],\n original_width,\n original_height,\n },\n ],\n transcription: [item.transcription],\n poly: [\n {\n points: points,\n closed: true,\n original_width,\n original_height,\n },\n ],\n annotator: 1,\n annotation_id: index + 1,\n created_at: now,\n updated_at: now,\n lead_time: 0,\n };\n });\n};\n","export const OUTPUT_BASE_DIR = './output';\n\nexport const DEFAULT_LABEL_NAME = 'Text';\nexport const DEFAULT_LABEL_STUDIO_FULL_JSON = true;\nexport const DEFAULT_CREATE_FILE_PER_IMAGE = false;\nexport const DEFAULT_CREATE_FILE_LIST_FOR_SERVING = true;\nexport const DEFAULT_FILE_LIST_NAME = 'files.txt';\nexport const DEFAULT_BASE_SERVER_URL = 'http://localhost:8081';\n\nexport const DEFAULT_PPOCR_FILE_NAME = 'Label.txt';\n\n// Vertical sorting options\nexport const SORT_VERTICAL_NONE = 'none';\nexport const SORT_VERTICAL_TOP_BOTTOM = 'top-bottom';\nexport const SORT_VERTICAL_BOTTOM_TOP = 'bottom-top';\nexport const DEFAULT_SORT_VERTICAL = SORT_VERTICAL_NONE;\n\n// Horizontal sorting options\nexport const SORT_HORIZONTAL_NONE = 'none';\nexport const SORT_HORIZONTAL_LTR = 'ltr';\nexport const SORT_HORIZONTAL_RTL = 'rtl';\nexport const DEFAULT_SORT_HORIZONTAL = SORT_HORIZONTAL_NONE;\n\nexport type VerticalSortOrder =\n | typeof SORT_VERTICAL_NONE\n | typeof SORT_VERTICAL_TOP_BOTTOM\n | typeof SORT_VERTICAL_BOTTOM_TOP;\n\nexport type HorizontalSortOrder =\n | typeof SORT_HORIZONTAL_NONE\n | typeof SORT_HORIZONTAL_LTR\n | typeof SORT_HORIZONTAL_RTL;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,WAAsB;AAOf,IAAM,qBAAqB,OAChC,MACA,iBACqC;AACrC,QAAM,YAAY,oBAAI,IAAwB;AAE9C,aAAW,QAAQ,MAAM;AAEvB,QAAI,YAAY,KAAK,eAAe;AACpC,QAAI,KAAK,KAAK,KAAK;AAEjB,YAAM,UAAU,KAAK,KAAK,IAAI,QAAQ,uBAAuB,EAAE;AAC/D,kBAAY,mBAAmB,OAAO;AAAA,IACxC;AAGA,QAAI,cAAc;AAChB,kBAAY,GAAG,YAAY,IAAI,KAAK,eAAe,UAAU,MAAM,GAAG,EAAE,IAAI,KAAK,SAAS;AAAA,IAC5F;AAEA,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IAAI,MAAM,CAAC;AACvB,eAAO,KAAK,IAAI,MAAM,CAAC;AACvB,eAAO,KAAK,IAAI,MAAM,CAAC;AAAA,MACzB;AAAA,IACF;AAEA,UAAM,QAAQ,OAAO;AACrB,UAAM,SAAS,OAAO;AAEtB,WAAO;AAAA,MACL,KAAK,UAAU,GAAG,gBAAgB,GAAG,SAAS,EAAE;AAAA,MAChD,IAAI,QAAQ;AAAA,MACZ,MAAM;AAAA,QACJ;AAAA,UACE,GAAG;AAAA,UACH,GAAG;AAAA,UACH;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACV;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,OAAO;AAAA,QACL;AAAA,UACE;AAAA,UACA,QAAQ;AAAA,UACR,QAAQ,CAAC,SAAS;AAAA,UAClB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,eAAe,CAAC,KAAK,aAAa;AAAA,MAClC,MAAM;AAAA,QACJ;AAAA,UACE;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,WAAW;AAAA,MACX,eAAe,QAAQ;AAAA,MACvB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,WAAW;AAAA,IACb;AAAA,EACF,CAAC;AACH;","names":["polygon","area","sizeOf"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/index.ts","../src/lib/schema.ts","../src/lib/label-studio.ts","../src/lib/geometry.ts","../src/constants.ts","../src/lib/sort.ts","../src/lib/enhance.ts","../src/lib/ppocr-label.ts"],"sourcesContent":["// Schema exports\nexport * from './schema';\n\n// Conversion functions\nexport * from './label-studio';\nexport * from './ppocr-label';\n\n// Enhancement functions\nexport * from './enhance';\n\n// Utility functions\nexport * from './geometry';\nexport * from './sort';\n","import z from 'zod';\n\nexport const FullOCRLabelStudioSchema = z.array(\n z.object({\n id: z.number(),\n annotations: z.array(\n z.object({\n id: z.number(),\n completed_by: z.number(),\n result: z.array(\n z.union([\n // Most specific rectangle variants first (with text or labels)\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n text: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n labels: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Base rectangle without text or labels\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Most specific polygon variants first (with text or labels)\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n text: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n labels: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Base polygon without text or labels\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n ]),\n ),\n was_cancelled: z.boolean(),\n ground_truth: z.boolean(),\n created_at: z.string(),\n updated_at: z.string(),\n draft_created_at: z.string(),\n lead_time: z.number(),\n prediction: z.object({}),\n result_count: z.number(),\n unique_id: z.string(),\n import_id: z.null(),\n last_action: z.null(),\n bulk_created: z.boolean(),\n task: z.number(),\n project: z.number(),\n updated_by: z.number(),\n parent_prediction: z.null(),\n parent_annotation: z.null(),\n last_created_by: z.null(),\n }),\n ),\n file_upload: z.string(),\n drafts: z.array(\n z.object({\n id: z.number(),\n user: z.string(),\n created_username: z.string(),\n created_ago: z.string(),\n result: z.array(\n z.union([\n // Most specific rectangle variants first (with text or labels)\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n text: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n labels: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Base rectangle without text or labels\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Most specific polygon variants first (with text or labels)\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n text: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n labels: z.array(z.string()),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n // Base polygon without text or labels\n z.object({\n original_width: z.number(),\n original_height: z.number(),\n image_rotation: z.number(),\n value: z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n }),\n id: z.string(),\n from_name: z.string(),\n to_name: z.string(),\n type: z.string(),\n origin: z.string(),\n }),\n ]),\n ),\n lead_time: z.number(),\n was_postponed: z.boolean(),\n import_id: z.null(),\n created_at: z.string(),\n updated_at: z.string(),\n task: z.number(),\n annotation: z.number(),\n }),\n ),\n predictions: z.array(z.unknown()),\n data: z.object({ ocr: z.string() }),\n meta: z.object({}),\n created_at: z.string(),\n updated_at: z.string(),\n allow_skip: z.boolean(),\n inner_id: z.number(),\n total_annotations: z.number(),\n cancelled_annotations: z.number(),\n total_predictions: z.number(),\n comment_count: z.number(),\n unresolved_comment_count: z.number(),\n last_comment_updated_at: z.null(),\n project: z.number(),\n updated_by: z.number(),\n comment_authors: z.array(z.unknown()),\n }),\n);\n\nexport const MinOCRLabelStudioSchema = z.array(\n z.object({\n ocr: z.string(),\n id: z.number(),\n bbox: z\n .array(\n z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n original_width: z.number(),\n original_height: z.number(),\n }),\n )\n .optional()\n .default([]),\n label: z\n .array(\n z.union([\n z.object({\n x: z.number(),\n y: z.number(),\n width: z.number(),\n height: z.number(),\n rotation: z.number(),\n labels: z.array(z.string()),\n original_width: z.number(),\n original_height: z.number(),\n }),\n z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n labels: z.array(z.string()),\n original_width: z.number(),\n original_height: z.number(),\n }),\n ]),\n )\n .optional()\n .default([]),\n transcription: z\n .union([z.string(), z.array(z.string())])\n .optional()\n .transform((val) => {\n if (!val) return [];\n return Array.isArray(val) ? val : [val];\n }),\n poly: z\n .array(\n z.object({\n points: z.array(z.array(z.number())),\n closed: z.boolean(),\n original_width: z.number(),\n original_height: z.number(),\n }),\n )\n .optional()\n .default([]),\n annotator: z.number(),\n annotation_id: z.number(),\n created_at: z.string(),\n updated_at: z.string(),\n lead_time: z.number(),\n }),\n);\n\nexport const PPOCRLabelSchema = z.array(\n z.object({\n transcription: z.string(),\n points: z.array(z.array(z.number())),\n dt_score: z.number().optional(), // Detection score (from PaddleOCR)\n difficult: z.boolean().optional(), // Difficult flag (from PPOCRLabel tool)\n }),\n);\n\nexport type FullOCRLabelStudio = z.infer<typeof FullOCRLabelStudioSchema>;\nexport type MinOCRLabelStudio = z.infer<typeof MinOCRLabelStudioSchema>;\nexport type PPOCRLabel = z.infer<typeof PPOCRLabelSchema>;\n","import * as turf from '@turf/turf';\nimport { type ShapeNormalizeOption } from '@/constants';\nimport { type EnhancementOptions, enhancePPOCRLabel } from '@/lib/enhance';\nimport { type Point, roundPoints, transformPoints } from '@/lib/geometry';\nimport {\n type FullOCRLabelStudio,\n type MinOCRLabelStudio,\n type PPOCRLabel,\n} from '@/lib/schema';\n\nexport interface ConversionOptions {\n baseImageDir?: string;\n normalizeShape?: ShapeNormalizeOption;\n widthIncrement?: number;\n heightIncrement?: number;\n precision?: number;\n}\n\nexport const labelStudioToPPOCR = async (\n data: FullOCRLabelStudio,\n options?: ConversionOptions,\n): Promise<Map<string, PPOCRLabel>> => {\n const {\n baseImageDir,\n normalizeShape,\n widthIncrement = 0,\n heightIncrement = 0,\n precision = 0,\n } = options || {};\n const resultMap = new Map<string, PPOCRLabel>();\n\n for (const task of data) {\n // Extract image path from data.ocr (full path with URL) or file_upload (just filename)\n let imagePath = task.file_upload || '';\n if (task.data.ocr) {\n // Extract path from URL: http://localhost:8081/ch/image.jpg -> ch/image.jpg\n const urlPath = task.data.ocr.replace(/^https?:\\/\\/[^/]+\\//, '');\n imagePath = decodeURIComponent(urlPath);\n }\n\n // Apply baseImageDir if provided\n if (baseImageDir) {\n imagePath = `${baseImageDir}/${task.file_upload || imagePath.split('/').pop() || imagePath}`;\n }\n\n const imageAnnotations: PPOCRLabel = [];\n\n // Process each annotation in the task\n for (const annotation of task.annotations) {\n // Group result items by their ID to avoid duplicates\n // (polygon, labels, and textarea share the same ID)\n const groupedById = new Map<string, typeof annotation.result>();\n\n for (const resultItem of annotation.result) {\n const { id } = resultItem;\n if (!groupedById.has(id)) {\n groupedById.set(id, []);\n }\n groupedById.get(id)!.push(resultItem);\n }\n\n // Process each group of result items (with same ID)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for (const [_, resultItems] of groupedById) {\n let points: number[][] | undefined;\n let transcription = '';\n\n // Process all result items in this group to extract points and transcription\n for (const resultItem of resultItems) {\n // Extract points from different value types\n if ('points' in resultItem.value && resultItem.value.points) {\n // Polygon/polyline with percentage points - convert to absolute\n const { points: valuePoints } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n // Convert percentage coordinates to absolute pixels\n points = valuePoints.map(([x, y]) => [\n ((x ?? 0) * original_width) / 100,\n ((y ?? 0) * original_height) / 100,\n ]);\n } else if (\n 'x' in resultItem.value &&\n 'y' in resultItem.value &&\n 'width' in resultItem.value &&\n 'height' in resultItem.value\n ) {\n // Rectangle - convert to 4 corner points\n const { x, y, width, height } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n // Convert normalized values to absolute coordinates\n const absX = (x * original_width) / 100;\n const absY = (y * original_height) / 100;\n const absWidth = (width * original_width) / 100;\n const absHeight = (height * original_height) / 100;\n\n points = [\n [absX, absY],\n [absX + absWidth, absY],\n [absX + absWidth, absY + absHeight],\n [absX, absY + absHeight],\n ];\n }\n\n // Extract transcription from text field\n if (\n 'text' in resultItem.value &&\n Array.isArray(resultItem.value.text)\n ) {\n transcription = resultItem.value.text[0] || '';\n }\n }\n\n // If we have points, create a PPOCRLabel entry\n if (points && points.length > 0) {\n // Apply geometry transformations\n points = transformPoints(points as Point[], {\n normalizeShape,\n widthIncrement,\n heightIncrement,\n });\n\n // Round points to specified precision\n points = roundPoints(points as Point[], precision);\n\n // Calculate dt_score based on polygon area\n let dt_score = 1.0;\n try {\n const firstPoint = points[0];\n if (firstPoint) {\n const polygon = turf.polygon([points.concat([firstPoint])]);\n const area = turf.area(polygon);\n dt_score = Math.min(1.0, Math.max(0.5, area / 10000));\n }\n } catch {\n dt_score = 0.8;\n }\n\n imageAnnotations.push({\n transcription,\n points,\n dt_score,\n });\n }\n }\n }\n\n if (imageAnnotations.length > 0) {\n resultMap.set(imagePath, imageAnnotations);\n }\n }\n\n return resultMap;\n};\n\nexport const minLabelStudioToPPOCR = async (\n data: MinOCRLabelStudio,\n options?: ConversionOptions,\n): Promise<Map<string, PPOCRLabel>> => {\n const {\n baseImageDir,\n normalizeShape,\n widthIncrement = 0,\n heightIncrement = 0,\n precision = 0,\n } = options || {};\n const resultMap = new Map<string, PPOCRLabel>();\n\n for (const item of data) {\n // Extract image path from ocr URL\n let imagePath = item.ocr || '';\n if (imagePath) {\n // Extract path from URL: http://localhost:8081/ch/image.jpg -> ch/image.jpg\n imagePath = decodeURIComponent(\n imagePath.replace(/^https?:\\/\\/[^/]+\\//, ''),\n );\n }\n\n // Apply baseImageDir if provided\n if (baseImageDir) {\n imagePath = `${baseImageDir}/${imagePath.split('/').pop() || imagePath}`;\n }\n\n // Process each bbox/poly with its corresponding transcription\n const numAnnotations = Math.max(\n item.poly?.length || 0,\n item.bbox?.length || 0,\n item.transcription?.length || 0,\n );\n\n for (let i = 0; i < numAnnotations; i++) {\n let points: number[][] | undefined;\n\n // Use poly if available, otherwise convert from bbox\n if (item.poly && item.poly.length > i && item.poly[i]) {\n const poly = item.poly[i];\n if (poly) {\n const { points: polyPoints } = poly;\n points = polyPoints;\n }\n } else if (item.bbox && item.bbox.length > i && item.bbox[i]) {\n const bbox = item.bbox[i];\n if (bbox) {\n const { x, y, width, height } = bbox;\n\n // Convert bbox to 4 corner points\n points = [\n [x, y],\n [x + width, y],\n [x + width, y + height],\n [x, y + height],\n ];\n }\n }\n\n // Skip if no geometry data for this annotation\n if (!points) {\n continue;\n }\n\n // Apply geometry transformations\n points = transformPoints(points as Point[], {\n normalizeShape,\n widthIncrement,\n heightIncrement,\n });\n\n // Round points to specified precision\n points = roundPoints(points as Point[], precision);\n\n // Get transcription text for this annotation\n const transcription =\n item.transcription && item.transcription.length > i\n ? item.transcription[i]\n : '';\n\n // Calculate dt_score based on polygon area\n let dt_score = 1.0;\n try {\n const firstPoint = points[0];\n if (firstPoint) {\n const polygon = turf.polygon([points.concat([firstPoint])]);\n const area = turf.area(polygon);\n dt_score = Math.min(1.0, Math.max(0.5, area / 10000));\n }\n } catch {\n dt_score = 0.8;\n }\n\n const annotation = {\n transcription: transcription ?? '',\n points,\n dt_score,\n };\n\n // Group by image path\n if (!resultMap.has(imagePath)) {\n resultMap.set(imagePath, []);\n }\n resultMap.get(imagePath)!.push(annotation);\n }\n }\n\n return resultMap;\n};\n\n/**\n * Enhance Label Studio data (both Full and Min formats) with sorting, normalization, and resizing\n */\nexport const enhanceLabelStudioData = async (\n data: FullOCRLabelStudio | MinOCRLabelStudio,\n isFull: boolean,\n options: EnhancementOptions,\n): Promise<FullOCRLabelStudio | MinOCRLabelStudio> => {\n const {\n sortVertical,\n sortHorizontal,\n normalizeShape,\n widthIncrement = 0,\n heightIncrement = 0,\n precision = 0,\n } = options;\n\n if (isFull) {\n const fullData = data as FullOCRLabelStudio;\n return fullData.map((task) => ({\n ...task,\n annotations: task.annotations.map((annotation) => {\n // Group result items by their ID\n const groupedById = new Map<string, typeof annotation.result>();\n\n for (const resultItem of annotation.result) {\n const { id } = resultItem;\n if (!groupedById.has(id)) {\n groupedById.set(id, []);\n }\n groupedById.get(id)!.push(resultItem);\n }\n\n // Process each group and enhance\n const enhancedResult: typeof annotation.result = [];\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n for (const [_, resultItems] of groupedById) {\n // Collect all items in group to extract points\n let ppocrAnnotations: PPOCRLabel = [];\n\n for (const resultItem of resultItems) {\n let points: number[][] | undefined;\n\n // Extract points\n if ('points' in resultItem.value && resultItem.value.points) {\n const { points: valuePoints } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n points = valuePoints.map(([x, y]) => [\n ((x ?? 0) * original_width) / 100,\n ((y ?? 0) * original_height) / 100,\n ]);\n } else if (\n 'x' in resultItem.value &&\n 'y' in resultItem.value &&\n 'width' in resultItem.value &&\n 'height' in resultItem.value\n ) {\n const { x, y, width, height } = resultItem.value;\n const { original_width, original_height } = resultItem;\n\n const absX = (x * original_width) / 100;\n const absY = (y * original_height) / 100;\n const absWidth = (width * original_width) / 100;\n const absHeight = (height * original_height) / 100;\n\n points = [\n [absX, absY],\n [absX + absWidth, absY],\n [absX + absWidth, absY + absHeight],\n [absX, absY + absHeight],\n ];\n }\n\n if (points) {\n ppocrAnnotations.push({\n transcription: '',\n points: points as Point[],\n dt_score: 1.0,\n });\n }\n }\n\n // Apply enhancements\n if (ppocrAnnotations.length > 0) {\n ppocrAnnotations = enhancePPOCRLabel(ppocrAnnotations, {\n sortVertical,\n sortHorizontal,\n normalizeShape,\n widthIncrement,\n heightIncrement,\n precision,\n });\n\n // Convert back to Label Studio format\n for (let i = 0; i < resultItems.length; i++) {\n const resultItem = resultItems[i]!;\n const enhanced = ppocrAnnotations[i];\n\n if (!enhanced) {\n enhancedResult.push(resultItem);\n continue;\n }\n\n // Update the points in the result item\n if ('points' in resultItem.value && resultItem.value.points) {\n const { original_width, original_height } = resultItem;\n\n enhancedResult.push({\n ...resultItem,\n value: {\n ...resultItem.value,\n points: enhanced.points.map(\n ([x, y]) =>\n [\n ((x ?? 0) / original_width) * 100,\n ((y ?? 0) / original_height) * 100,\n ] as [number, number],\n ),\n },\n });\n } else if (\n 'x' in resultItem.value &&\n 'y' in resultItem.value &&\n 'width' in resultItem.value &&\n 'height' in resultItem.value\n ) {\n // Convert back to bbox format\n const { original_width, original_height } = resultItem;\n const xs = enhanced.points.map(([x]) => x ?? 0);\n const ys = enhanced.points.map(([, y]) => y ?? 0);\n const minX = Math.min(...xs);\n const maxX = Math.max(...xs);\n const minY = Math.min(...ys);\n const maxY = Math.max(...ys);\n\n enhancedResult.push({\n ...resultItem,\n value: {\n ...resultItem.value,\n x: (minX / original_width) * 100,\n y: (minY / original_height) * 100,\n width: ((maxX - minX) / original_width) * 100,\n height: ((maxY - minY) / original_height) * 100,\n },\n });\n } else {\n enhancedResult.push(resultItem);\n }\n }\n } else {\n enhancedResult.push(...resultItems);\n }\n }\n\n return {\n ...annotation,\n result: enhancedResult,\n };\n }),\n }));\n } else {\n // Handle MinOCRLabelStudio format\n const minData = data as MinOCRLabelStudio;\n return minData.map((item) => {\n // Collect all points from poly/bbox\n let ppocrAnnotations: PPOCRLabel = [];\n\n const numAnnotations = Math.max(\n item.poly?.length || 0,\n item.bbox?.length || 0,\n item.transcription?.length || 0,\n );\n\n for (let i = 0; i < numAnnotations; i++) {\n let points: number[][] | undefined;\n\n if (item.poly && item.poly.length > i && item.poly[i]) {\n const { points: polyPoints } = item.poly[i]!;\n points = polyPoints;\n } else if (item.bbox && item.bbox.length > i && item.bbox[i]) {\n const { x, y, width, height } = item.bbox[i]!;\n points = [\n [x, y],\n [x + width, y],\n [x + width, y + height],\n [x, y + height],\n ];\n }\n\n if (points) {\n ppocrAnnotations.push({\n transcription:\n item.transcription && item.transcription.length > i\n ? (item.transcription[i] ?? '')\n : '',\n points: points as Point[],\n dt_score: 1.0,\n });\n }\n }\n\n // Apply enhancements\n if (ppocrAnnotations.length > 0) {\n ppocrAnnotations = enhancePPOCRLabel(ppocrAnnotations, {\n sortVertical,\n sortHorizontal,\n normalizeShape,\n widthIncrement,\n heightIncrement,\n precision,\n });\n\n // Convert back to min format\n const newPoly = ppocrAnnotations.map((ann) => ({\n points: ann.points,\n }));\n\n // Return updated item with poly (omit bbox)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { bbox: _, ...itemWithoutBbox } = item;\n return {\n ...itemWithoutBbox,\n poly: newPoly,\n };\n }\n\n return item;\n }) as MinOCRLabelStudio;\n }\n};\n","/**\n * Geometry utility functions for shape normalization and bounding box operations\n */\n\nimport type { ShapeNormalizeOption } from '@/constants';\n\nexport type Point = [number, number];\n\n/**\n * Round a number to a specified precision\n * @param value - The number to round\n * @param precision - Number of decimal places (-1 means no rounding)\n * @returns Rounded number\n */\nexport function roundToPrecision(value: number, precision: number): number {\n if (precision < 0) {\n return value; // No rounding\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n\n/**\n * Round points array to a specified precision\n * @param points - Array of points to round\n * @param precision - Number of decimal places (-1 means no rounding)\n * @returns Rounded points\n */\nexport function roundPoints(points: Point[], precision: number): Point[] {\n if (precision < 0) {\n return points; // No rounding\n }\n return points.map(\n ([x, y]) =>\n [roundToPrecision(x, precision), roundToPrecision(y, precision)] as Point,\n );\n}\n\n/**\n * Calculate the center point of a polygon\n */\nexport function calculateCenter(points: Point[]): Point {\n const sum = points.reduce((acc, [x, y]) => [acc[0] + x, acc[1] + y], [\n 0, 0,\n ] as Point);\n return [sum[0] / points.length, sum[1] / points.length];\n}\n\n/**\n * Calculate the minimum bounding rectangle of a polygon\n */\nexport function getMinimumBoundingRect(points: Point[]): {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n width: number;\n height: number;\n} {\n const minX = Math.min(...points.map(([x]) => x));\n const maxX = Math.max(...points.map(([x]) => x));\n const minY = Math.min(...points.map(([, y]) => y));\n const maxY = Math.max(...points.map(([, y]) => y));\n\n return {\n minX,\n minY,\n maxX,\n maxY,\n width: maxX - minX,\n height: maxY - minY,\n };\n}\n\n/**\n * Convert diamond-like shapes to axis-aligned rectangles\n * @param points - Array of points representing the shape\n * @returns Normalized rectangle points\n */\nexport function normalizeShape(points: Point[]): Point[] {\n if (points.length < 3) {\n return points;\n }\n\n // Convert to axis-aligned bounding rectangle\n const { minX, minY, maxX, maxY } = getMinimumBoundingRect(points);\n\n return [\n [minX, minY],\n [maxX, minY],\n [maxX, maxY],\n [minX, maxY],\n ];\n}\n\n/**\n * Resize bounding box by a certain amount while keeping it centered\n * @param points - Array of points representing the bounding box\n * @param widthIncrement - Amount to increase width (can be negative to decrease)\n * @param heightIncrement - Amount to increase height (can be negative to decrease)\n * @returns Resized points\n */\nexport function resizeBoundingBox(\n points: Point[],\n widthIncrement: number,\n heightIncrement: number,\n): Point[] {\n if (points.length === 0) {\n return points;\n }\n\n // Calculate center\n const center = calculateCenter(points);\n\n // Calculate current bounding box\n const bbox = getMinimumBoundingRect(points);\n\n // Calculate new dimensions\n const newWidth = Math.max(1, bbox.width + widthIncrement);\n const newHeight = Math.max(1, bbox.height + heightIncrement);\n\n // Calculate scale factors\n const scaleX = newWidth / bbox.width;\n const scaleY = newHeight / bbox.height;\n\n // Transform each point: translate to origin, scale, translate back\n return points.map(([x, y]) => {\n const relX = x - center[0];\n const relY = y - center[1];\n\n return [center[0] + relX * scaleX, center[1] + relY * scaleY] as Point;\n });\n}\n\n/**\n * Apply geometry transformations to points\n * @param points - Original points\n * @param options - Transformation options\n * @returns Transformed points\n */\nexport function transformPoints(\n points: Point[],\n options: {\n normalizeShape?: ShapeNormalizeOption;\n widthIncrement?: number;\n heightIncrement?: number;\n },\n): Point[] {\n let result = points;\n\n // Apply shape normalization first\n if (options.normalizeShape && options.normalizeShape === 'rectangle') {\n result = normalizeShape(result);\n }\n\n // Then apply resizing\n if (\n options.widthIncrement !== undefined ||\n options.heightIncrement !== undefined\n ) {\n result = resizeBoundingBox(\n result,\n options.widthIncrement ?? 0,\n options.heightIncrement ?? 0,\n );\n }\n\n return result;\n}\n","export const OUTPUT_BASE_DIR = './output';\n\nexport const DEFAULT_LABEL_NAME = 'Text';\nexport const DEFAULT_LABEL_STUDIO_FULL_JSON = true;\nexport const DEFAULT_CREATE_FILE_PER_IMAGE = false;\nexport const DEFAULT_CREATE_FILE_LIST_FOR_SERVING = true;\nexport const DEFAULT_FILE_LIST_NAME = 'files.txt';\nexport const DEFAULT_BASE_SERVER_URL = 'http://localhost:8081';\n\nexport const DEFAULT_PPOCR_FILE_NAME = 'Label.txt';\n\n// Vertical sorting options\nexport const SORT_VERTICAL_NONE = 'none';\nexport const SORT_VERTICAL_TOP_BOTTOM = 'top-bottom';\nexport const SORT_VERTICAL_BOTTOM_TOP = 'bottom-top';\nexport const DEFAULT_SORT_VERTICAL = SORT_VERTICAL_NONE;\n\n// Horizontal sorting options\nexport const SORT_HORIZONTAL_NONE = 'none';\nexport const SORT_HORIZONTAL_LTR = 'ltr';\nexport const SORT_HORIZONTAL_RTL = 'rtl';\nexport const DEFAULT_SORT_HORIZONTAL = SORT_HORIZONTAL_NONE;\n\nexport type VerticalSortOrder =\n | typeof SORT_VERTICAL_NONE\n | typeof SORT_VERTICAL_TOP_BOTTOM\n | typeof SORT_VERTICAL_BOTTOM_TOP;\n\nexport type HorizontalSortOrder =\n | typeof SORT_HORIZONTAL_NONE\n | typeof SORT_HORIZONTAL_LTR\n | typeof SORT_HORIZONTAL_RTL;\n\n// Shape normalization options\nexport const SHAPE_NORMALIZE_NONE = 'none';\nexport const SHAPE_NORMALIZE_RECTANGLE = 'rectangle';\nexport const DEFAULT_SHAPE_NORMALIZE = SHAPE_NORMALIZE_NONE;\n\nexport type ShapeNormalizeOption =\n | typeof SHAPE_NORMALIZE_NONE\n | typeof SHAPE_NORMALIZE_RECTANGLE;\n\n// Bounding box resize options\nexport const DEFAULT_WIDTH_INCREMENT = 0;\nexport const DEFAULT_HEIGHT_INCREMENT = 0;\n\n// Number precision options\n// For Label Studio: keep full precision (no rounding) by default\nexport const DEFAULT_LABEL_STUDIO_PRECISION = -1; // -1 means no rounding\n// For PPOCR: round to integers\nexport const DEFAULT_PPOCR_PRECISION = 0;\n","import type { HorizontalSortOrder, VerticalSortOrder } from '@/constants';\nimport {\n SORT_HORIZONTAL_LTR,\n SORT_HORIZONTAL_NONE,\n SORT_HORIZONTAL_RTL,\n SORT_VERTICAL_NONE,\n SORT_VERTICAL_TOP_BOTTOM,\n} from '@/constants';\nimport type { PPOCRLabel } from '@/lib/schema';\n\n// Tolerance for grouping bounding boxes into columns/rows\n// Boxes within this pixel distance are considered in the same column/row\nconst GROUPING_TOLERANCE = 50;\n\n/**\n * Calculate the bounding box center point from polygon points\n */\nfunction getBoundingBoxCenter(points: number[][]): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (const [x, y] of points) {\n if (x !== undefined && y !== undefined) {\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n }\n\n return {\n x: (minX + maxX) / 2,\n y: (minY + maxY) / 2,\n width: maxX - minX,\n height: maxY - minY,\n };\n}\n\n/**\n * Sort PPOCRLabel array based on bounding box positions\n * Supports both traditional reading order (top-bottom, then left-right)\n * and SinoNom reading order (right-left columns, top-bottom within each column)\n * @param annotations - Array of PPOCR annotations to sort\n * @param verticalSort - Vertical sort order: 'none', 'top-bottom', 'bottom-top'\n * @param horizontalSort - Horizontal sort order: 'none', 'ltr', 'rtl'\n * @returns Sorted array (or original array if both sorts are 'none')\n */\nexport function sortBoundingBoxes(\n annotations: PPOCRLabel,\n verticalSort: VerticalSortOrder,\n horizontalSort: HorizontalSortOrder,\n): PPOCRLabel {\n if (\n verticalSort === SORT_VERTICAL_NONE &&\n horizontalSort === SORT_HORIZONTAL_NONE\n ) {\n return annotations;\n }\n\n // Create a copy to avoid mutating the original array\n const sorted = [...annotations];\n\n // Detect if this is vertical text (SinoNom style) or horizontal text (Arabic/Hebrew style)\n // by checking if most boxes are taller than they are wide\n const isVerticalText =\n sorted.length > 0 &&\n (() => {\n const verticalCount = sorted.filter((ann) => {\n const center = getBoundingBoxCenter(ann.points);\n return center.height > center.width * 1.5; // At least 1.5x taller than wide\n }).length;\n return verticalCount > sorted.length / 2; // More than half are vertical\n })();\n\n // For RTL with vertical sorting and vertical text (SinoNom):\n // Group into columns first, then sort within each column\n if (\n horizontalSort === SORT_HORIZONTAL_RTL &&\n verticalSort !== SORT_VERTICAL_NONE &&\n isVerticalText\n ) {\n // Calculate centers for all annotations\n const annotationsWithCenters = sorted.map((ann) => ({\n annotation: ann,\n center: getBoundingBoxCenter(ann.points),\n }));\n\n // Group annotations into columns based on x-position\n const columns: (typeof annotationsWithCenters)[] = [];\n\n for (const item of annotationsWithCenters) {\n let addedToColumn = false;\n\n for (const column of columns) {\n // Check if this annotation belongs to an existing column\n const avgX =\n column.reduce((sum, c) => sum + c.center.x, 0) / column.length;\n if (Math.abs(item.center.x - avgX) < GROUPING_TOLERANCE) {\n column.push(item);\n addedToColumn = true;\n break;\n }\n }\n\n if (!addedToColumn) {\n columns.push([item]);\n }\n }\n\n // Sort columns right-to-left\n columns.sort((colA, colB) => {\n const avgXA = colA.reduce((sum, c) => sum + c.center.x, 0) / colA.length;\n const avgXB = colB.reduce((sum, c) => sum + c.center.x, 0) / colB.length;\n return avgXB - avgXA; // Right to left\n });\n\n // Sort within each column top-to-bottom or bottom-to-top\n for (const column of columns) {\n column.sort((a, b) => {\n return verticalSort === SORT_VERTICAL_TOP_BOTTOM\n ? a.center.y - b.center.y\n : b.center.y - a.center.y;\n });\n }\n\n // Flatten back to a single array\n return columns.flat().map((item) => item.annotation);\n }\n\n // For all other cases, use simple sort with priority\n sorted.sort((a, b) => {\n const centerA = getBoundingBoxCenter(a.points);\n const centerB = getBoundingBoxCenter(b.points);\n\n // Apply vertical sorting first (if specified)\n if (verticalSort !== SORT_VERTICAL_NONE) {\n const yDiff =\n verticalSort === SORT_VERTICAL_TOP_BOTTOM\n ? centerA.y - centerB.y\n : centerB.y - centerA.y;\n\n // If there's a significant difference in y-position, return that\n if (Math.abs(yDiff) > GROUPING_TOLERANCE) {\n return yDiff;\n }\n }\n\n // Apply horizontal sorting (if specified and y-positions are similar or not sorting vertically)\n if (horizontalSort !== SORT_HORIZONTAL_NONE) {\n return horizontalSort === SORT_HORIZONTAL_LTR\n ? centerA.x - centerB.x\n : centerB.x - centerA.x;\n }\n\n return 0;\n });\n\n return sorted;\n}\n","import type {\n HorizontalSortOrder,\n ShapeNormalizeOption,\n VerticalSortOrder,\n} from '@/constants';\nimport { type Point, roundPoints, transformPoints } from '@/lib/geometry';\nimport type { PPOCRLabel } from '@/lib/schema';\nimport { sortBoundingBoxes } from '@/lib/sort';\n\n/**\n * Common enhancement options shared across formats\n */\nexport interface EnhancementOptions {\n sortVertical?: VerticalSortOrder;\n sortHorizontal?: HorizontalSortOrder;\n normalizeShape?: ShapeNormalizeOption;\n widthIncrement?: number;\n heightIncrement?: number;\n precision?: number;\n}\n\n/**\n * Apply all enhancement transformations to PPOCRLabel data\n */\nexport function enhancePPOCRLabel(\n data: PPOCRLabel,\n options: EnhancementOptions,\n): PPOCRLabel {\n const {\n sortVertical,\n sortHorizontal,\n normalizeShape,\n widthIncrement = 0,\n heightIncrement = 0,\n precision = 0,\n } = options;\n\n // Apply sorting first\n let enhanced = data;\n if (sortVertical && sortHorizontal) {\n enhanced = sortBoundingBoxes(enhanced, sortVertical, sortHorizontal);\n }\n\n // Apply shape transformations\n if (normalizeShape || widthIncrement !== 0 || heightIncrement !== 0) {\n enhanced = enhanced.map((annotation) => {\n let points = transformPoints(annotation.points as Point[], {\n normalizeShape,\n widthIncrement,\n heightIncrement,\n });\n\n // Apply precision rounding\n points = roundPoints(points, precision);\n\n return {\n ...annotation,\n points,\n };\n });\n }\n\n return enhanced;\n}\n\n/**\n * Type guard to check if enhancement options are provided\n */\nexport function hasEnhancementOptions(options: EnhancementOptions): boolean {\n return !!(\n options.sortVertical ||\n options.sortHorizontal ||\n options.normalizeShape ||\n options.widthIncrement !== 0 ||\n options.heightIncrement !== 0\n );\n}\n","import { randomUUID } from 'node:crypto';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport sizeOf from 'image-size';\nimport {\n DEFAULT_LABEL_NAME,\n DEFAULT_LABEL_STUDIO_PRECISION,\n type ShapeNormalizeOption,\n} from '@/constants';\nimport { type Point, roundToPrecision, transformPoints } from '@/lib/geometry';\nimport {\n type FullOCRLabelStudio,\n type MinOCRLabelStudio,\n type PPOCRLabel,\n} from '@/lib/schema';\n\nexport type ToLabelStudioOptions = {\n imagePath: string;\n baseServerUrl: string;\n inputDir?: string;\n toFullJson?: boolean;\n taskId?: number;\n labelName?: string;\n normalizeShape?: ShapeNormalizeOption;\n widthIncrement?: number;\n heightIncrement?: number;\n precision?: number;\n};\n\nexport const ppocrToLabelStudio = async (\n data: PPOCRLabel,\n options: ToLabelStudioOptions,\n): Promise<FullOCRLabelStudio | MinOCRLabelStudio> => {\n const {\n imagePath,\n baseServerUrl,\n inputDir,\n toFullJson = true,\n taskId = 1,\n labelName = DEFAULT_LABEL_NAME,\n normalizeShape,\n widthIncrement = 0,\n heightIncrement = 0,\n precision = DEFAULT_LABEL_STUDIO_PRECISION,\n } = options || {};\n\n if (toFullJson) {\n return ppocrToFullLabelStudio(\n data,\n imagePath,\n baseServerUrl,\n inputDir,\n taskId,\n labelName,\n normalizeShape,\n widthIncrement,\n heightIncrement,\n precision,\n );\n } else {\n return ppocrToMinLabelStudio(\n data,\n imagePath,\n baseServerUrl,\n inputDir,\n labelName,\n normalizeShape,\n widthIncrement,\n heightIncrement,\n precision,\n );\n }\n};\n\nexport const ppocrToFullLabelStudio = (\n data: PPOCRLabel,\n imagePath: string,\n baseServerUrl: string,\n inputDir?: string,\n taskId: number = 1,\n labelName: string = DEFAULT_LABEL_NAME,\n normalizeShape?: ShapeNormalizeOption,\n widthIncrement: number = 0,\n heightIncrement: number = 0,\n precision: number = DEFAULT_LABEL_STUDIO_PRECISION,\n): FullOCRLabelStudio => {\n const newBaseServerUrl =\n baseServerUrl.replace(/\\/+$/, '') + (baseServerUrl === '' ? '' : '/');\n\n const now = new Date().toISOString();\n\n // Get actual image dimensions from the image file\n let original_width = 1920;\n let original_height = 1080;\n\n // Resolve absolute path to image file\n const resolvedImagePath = inputDir ? join(inputDir, imagePath) : imagePath;\n\n if (!existsSync(resolvedImagePath)) {\n throw new Error(`Image file not found: ${resolvedImagePath}`);\n }\n\n const buffer = readFileSync(resolvedImagePath);\n const dimensions = sizeOf(buffer);\n if (!dimensions.width || !dimensions.height) {\n throw new Error(\n `Failed to read image dimensions from: ${resolvedImagePath}`,\n );\n }\n original_width = dimensions.width;\n original_height = dimensions.height;\n\n // Extract filename from imagePath for file_upload (just the filename)\n const fileName = imagePath.split('/').pop() || imagePath;\n\n // Group all PPOCRLabel items into a single task with one annotation\n const result: FullOCRLabelStudio = [\n {\n id: taskId,\n annotations: [\n {\n id: taskId,\n completed_by: 1,\n result: data\n .map((item) => {\n let { points } = item;\n\n // Apply geometry transformations\n points = transformPoints(points as Point[], {\n normalizeShape,\n widthIncrement,\n heightIncrement,\n });\n\n // Generate a single ID for all three related annotations\n const annotationId = randomUUID().slice(0, 10);\n const polygonPoints = points.map(([x, y]) => [\n roundToPrecision(((x ?? 0) / original_width) * 100, precision),\n roundToPrecision(((y ?? 0) / original_height) * 100, precision),\n ]);\n\n // Create result items: polygon, labels, and textarea\n return [\n // 1. Polygon geometry only\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n },\n id: annotationId,\n from_name: 'poly',\n to_name: 'image',\n type: 'polygon',\n origin: 'manual',\n },\n // 2. Labels with polygon geometry\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n labels: [labelName],\n },\n id: annotationId,\n from_name: 'label',\n to_name: 'image',\n type: 'labels',\n origin: 'manual',\n },\n // 3. Textarea with polygon geometry and text\n {\n original_width,\n original_height,\n image_rotation: 0,\n value: {\n points: polygonPoints,\n closed: true,\n text: [item.transcription],\n },\n id: annotationId,\n from_name: 'transcription',\n to_name: 'image',\n type: 'textarea',\n origin: 'manual',\n },\n ];\n })\n .flat(),\n was_cancelled: false,\n ground_truth: false,\n created_at: now,\n updated_at: now,\n draft_created_at: now,\n lead_time: 0,\n prediction: {},\n result_count: data.length * 3,\n unique_id: randomUUID(),\n import_id: null,\n last_action: null,\n bulk_created: false,\n task: taskId,\n project: 1,\n updated_by: 1,\n parent_prediction: null,\n parent_annotation: null,\n last_created_by: null,\n },\n ],\n file_upload: fileName,\n drafts: [],\n predictions: [],\n data: { ocr: `${newBaseServerUrl}${imagePath}` },\n meta: {},\n created_at: now,\n updated_at: now,\n allow_skip: false,\n inner_id: taskId,\n total_annotations: 1,\n cancelled_annotations: 0,\n total_predictions: 0,\n comment_count: 0,\n unresolved_comment_count: 0,\n last_comment_updated_at: null,\n project: 1,\n updated_by: 1,\n comment_authors: [],\n },\n ];\n\n return result;\n};\n\nexport const ppocrToMinLabelStudio = (\n data: PPOCRLabel,\n imagePath: string,\n baseServerUrl: string,\n inputDir?: string,\n labelName: string = 'text',\n normalizeShape?: ShapeNormalizeOption,\n widthIncrement: number = 0,\n heightIncrement: number = 0,\n precision: number = DEFAULT_LABEL_STUDIO_PRECISION,\n): MinOCRLabelStudio => {\n const newBaseServerUrl =\n baseServerUrl.replace(/\\/+$/, '') + (baseServerUrl === '' ? '' : '/');\n\n const now = new Date().toISOString();\n\n // Get actual image dimensions from the image file\n let original_width = 1920;\n let original_height = 1080;\n\n // Resolve absolute path to image file\n const resolvedImagePath = inputDir ? join(inputDir, imagePath) : imagePath;\n\n if (!existsSync(resolvedImagePath)) {\n throw new Error(`Image file not found: ${resolvedImagePath}`);\n }\n\n const buffer = readFileSync(resolvedImagePath);\n const dimensions = sizeOf(buffer);\n if (!dimensions.width || !dimensions.height) {\n throw new Error(\n `Failed to read image dimensions from: ${resolvedImagePath}`,\n );\n }\n original_width = dimensions.width;\n original_height = dimensions.height;\n\n return data.map((item, index) => {\n let { points } = item;\n\n // Apply geometry transformations\n points = transformPoints(points as Point[], {\n normalizeShape,\n widthIncrement,\n heightIncrement,\n });\n\n // Round coordinates based on precision first\n const roundedPoints = points.map(\n ([x, y]) =>\n [\n roundToPrecision(x ?? 0, precision),\n roundToPrecision(y ?? 0, precision),\n ] as [number, number],\n );\n\n // Calculate bbox from rounded points\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n for (const point of roundedPoints) {\n const [x, y] = point;\n if (x !== undefined && y !== undefined) {\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n }\n\n const width = maxX - minX;\n const height = maxY - minY;\n\n return {\n ocr: encodeURI(`${newBaseServerUrl}${imagePath}`),\n id: index + 1,\n bbox: [\n {\n x: minX,\n y: minY,\n width: width,\n height: height,\n rotation: 0,\n original_width,\n original_height,\n },\n ],\n label: [\n {\n points: roundedPoints,\n closed: true,\n labels: [labelName],\n original_width,\n original_height,\n },\n ],\n transcription: [item.transcription],\n poly: [\n {\n points: roundedPoints,\n closed: true,\n original_width,\n original_height,\n },\n ],\n annotator: 1,\n annotation_id: index + 1,\n created_at: now,\n updated_at: now,\n lead_time: 0,\n };\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAc;AAEP,IAAM,2BAA2B,WAAAA,QAAE;AAAA,EACxC,WAAAA,QAAE,OAAO;AAAA,IACP,IAAI,WAAAA,QAAE,OAAO;AAAA,IACb,aAAa,WAAAA,QAAE;AAAA,MACb,WAAAA,QAAE,OAAO;AAAA,QACP,IAAI,WAAAA,QAAE,OAAO;AAAA,QACb,cAAc,WAAAA,QAAE,OAAO;AAAA,QACvB,QAAQ,WAAAA,QAAE;AAAA,UACR,WAAAA,QAAE,MAAM;AAAA;AAAA,YAEN,WAAAA,QAAE,OAAO;AAAA,cACP,gBAAgB,WAAAA,QAAE,OAAO;AAAA,cACzB,iBAAiB,WAAAA,QA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;AAAA,UACR,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,WAAW;AAAA,MACX,eAAe,QAAQ;AAAA,MACvB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,WAAW;AAAA,IACb;AAAA,EACF,CAAC;AACH;","names":["z","normalizeShape","normalizeShape","polygon","area","normalizeShape","sizeOf"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,7 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
15
15
|
width: z.ZodNumber;
|
|
16
16
|
height: z.ZodNumber;
|
|
17
17
|
rotation: z.ZodNumber;
|
|
18
|
+
text: z.ZodArray<z.ZodString>;
|
|
18
19
|
}, z.core.$strip>;
|
|
19
20
|
id: z.ZodString;
|
|
20
21
|
from_name: z.ZodString;
|
|
@@ -48,7 +49,6 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
48
49
|
width: z.ZodNumber;
|
|
49
50
|
height: z.ZodNumber;
|
|
50
51
|
rotation: z.ZodNumber;
|
|
51
|
-
text: z.ZodArray<z.ZodString>;
|
|
52
52
|
}, z.core.$strip>;
|
|
53
53
|
id: z.ZodString;
|
|
54
54
|
from_name: z.ZodString;
|
|
@@ -62,6 +62,7 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
62
62
|
value: z.ZodObject<{
|
|
63
63
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
64
64
|
closed: z.ZodBoolean;
|
|
65
|
+
text: z.ZodArray<z.ZodString>;
|
|
65
66
|
}, z.core.$strip>;
|
|
66
67
|
id: z.ZodString;
|
|
67
68
|
from_name: z.ZodString;
|
|
@@ -89,7 +90,6 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
89
90
|
value: z.ZodObject<{
|
|
90
91
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
91
92
|
closed: z.ZodBoolean;
|
|
92
|
-
text: z.ZodArray<z.ZodString>;
|
|
93
93
|
}, z.core.$strip>;
|
|
94
94
|
id: z.ZodString;
|
|
95
95
|
from_name: z.ZodString;
|
|
@@ -132,6 +132,7 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
132
132
|
width: z.ZodNumber;
|
|
133
133
|
height: z.ZodNumber;
|
|
134
134
|
rotation: z.ZodNumber;
|
|
135
|
+
text: z.ZodArray<z.ZodString>;
|
|
135
136
|
}, z.core.$strip>;
|
|
136
137
|
id: z.ZodString;
|
|
137
138
|
from_name: z.ZodString;
|
|
@@ -165,7 +166,6 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
165
166
|
width: z.ZodNumber;
|
|
166
167
|
height: z.ZodNumber;
|
|
167
168
|
rotation: z.ZodNumber;
|
|
168
|
-
text: z.ZodArray<z.ZodString>;
|
|
169
169
|
}, z.core.$strip>;
|
|
170
170
|
id: z.ZodString;
|
|
171
171
|
from_name: z.ZodString;
|
|
@@ -179,6 +179,7 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
179
179
|
value: z.ZodObject<{
|
|
180
180
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
181
181
|
closed: z.ZodBoolean;
|
|
182
|
+
text: z.ZodArray<z.ZodString>;
|
|
182
183
|
}, z.core.$strip>;
|
|
183
184
|
id: z.ZodString;
|
|
184
185
|
from_name: z.ZodString;
|
|
@@ -206,7 +207,6 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
206
207
|
value: z.ZodObject<{
|
|
207
208
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
208
209
|
closed: z.ZodBoolean;
|
|
209
|
-
text: z.ZodArray<z.ZodString>;
|
|
210
210
|
}, z.core.$strip>;
|
|
211
211
|
id: z.ZodString;
|
|
212
212
|
from_name: z.ZodString;
|
|
@@ -244,7 +244,7 @@ declare const FullOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
244
244
|
declare const MinOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
245
245
|
ocr: z.ZodString;
|
|
246
246
|
id: z.ZodNumber;
|
|
247
|
-
bbox: z.ZodArray<z.ZodObject<{
|
|
247
|
+
bbox: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
248
248
|
x: z.ZodNumber;
|
|
249
249
|
y: z.ZodNumber;
|
|
250
250
|
width: z.ZodNumber;
|
|
@@ -252,8 +252,8 @@ declare const MinOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
252
252
|
rotation: z.ZodNumber;
|
|
253
253
|
original_width: z.ZodNumber;
|
|
254
254
|
original_height: z.ZodNumber;
|
|
255
|
-
}, z.core.$strip
|
|
256
|
-
label: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
255
|
+
}, z.core.$strip>>>>;
|
|
256
|
+
label: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
257
257
|
x: z.ZodNumber;
|
|
258
258
|
y: z.ZodNumber;
|
|
259
259
|
width: z.ZodNumber;
|
|
@@ -268,14 +268,14 @@ declare const MinOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
268
268
|
labels: z.ZodArray<z.ZodString>;
|
|
269
269
|
original_width: z.ZodNumber;
|
|
270
270
|
original_height: z.ZodNumber;
|
|
271
|
-
}, z.core.$strip>]
|
|
272
|
-
transcription: z.ZodArray<z.ZodString
|
|
273
|
-
poly: z.ZodArray<z.ZodObject<{
|
|
271
|
+
}, z.core.$strip>]>>>>;
|
|
272
|
+
transcription: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>, z.ZodTransform<string[], string | string[] | undefined>>;
|
|
273
|
+
poly: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
274
274
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
275
275
|
closed: z.ZodBoolean;
|
|
276
276
|
original_width: z.ZodNumber;
|
|
277
277
|
original_height: z.ZodNumber;
|
|
278
|
-
}, z.core.$strip
|
|
278
|
+
}, z.core.$strip>>>>;
|
|
279
279
|
annotator: z.ZodNumber;
|
|
280
280
|
annotation_id: z.ZodNumber;
|
|
281
281
|
created_at: z.ZodString;
|
|
@@ -285,14 +285,58 @@ declare const MinOCRLabelStudioSchema: z.ZodArray<z.ZodObject<{
|
|
|
285
285
|
declare const PPOCRLabelSchema: z.ZodArray<z.ZodObject<{
|
|
286
286
|
transcription: z.ZodString;
|
|
287
287
|
points: z.ZodArray<z.ZodArray<z.ZodNumber>>;
|
|
288
|
-
dt_score: z.ZodNumber
|
|
288
|
+
dt_score: z.ZodOptional<z.ZodNumber>;
|
|
289
|
+
difficult: z.ZodOptional<z.ZodBoolean>;
|
|
289
290
|
}, z.core.$strip>>;
|
|
290
291
|
type FullOCRLabelStudio = z.infer<typeof FullOCRLabelStudioSchema>;
|
|
291
292
|
type MinOCRLabelStudio = z.infer<typeof MinOCRLabelStudioSchema>;
|
|
292
293
|
type PPOCRLabel = z.infer<typeof PPOCRLabelSchema>;
|
|
293
294
|
|
|
294
|
-
declare const
|
|
295
|
-
declare const
|
|
295
|
+
declare const SORT_VERTICAL_NONE = "none";
|
|
296
|
+
declare const SORT_VERTICAL_TOP_BOTTOM = "top-bottom";
|
|
297
|
+
declare const SORT_VERTICAL_BOTTOM_TOP = "bottom-top";
|
|
298
|
+
declare const SORT_HORIZONTAL_NONE = "none";
|
|
299
|
+
declare const SORT_HORIZONTAL_LTR = "ltr";
|
|
300
|
+
declare const SORT_HORIZONTAL_RTL = "rtl";
|
|
301
|
+
type VerticalSortOrder = typeof SORT_VERTICAL_NONE | typeof SORT_VERTICAL_TOP_BOTTOM | typeof SORT_VERTICAL_BOTTOM_TOP;
|
|
302
|
+
type HorizontalSortOrder = typeof SORT_HORIZONTAL_NONE | typeof SORT_HORIZONTAL_LTR | typeof SORT_HORIZONTAL_RTL;
|
|
303
|
+
declare const SHAPE_NORMALIZE_NONE = "none";
|
|
304
|
+
declare const SHAPE_NORMALIZE_RECTANGLE = "rectangle";
|
|
305
|
+
type ShapeNormalizeOption = typeof SHAPE_NORMALIZE_NONE | typeof SHAPE_NORMALIZE_RECTANGLE;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Common enhancement options shared across formats
|
|
309
|
+
*/
|
|
310
|
+
interface EnhancementOptions {
|
|
311
|
+
sortVertical?: VerticalSortOrder;
|
|
312
|
+
sortHorizontal?: HorizontalSortOrder;
|
|
313
|
+
normalizeShape?: ShapeNormalizeOption;
|
|
314
|
+
widthIncrement?: number;
|
|
315
|
+
heightIncrement?: number;
|
|
316
|
+
precision?: number;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Apply all enhancement transformations to PPOCRLabel data
|
|
320
|
+
*/
|
|
321
|
+
declare function enhancePPOCRLabel(data: PPOCRLabel, options: EnhancementOptions): PPOCRLabel;
|
|
322
|
+
/**
|
|
323
|
+
* Type guard to check if enhancement options are provided
|
|
324
|
+
*/
|
|
325
|
+
declare function hasEnhancementOptions(options: EnhancementOptions): boolean;
|
|
326
|
+
|
|
327
|
+
interface ConversionOptions {
|
|
328
|
+
baseImageDir?: string;
|
|
329
|
+
normalizeShape?: ShapeNormalizeOption;
|
|
330
|
+
widthIncrement?: number;
|
|
331
|
+
heightIncrement?: number;
|
|
332
|
+
precision?: number;
|
|
333
|
+
}
|
|
334
|
+
declare const labelStudioToPPOCR: (data: FullOCRLabelStudio, options?: ConversionOptions) => Promise<Map<string, PPOCRLabel>>;
|
|
335
|
+
declare const minLabelStudioToPPOCR: (data: MinOCRLabelStudio, options?: ConversionOptions) => Promise<Map<string, PPOCRLabel>>;
|
|
336
|
+
/**
|
|
337
|
+
* Enhance Label Studio data (both Full and Min formats) with sorting, normalization, and resizing
|
|
338
|
+
*/
|
|
339
|
+
declare const enhanceLabelStudioData: (data: FullOCRLabelStudio | MinOCRLabelStudio, isFull: boolean, options: EnhancementOptions) => Promise<FullOCRLabelStudio | MinOCRLabelStudio>;
|
|
296
340
|
|
|
297
341
|
type ToLabelStudioOptions = {
|
|
298
342
|
imagePath: string;
|
|
@@ -301,9 +345,84 @@ type ToLabelStudioOptions = {
|
|
|
301
345
|
toFullJson?: boolean;
|
|
302
346
|
taskId?: number;
|
|
303
347
|
labelName?: string;
|
|
348
|
+
normalizeShape?: ShapeNormalizeOption;
|
|
349
|
+
widthIncrement?: number;
|
|
350
|
+
heightIncrement?: number;
|
|
351
|
+
precision?: number;
|
|
304
352
|
};
|
|
305
353
|
declare const ppocrToLabelStudio: (data: PPOCRLabel, options: ToLabelStudioOptions) => Promise<FullOCRLabelStudio | MinOCRLabelStudio>;
|
|
306
|
-
declare const ppocrToFullLabelStudio: (data: PPOCRLabel, imagePath: string, baseServerUrl: string, inputDir?: string, taskId?: number, labelName?: string) => FullOCRLabelStudio;
|
|
307
|
-
declare const ppocrToMinLabelStudio: (data: PPOCRLabel, imagePath: string, baseServerUrl: string, inputDir?: string, labelName?: string) => MinOCRLabelStudio;
|
|
354
|
+
declare const ppocrToFullLabelStudio: (data: PPOCRLabel, imagePath: string, baseServerUrl: string, inputDir?: string, taskId?: number, labelName?: string, normalizeShape?: ShapeNormalizeOption, widthIncrement?: number, heightIncrement?: number, precision?: number) => FullOCRLabelStudio;
|
|
355
|
+
declare const ppocrToMinLabelStudio: (data: PPOCRLabel, imagePath: string, baseServerUrl: string, inputDir?: string, labelName?: string, normalizeShape?: ShapeNormalizeOption, widthIncrement?: number, heightIncrement?: number, precision?: number) => MinOCRLabelStudio;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Geometry utility functions for shape normalization and bounding box operations
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
type Point = [number, number];
|
|
362
|
+
/**
|
|
363
|
+
* Round a number to a specified precision
|
|
364
|
+
* @param value - The number to round
|
|
365
|
+
* @param precision - Number of decimal places (-1 means no rounding)
|
|
366
|
+
* @returns Rounded number
|
|
367
|
+
*/
|
|
368
|
+
declare function roundToPrecision(value: number, precision: number): number;
|
|
369
|
+
/**
|
|
370
|
+
* Round points array to a specified precision
|
|
371
|
+
* @param points - Array of points to round
|
|
372
|
+
* @param precision - Number of decimal places (-1 means no rounding)
|
|
373
|
+
* @returns Rounded points
|
|
374
|
+
*/
|
|
375
|
+
declare function roundPoints(points: Point[], precision: number): Point[];
|
|
376
|
+
/**
|
|
377
|
+
* Calculate the center point of a polygon
|
|
378
|
+
*/
|
|
379
|
+
declare function calculateCenter(points: Point[]): Point;
|
|
380
|
+
/**
|
|
381
|
+
* Calculate the minimum bounding rectangle of a polygon
|
|
382
|
+
*/
|
|
383
|
+
declare function getMinimumBoundingRect(points: Point[]): {
|
|
384
|
+
minX: number;
|
|
385
|
+
minY: number;
|
|
386
|
+
maxX: number;
|
|
387
|
+
maxY: number;
|
|
388
|
+
width: number;
|
|
389
|
+
height: number;
|
|
390
|
+
};
|
|
391
|
+
/**
|
|
392
|
+
* Convert diamond-like shapes to axis-aligned rectangles
|
|
393
|
+
* @param points - Array of points representing the shape
|
|
394
|
+
* @returns Normalized rectangle points
|
|
395
|
+
*/
|
|
396
|
+
declare function normalizeShape(points: Point[]): Point[];
|
|
397
|
+
/**
|
|
398
|
+
* Resize bounding box by a certain amount while keeping it centered
|
|
399
|
+
* @param points - Array of points representing the bounding box
|
|
400
|
+
* @param widthIncrement - Amount to increase width (can be negative to decrease)
|
|
401
|
+
* @param heightIncrement - Amount to increase height (can be negative to decrease)
|
|
402
|
+
* @returns Resized points
|
|
403
|
+
*/
|
|
404
|
+
declare function resizeBoundingBox(points: Point[], widthIncrement: number, heightIncrement: number): Point[];
|
|
405
|
+
/**
|
|
406
|
+
* Apply geometry transformations to points
|
|
407
|
+
* @param points - Original points
|
|
408
|
+
* @param options - Transformation options
|
|
409
|
+
* @returns Transformed points
|
|
410
|
+
*/
|
|
411
|
+
declare function transformPoints(points: Point[], options: {
|
|
412
|
+
normalizeShape?: ShapeNormalizeOption;
|
|
413
|
+
widthIncrement?: number;
|
|
414
|
+
heightIncrement?: number;
|
|
415
|
+
}): Point[];
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Sort PPOCRLabel array based on bounding box positions
|
|
419
|
+
* Supports both traditional reading order (top-bottom, then left-right)
|
|
420
|
+
* and SinoNom reading order (right-left columns, top-bottom within each column)
|
|
421
|
+
* @param annotations - Array of PPOCR annotations to sort
|
|
422
|
+
* @param verticalSort - Vertical sort order: 'none', 'top-bottom', 'bottom-top'
|
|
423
|
+
* @param horizontalSort - Horizontal sort order: 'none', 'ltr', 'rtl'
|
|
424
|
+
* @returns Sorted array (or original array if both sorts are 'none')
|
|
425
|
+
*/
|
|
426
|
+
declare function sortBoundingBoxes(annotations: PPOCRLabel, verticalSort: VerticalSortOrder, horizontalSort: HorizontalSortOrder): PPOCRLabel;
|
|
308
427
|
|
|
309
|
-
export { type ToLabelStudioOptions, labelStudioToPPOCR, minLabelStudioToPPOCR, ppocrToFullLabelStudio, ppocrToLabelStudio, ppocrToMinLabelStudio };
|
|
428
|
+
export { type ConversionOptions, type EnhancementOptions, type FullOCRLabelStudio, FullOCRLabelStudioSchema, type MinOCRLabelStudio, MinOCRLabelStudioSchema, type PPOCRLabel, PPOCRLabelSchema, type Point, type ToLabelStudioOptions, calculateCenter, enhanceLabelStudioData, enhancePPOCRLabel, getMinimumBoundingRect, hasEnhancementOptions, labelStudioToPPOCR, minLabelStudioToPPOCR, normalizeShape, ppocrToFullLabelStudio, ppocrToLabelStudio, ppocrToMinLabelStudio, resizeBoundingBox, roundPoints, roundToPrecision, sortBoundingBoxes, transformPoints };
|