Overview
Design and implement an extension/plugin system to enable:
- AI models (auto-annotation, segmentation, classification)
- Custom drawing tools
- Batch processors and validators
- Custom export formats
Design Goals
- Type Safety: Full TypeScript support with strong typing
- Framework Agnostic: Core extension API independent of React/OSD
- Easy Integration: Simple registration and lifecycle management
- Performance: Minimal overhead, async operation support
- Extensibility: Support for future capabilities
Proposed Extension API
interface AnnotaExtension {
id: string;
name: string;
version: string;
// Lifecycle hooks
onInit?(annotator: Annotator): void | Promise<void>;
onDestroy?(): void | Promise<void>;
// Tool extensions
tools?: Tool[];
// AI capabilities
detect?(image: ImageData, options: any): Promise<Annotation[]>;
classify?(annotation: Annotation): Promise<Classification>;
segment?(point: Point, image: ImageData): Promise<Polygon>;
}
Example Extension
const openCVExtension: AnnotaExtension = {
id: 'opencv-edge-detector',
name: 'OpenCV Edge Detector',
version: '1.0.0',
async onInit(annotator) {
await initOpenCV();
console.log('OpenCV extension loaded');
},
async segment(point, imageData) {
const result = await detectEdge(imageData, point, {
threshold: 128,
thresholdType: 'otsu',
});
return result.polygon;
},
};
// Register extension
annotator.registerExtension(openCVExtension);
Use Cases
- OpenCV Integration: Edge detection, thresholding, morphological operations
- SAM Integration: Segment Anything Model for one-click segmentation
- Custom Tools: Domain-specific annotation tools
- Export Formats: Custom serialization (GeoJSON, XML, proprietary formats)
- Validation: Quality control and annotation validation workflows
Open Questions
- How should extensions access the viewer/canvas for rendering?
- Should extensions be able to extend the UI (add toolbar buttons, panels)?
- How to handle extension dependencies and conflicts?
- Should we support remote extensions (loaded from URLs)?
- How to manage extension state and persistence?
- Security considerations for third-party extensions?
Related
- Current AI integration: Contour tool uses OpenCV.js directly
- See
src/tools/contour.ts for existing pattern
Discussion
Please share your thoughts on:
- API design and developer experience
- Use cases and requirements
- Implementation approach
- Security and sandboxing needs
Overview
Design and implement an extension/plugin system to enable:
Design Goals
Proposed Extension API
Example Extension
Use Cases
Open Questions
Related
src/tools/contour.tsfor existing patternDiscussion
Please share your thoughts on: