edgefirst_client/coco/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright © 2025 Au-Zone Technologies. All Rights Reserved.
3
4//! # COCO Dataset Format Support
5//!
6//! This module provides comprehensive support for the COCO (Common Objects in
7//! Context) dataset format, enabling bidirectional conversion between COCO and
8//! EdgeFirst formats.
9//!
10//! ## Supported Workflows
11//!
12//! 1. **COCO → EdgeFirst Arrow**: Convert COCO JSON/ZIP to Arrow-based
13//! EdgeFirst format
14//! 2. **EdgeFirst Arrow → COCO**: Convert Arrow format back to COCO JSON
15//! 3. **COCO → Studio**: Import COCO directly into EdgeFirst Studio via API
16//! 4. **Studio → COCO**: Export Studio dataset to COCO format
17//!
18//! ## Scope
19//!
20//! Phase 1 supports:
21//! - Bounding boxes (box2d)
22//! - Polygon segmentation (mask)
23//! - RLE segmentation (decoded to polygons)
24//!
25//! Not yet supported: keypoints, captions, panoptic segmentation.
26//!
27//! ## Example
28//!
29//! ```rust,no_run
30//! use edgefirst_client::coco::{CocoReader, CocoToArrowOptions, coco_to_arrow};
31//!
32//! # async fn example() -> Result<(), edgefirst_client::Error> {
33//! // Read COCO annotations
34//! let reader = CocoReader::new();
35//! let dataset = reader.read_json("annotations/instances_val2017.json")?;
36//! println!(
37//! "Found {} images and {} annotations",
38//! dataset.images.len(),
39//! dataset.annotations.len()
40//! );
41//!
42//! // Convert to EdgeFirst Arrow format
43//! let options = CocoToArrowOptions::default();
44//! let count = coco_to_arrow(
45//! "annotations/instances_val2017.json",
46//! "dataset.arrow",
47//! &options,
48//! None,
49//! )
50//! .await?;
51//! println!("Converted {} samples", count);
52//! # Ok(())
53//! # }
54//! ```
55
56mod convert;
57mod reader;
58mod types;
59pub mod verify;
60mod writer;
61
62#[cfg(feature = "polars")]
63mod arrow;
64
65#[cfg(feature = "polars")]
66pub mod studio;
67
68// Re-export types
69pub use types::{
70 CocoAnnotation, CocoCategory, CocoCompressedRle, CocoDataset, CocoImage, CocoIndex, CocoInfo,
71 CocoLicense, CocoRle, CocoSegmentation,
72};
73
74// Re-export readers/writers
75pub use reader::{
76 CocoReadOptions, CocoReader, infer_group_from_filename, infer_group_from_folder,
77 read_coco_directory,
78};
79pub use writer::{CocoWriteOptions, CocoWriter};
80
81// Re-export conversion functions
82pub use convert::{
83 box2d_to_coco_bbox, calculate_coco_area, coco_bbox_to_box2d, coco_polygon_to_mask,
84 coco_rle_to_mask, coco_segmentation_to_mask, decode_compressed_rle, decode_rle,
85 mask_to_coco_polygon, mask_to_contours, validate_coco_bbox,
86};
87
88// Re-export Arrow conversions (feature-gated)
89#[cfg(feature = "polars")]
90pub use arrow::{ArrowToCocoOptions, CocoToArrowOptions, arrow_to_coco, coco_to_arrow};
91
92// Re-export Studio integration (feature-gated)
93#[cfg(feature = "polars")]
94pub use studio::{
95 CocoExportOptions, CocoImportOptions, CocoImportResult, CocoUpdateOptions, CocoUpdateResult,
96 CocoVerifyOptions, export_studio_to_coco, import_coco_to_studio, update_coco_annotations,
97 verify_coco_import,
98};
99
100// Re-export verification types
101pub use verify::{
102 BboxValidationResult, CategoryValidationResult, MaskValidationResult, VerificationResult,
103};
104
105#[cfg(test)]
106mod tests;