Skip to content

ba-san/Count-Annotator2

Repository files navigation

Count-Annotator2

Overview

This program is an annotation support program for creating datasets of training images, which is essential in recent image recognition, especially for handling crowd and cell data.

You can create point-annotated images for object counting and a CSV file that contains each point's location.
Plus, this programs aims to make small cropped images from a single image like 4K-image.

You can see the demo movie below (click the image and will direct to Youtube).
DEMO MOVIE

The programs work on both Linux and Windows.
Please note that programs are designed to work in teams.

(This repository itself is a successor of Count-Annotator. )

Guidance with images

From a big single frame, the programs will create a myriad of cropped images.
To do this, 1.input original images that has objects you want to annotate.

2.annotate objects manually.

3.The programs will crop images in a sliding window manner (red thick box below).

You can get annotated images and a CSV file which contains each point's location. One directory for one frame.

Tutorial Workflow

video2img.py --> copy created img folder to root directory(pocari-cm.mp4) --> annotation.py --> checker.py
--> cropping.py --> inside output folder(pocari-cm.mp4_output), integrate_img4dataset.py
--> move created folder to lessen --> lessen.py --> (image_resize_LANCZOS.py)

Notice: Annotation directory transition

Count-Annotator2 is useful for teams. Each member can create training data using annotaion2.py and a leader can check each data quality by checker.py.

When you annotate data by annotation2.py, directories for each frame will be created (Blue box).
After that, a leader can check each annotated frame by checker.py. The name of directory checked by him/her will be changed to "OO_checked" (Green box).
Finally, you can crop checked frames by running cropping.py exclusively. Directory's name will be changed to "OO_cropped" again (Red box). This is the final deliverable.

Set up

It is recommended to use Python3.7.
1.download this repository.

git clone https://github.com/ba-san/Count-Annotator2.git  

2.install packages.

pip install -r requirements.txt    

How to use

0. (Optional) Converting videos into images

If you won't use video as input, you can skip it.

  1. setting the path and frame in video2img.py
foldername = 'demo'

You can change frame interval here.
Just change the number below.

	30, cnt, # frame interval, counting videos
  1. run by python video2img.py

1. Annotation

  1. setting the path in annotation.py
folder = "pocari-cm.mp4" #input images in this directory

2.run by python annotation.py

Keyboard intructions

Z,X,C -- count object (different colors)
   V    -- cover black mask
   B    -- stop annotation. DO NOT END IT BY TYPING 'Ctrl + C' OR ANY OTHER WAY!!
   F    -- delete nearest point
   D    -- delete nearest mask
   E    -- delete white point
   G    -- show/remove grid
   H    -- fix y-cordinate of red box
   T    -- refer to original/denoised image (some functions cannot be used while this mode)
   U    -- show histgram-equalized image
   Y    -- make image sharp
   P    -- pend image
I,J,K,M-- move pointer up, left, right, down respectively
   A,S -- make circle smaller/bigger
   Q,W -- make window smaller/bigger
Enter(and N)-- move to next image

2. Double checking

If you are annotating as a team, it's highly reccomended only a team leader use this script.
In the case you run checker.py at different environments from "OO_output" was originally created, change images' path inside OO.csv to match to your environment!! (You can use path_changer.py for this purpose.)

  1. setting the path in checker.py
folder = "pocari-cm.mp4" # must be "OO_output"
  1. run by python checker.py

Keyboard intructions

Refer above.

3. Cropping

0.make sure each img's path inside csv is correct.
(You need to use path_changer.py beforehand if the cropping directory is different from annotation or double checking directory. )

1.set cropped image size and the intervals of sliding window.

## change setting here ##
width = 256 # cropped image's width
height = 256 # cropped image's height
x_gap = 30 # gap between cropped images' left side
y_gap = 30 # gap between cropped images' upper side
#########################

In this case, cropped image size is 256px x 256px
and interval of slidng window is 30px for both x and y.

2.run by python cropping.py
Program will automatically detect "OO_checked" files and crops them all at once.

3.integrate cropped images.
Inside your 'OO_output' directory, run python integrate_img4dataset.py.

4. (Optional) Downsampling

0.move cropped directory into 'lessen' directory.

1.set values below in lessen.py

source = "pocari-cm.mp4_output_256_256_30_30_0" # set name of the directory
max_train = 222 # maximum number of train image per class
max_test = 153 # maximum number of test image per class 

Note: Please be noted that each category directory has a single CSV file.
You need to take it into account when run lessen.py.

2.run by python lessen.py

5. (Optional) Resize

0.set values below in image_resize_LANCZOS.py

dirname = "pocari-cm.mp4_output_256_256_30_30_0" # set the directory name
resized = 32 # set the size here

1.run by python image_resize_LANCZOS.py

About

annotation environment for object counting

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages