Beispiel #1
0
def get_symbols(img, model):
    masks, coords = get_characters(img)
    masks = np.array([dataset_util.reshape(mask, config.SYMBOLS_INPUT_DIM[1:]) for mask in masks])
    prediction = classifier.predict(model, masks)
    best_pred = classifier_util.get_best_prediction(prediction)
    log(f"Symbols: {[classifier.LABELS[x] for x in best_pred]}", LOG_DEBUG, "Symbols")
    return best_pred, coords
Beispiel #2
0
def get_labels(img, model):
    masks, coords = get_characters(img)
    masks = array([
        dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:]) for mask in masks
    ])
    prediction = classifier.predict(model, masks)
    return [x for x in classifier_util.get_best_prediction(prediction)], coords
Beispiel #3
0
def get_indicator_features(image, model):
    masks, lit = get_characters(image)
    masks = [
        dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:]) for mask in masks
    ]
    prediction = classifier.predict(model, np.array(masks))
    best_pred = classifier_util.get_best_prediction(prediction)
    return lit, format_label([classifier.LABELS[p] for p in best_pred])
Beispiel #4
0
def get_password(img, model):
    masks = get_characters(img)
    masks = array([
        dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:]) for mask in masks
    ])
    prediction = classifier.predict(model, masks)
    best_pred = classifier_util.get_best_prediction(prediction)
    characters = [classifier.LABELS[x] for x in best_pred]
    return "".join(characters)
Beispiel #5
0
def identify_side_features(sides, model):
    flattened = []
    for side in sides:
        for img in side:
            converted = dataset_util.reshape(convert_to_cv2(img), config.MODULE_INPUT_DIM[1:])
            flattened.append(converted)
    preds = module_classifier.predict(model, array(flattened))
    predictions = classifier_util.get_best_prediction(preds)
    return predictions
def get_serial_number(img, model):
    masks, alignment = get_characters(img)
    if not alignment:
        log("ERROR: Could not determine alignment of serial number",
            LOG_WARNING, "Serial Number")
        return None
    masks = np.array([
        dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:]) for mask in masks
    ])
    prediction = classifier.predict(model, masks)
    best_pred = classifier_util.get_best_prediction(prediction)
    return create_serial_string(best_pred, alignment)  # Return actual string.
Beispiel #7
0
def get_details_async(model, holder):
    duration_masks = get_duration_characters()
    if len(duration_masks) != 3:
        log(f"WARNING: Bomb duration string length != 3 (len={len(get_duration_characters)}).",
            config.LOG_WARNING)
    module_masks = get_module_characters()
    masks = duration_masks + module_masks
    masks = np.array([dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:]) for mask in masks])
    prediction = classifier.predict(model, masks)
    best_pred = classifier_util.get_best_prediction(prediction)
    labels = [classifier.LABELS[p] for p in best_pred]
    holder.append(format_time(labels[:3]))
    holder.append(fix_number(labels[3:5]))
Beispiel #8
0
def get_button_features(image, model):
    masks, color = get_characters(image)
    if len(masks) == 4:
        return "Hold", color
    elif len(masks) == 8:
        return "Detonate", color
    else:
        masks = np.array(
            [dataset_util.reshape(masks[0], config.CHAR_INPUT_DIM[1:])])
        prediction = classifier.predict(model, masks[0])
        best_pred = classifier_util.get_best_prediction(prediction)
        if classifier.LABELS[best_pred[0]] == "a":
            return "Abort", color
        return "Press", color
Beispiel #9
0
def get_words(img, model):
    _, words, coords = get_characters(img)
    predictions = []
    for masks in words:
        result = " "
        if masks is not None:
            masks = np.array([
                dataset_util.reshape(mask, config.CHAR_INPUT_DIM[1:])
                for mask in masks
            ])
            prediction = classifier.predict(model, masks)
            result = get_word(prediction)
        predictions.append(result)
    return predictions, coords
Beispiel #10
0
def process_bomb_data(images):
    IMAGES_CAPTURED = 0
    predictions = []
    for img in images:
        cv2_img = convert_to_cv2(img)
        path = f"../resources/training_images/"
        if AUTO_LABEL:
            resized = dataset_util.reshape(cv2_img, config.MODULE_INPUT_DIM[1:])
            pred = classifier.predict(MODEL, resized)
            label = classifier_util.get_best_prediction(pred)[0]
            predictions.append(label)
            if label in INCLUDED_LABELS:
                if label < 7:
                    label_name = clean_file_path(classifier.LABELS[label])
                    path = f"{path}{label_name}/"
        if DATA_TYPE != "modules":
            num_images = len(glob(path + "*.png"))
            imwrite(f"{path}{num_images:03d}.png", cv2_img)
            IMAGES_CAPTURED += 1

    log(f"Captured {IMAGES_CAPTURED} bomb images.")
    return predictions