Crate cocotools

source ·
Expand description

The cocotools crate provides tools to load, manipulate, convert and visualize COCO format datasets. The base class is the COCO struct, usually loaded from a COCO json annotation file.

This crate aims to provide similar functionalities to the python pycocotools package / cocoapi with additionnal utilities such as conversion between dataset formats. It also aims to have a better documentation and a more readable implementation.

Usage examples

Getting information about an image..

use cocotools::COCO;

let annotations_file_path = PathBuf::from("../data_samples/coco_25k/annotations.json");
let image_folder_path = PathBuf::from("../data_samples/coco_25k/images");
let coco_dataset = COCO::new(&annotations_file_path, &image_folder_path)?;
assert_eq!(coco_dataset.get_img(17627)?.file_name, "000000017627.jpg");

Loading a segmentation mask

use cocotools::COCO;
use cocotools::mask;
use cocotools::mask::conversions;
use cocotools::coco::object_detection;

let annotations_file_path = PathBuf::from("../data_samples/coco_25k/annotations.json");
let image_folder_path = PathBuf::from("../data_samples/coco_25k/images");
let coco_dataset = COCO::new(&annotations_file_path, &image_folder_path)?;
let anns = coco_dataset.get_img_anns(174482)?;
let mask = mask::Mask::try_from(&anns[0].segmentation)?;
assert_eq!(mask.ncols(), 388);
assert_eq!(mask.nrows(), 640);

Re-exports

  • pub use crate::coco::COCO;

Modules

  • Module containing the data annotation formats.
  • Module with the errors for the crate.
  • Module containing utilities to convert data formats.
  • Module for drawing and displaying annotations.