GrabCut-Annotation-Tool

Annotation tool using GrabCut() of OpenCV.

It can be used to create datasets for semantic segmentation.

* Due to GrabCut's algorithm, it is suitable for annotation of data with clear boundaries.

Requirement

  • opencv-python 4.5.2.54 or later
  • Pillow 7.2.0 or later
  • PySimpleGUI 4.32.1 or later

Directory

│  app.py │  config.json │ ├─core │  │  gui.py │  └─util.py │ ├─input │ └─output ├─image └─annotation

app.py, core/gui.py, core/util.py

Source code.

input

Image files are stored in this directory.

output

Directory to save annotation results.

  • image:The resized image is stored here
  • annotation:Annotation result is stored her
    * Saved in PNG format in palette mode

Usage

Start it with the following command.

python app.py

The following options can be specified.

  • --input

    Input image storage path

    Default:input
  • --output_image

    Storage path of annotation result (image)

    Default:output/image
  • --output_annotation

    Storage path of annotation result (segmentation image)

    Default:output/annotation
  • --config

    Configuration file to be loaded

    Default:config.json

Using GrabCut-Annotation-Tool

File select

You can switch the annotation target by clicking the file list.

keyboard shortcut  ↑、p:preview file ↓、n:next file

Initial ROI designation

You can specify the initial ROI by right-drag the mouse when "Select ROI" is displayed.



After the drag is finished, GrabCut processing is performed.



The area is selected.



Background designation

You can specify the background by dragging the right mouse button.





前景指定

You can switch to foreground specification by unchecking "Manually label background".

keyboard shortcut Ctrl



You can specify the foreground by dragging the right mouse button.





Class ID switching

You can switch the class ID by pressing the check box.

The single digit ID can be switched with a shortcut key.

keyboard shortcut 0-9



After switching the class ID, it is necessary to specify the ROI.





Auto save

Resized images and annotation images are automatically saved for each GrabCut process.



If you do not want to save automatically, uncheck "Auto save".

If you want to save other than auto save, press "s" on the keyboard.



Other settings


  • Mask alpha:Image Mask Superimpose Display Shading Degree
  • Iteration:Number of iterations of the GrabCut algorithm
  • Draw thickness:Line thickness when foreground / background is specified
  • Output width:Width of output image
  • Output height:Vertical width of output image

ToDo

  • [x] Memory leak improvement
  • [x] Allows other than upper left → lower right drag when ROI is selected
  • [x] Show ROI selection when class ID is selected with a shortcut key

Author

Kazuhito Takahashi(https://twitter.com/KzhtTkhs)

GitHub

GitHub - Kazuhito00/GrabCut-Annotation-Tool: OpenCVのGrabCut()を利用したセマンティックセグメンテーション向けアノテーションツール(Annotation tool using GrabCut() of OpenCV. It can be used to create datasets for semantic segmentation.)
OpenCVのGrabCut()を利用したセマンティックセグメンテーション向けアノテーションツール(Annotation tool using GrabCut() of OpenCV. It can be used to create datasets for semantic segmentation.) - GitHub - Kazuhito00/GrabCut-Annotation-T...