Exemple #1
0
def test_save_load_config(capsys):
    cfg = config.PipelinesConfig()
    cfg.morph_kernels_thickness = 10
    cfg.save_yaml('test_cfg.yaml')
    cfg2 = config.PipelinesConfig('test_cfg.yaml')
    assert (cfg.__dict__ == cfg2.__dict__)
    cfg.new_var = 10
    cfg.save_yaml('test_cfg.yaml')
    cfg2.load_yaml('test_cfg.yaml')
    captured = capsys.readouterr()
    assert ("WARNING" in captured.out)
Exemple #2
0
def test_update_num_iterations():
    cfg = config.PipelinesConfig()
    cfg.height_range = (5, 5)
    cfg.width_range = [(10, 10), (20, 20)]
    cfg.update_num_iterations()
    assert (cfg.num_iterations == 2)
    assert (len(cfg.height_range) == 2)
    assert (len(cfg.width_range) == 2)
Exemple #3
0
def DefaultConfig():
    cfg = config.PipelinesConfig()
    cfg.width_range = (30, 45)
    cfg.height_range = (30, 45)
    cfg.scaling_factors = [1.0]
    cfg.wh_ratio_range = (0.5, 1.5)
    cfg.group_size_range = (1, 100)
    cfg.dilation_iterations = 0
    cfg.morph_kernels_type = 'rectangles'
    return cfg
Exemple #4
0
def test_autoconfig_from_vott_simple():
    vott_dir = "tests/data/autoconfig_simple"
    file_path = "tests/data/autoconfig_simple/dummy_example.png"

    cfg = config.PipelinesConfig()
    cfg.autoconfigure_from_vott(vott_dir, class_tags=['box'])

    checkboxes = pipelines.get_checkboxes(file_path,
                                          cfg=cfg,
                                          px_threshold=0.01,
                                          plot=False,
                                          verbose=False)
    assert (len(checkboxes) == 12)

    cfg = config.PipelinesConfig()
    cfg.autoconfigure_from_vott(vott_dir, class_tags=['box'])

    rects, groups, _, _ = pipelines.get_boxes(file_path, cfg=cfg, plot=False)
    assert (len(rects) == 23)
    assert (len(groups) == 14)
Exemple #5
0
def test_autoconfig_simple():
    box_sizes = [(42, 44), (41, 47), (41, 44), (41, 44), (125, 54), (92, 103)]
    file_path = "tests/data/autoconfig_simple/dummy_example.png"

    cfg = config.PipelinesConfig()
    cfg.autoconfigure(box_sizes)

    checkboxes = pipelines.get_checkboxes(file_path,
                                          cfg=cfg,
                                          px_threshold=0.01,
                                          plot=False,
                                          verbose=False)
    assert (len(checkboxes) == 12)

    cfg = config.PipelinesConfig()
    cfg.autoconfigure(box_sizes)

    rects, groups, _, _ = pipelines.get_boxes(file_path, cfg=cfg, plot=False)
    assert (len(rects) == 23)
    assert (len(groups) == 14)
def get_checkbox_data_from_file(path):
    ig = cv.imread(path)
    data = []

    try:
        img_gry = cv.cvtColor(ig, cv.COLOR_BGR2GRAY)  # Gray scaling the image
    except Exception:
        name = path.split("\\")[-1]
        print(f" {name} is not a Image file.")
        return
    height, width = img_gry.shape  # To get the height and width of the image

    # Configuration for get_checkboxes
    cfg = config.PipelinesConfig()
    cfg.width_range = (15, 35)
    cfg.height_range = (15, 40)
    cfg.scaling_factors = [0.7]
    cfg.wh_ratio_range = (0.5, 1.7)

    # Checkboxes will contain data about all checkboxes in the image
    checkboxes = get_checkboxes(img_gry, cfg=cfg)
    print(f"{len(checkboxes)} checkbox found."
          )  # This will print total no of checkboxes found

    for checkbox in checkboxes:
        # checkbox[2] contains the pixel matrix of the current checkbox
        if box_checker(checkbox[2]):
            x, y, w, h = checkbox[0]
            # Crop out of image 80px in y direction
            # Here +80 is a kind of hard code, assuming 80 px from the top of box contains all data.
            cp = img_gry[y:y + 80, x:x + width]
            # This code will give desired data, but high chance of getting garbage value along with the data.
            text = tess.image_to_string(cp)
            data.append(text)
    if not data:
        print("No checkbox is checked")
    return data
Exemple #7
0
from common.common import compute_partial_ratio, compute_ratio, get_text_from_ocr, score_and_rank, apply_erosion, apply_dilatation, get_projection, load_image, find_runs, analyze_runs
from Training.Auto_Labelling.basic_implementation.autolabel_training import call_ocr

best_score = {}

config.thickness = 3
DATA_PATH = '../Data/'
file_name = 'form_example1.png'

# # Now we autodetect boxes on the form

# In[ ]:

from boxdetect import config

cfg = config.PipelinesConfig()

# important to adjust these values to match the size of boxes on your image
cfg.width_range = (30, 50)
cfg.height_range = (30, 35)

cfg.morph_kernels_type = 'rectangles'

# w/h ratio range for boxes/rectangles filtering
cfg.wh_ratio_range = (0.5, 1.6)

cfg.group_size_range = (2, 1000)

# In[ ]:

from boxdetect.pipelines import get_boxes