haiercv 0.1.4
Haier Uplus Intelligent Technology (Beijing) Co., Ltd Computer Vision Group data annotation scripts
License: MIT
Requires Python: >=2

# Download package
```batch
pip install haiercv
```

# Usage sample
```python
from haiercv.annotation.pre_process import pre_process
from haiercv.annotation.check_label import check_xml, check_json
from haiercv.annotation.segment_class import segment_class_batch
from haiercv.annotation.modify_label import modify_label

import argparse


def image_pre_process():
    """
    Specify `-f` parameter to decide which function(s) to apply:
        1. Only rename file, but want to keep the original suffix:
            -f=rename
        2. Only convert to .jpg file, but want to keep the original file name:
            -f=jpg
        3. Simply re-write the image to erase Exif and do nothing to either file name or suffix:
            -f=rewrite
        4. Erase Exif, rename, and convert to .jpg:
            -f=all
        Note: In any case, Exif will be erased.

    Usage example:
        python label_standard.py -a name_initials -s 1 -o ori_path -p target_path
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("-a", "--annotator", default="default", type=str,
                        help="annotator's name")
    parser.add_argument("-t", "--sort", default='n', type=str,
                        choices=['n', 'c', 'm',
                                 'nd', 'cd', 'md'],
                        help="n: file name; c: creation time; m: modification time"
                             "d: descending (ascending by default)")
    parser.add_argument("-s", "--start", default=1, type=int,
                        help="from which number number to start")
    parser.add_argument("-o", "--ori_path", default='', type=str,
                        help="original image folder")
    parser.add_argument("-p", "--target_path", default='', type=str,
                        help="target folder")
    parser.add_argument("-f", "--function", default='all', type=str,
                        help="choose the function to use: "
                             "rename: rename and rewrite the file (instead of copying), but maintain the suffix; "
                             "jpg: rewrite and change file suffix to .jpg; "
                             "rewrite: rewrite, but maintain file name and suffix; "
                             "all: rewrite, rename, and change suffix to .jpg",
                        choices=['rename', 'jpg', 'rewrite', 'all'])
    cfg = parser.parse_args()

    sort = cfg.sort
    start = cfg.start
    ori_path = cfg.ori_path
    target_path = cfg.target_path
    do_rename = None
    do_jpg = None
    if cfg.function == 'all':
        do_rename = True
        do_jpg = True
    elif cfg.function == 'rename':
        do_rename = True
    elif cfg.function == 'jpg':
        do_jpg = True
    elif cfg.function == 'rewrite':
        do_jpg = False
        do_rename = False
    annotator = cfg.annotator.replace("'", '')

    pre_process(sort=sort,
                start=start,
                ori_path=ori_path,
                target_path=target_path,
                do_rename=do_rename,
                do_jpg=do_jpg,
                annotator=annotator)


def label_check():
    """
    Usage:
        Label set:
            Either
            1. read labels from file, or
            2. define a list containing all labels.

        Folder path:
            Specify `folder_path` when calling functions.
    """
    # If you have a file containing all labels, uncomment the following lines #
    # label_file_path = r''
    # with open(label_file_path, 'r') as f:
    #     all_labels = [Symbol.strip('\n') for Symbol in f]  # labels

    # If you define all labels as follows, uncomment the following lines #
    all_labels = []

    # path to xml folder
    xml_folder_path = r''
    # path to json folder
    json_folder_path = r''

    check_xml(xml_folder_path, all_labels, xml_folder_path)
    check_json(xml_folder_path, all_labels, xml_folder_path)


def segment_batch():
    """
    Usage:
        Specify `xml_folder_path`, `img_folder_path`, `segment_folder_path`.
    """
    # path to xml folder
    xml_folder_path = r''
    # path to image folder
    img_folder_path = r''
    # path to save segmented bounding boxes
    segment_folder_path = r''

    segment_class_batch(xml_folder_path, img_folder_path, segment_folder_path)


def label_modification():
    """
    Usage:
        Specify `xml_folder_path`, `segment_folder_path`,
        which are expected to be the same as in `segment_batch()`
    """
    xml_folder_path = r''
    segment_folder_path = r''

    modify_label(xml_folder_path, segment_folder_path)


if __name__ == '__main__':
    ...
    # image_pre_process()
    # label_check()
    # segment_batch()
    # label_modification()

```