Skip to content
Snippets Groups Projects
Helpers.py 954 B
Newer Older
import cv2
import math


def CalculateWidth(size, h, w, imgCropped, imgFixed):
    c = size / h
    wCal = math.ceil(c * w)
    imgResized = cv2.resize(imgCropped, (wCal, size))

    wGap = math.ceil((size - wCal) / 2)
    imgFixed[:, wGap:wCal + wGap] = imgResized


def CalculateHeight(size, h, w, imgCropped, imgFixed):
    c = size / w
    hCal = math.ceil(c * h)
    imgResized = cv2.resize(imgCropped, (size, hCal))

    hGap = math.ceil((size - hCal) / 2)
    imgFixed[hGap:hCal + hGap, :] = imgResized


def GetPrediction(classifier, imgFixed):
Michiel_VE's avatar
Michiel_VE committed
    cv2.imshow('imgFixed helper', imgFixed)
    prediction, index = classifier.getPrediction(imgFixed)

    return prediction, index


def GetLabels(path):
    letters = []
    with open(path, 'r') as file:
        for line in file:
            parts = line.strip().split(' ')
            if len(parts) == 2:
                letter = parts[1]
                letters.append(letter)

Michiel_VE's avatar
Michiel_VE committed
    return letters