Exemplo n.º 1
0
class SheetMusicTemplateClassifier(IFullClassifier):
    def __init__(self, config):
        """
        Constructor, initialisiert Membervariablen.

        :param config:          Die Config für den SheetMusicClassifier
        """

        self.__logger = State().getLogger("DetectionCore_Component_Logger")
        self.__logger.info("Starting __init__()",
                           "SheetMusicTemplateClassifier:__init__")
        self.__config = config

        lineRemoveConfig = self.__config["HorizontalLineRemoveDetector"]
        self.__horizontalLineRemoveDetector = HorizontalLineRemoveDetector \
            (indexOfProcessMat=lineRemoveConfig["indexOfProcessMat"],
             anchorPoint=(lineRemoveConfig["anchorPointX"], lineRemoveConfig["anchorPointY"]),
             kernelWidth=lineRemoveConfig["kernelWidth"],
             kernelHeight=lineRemoveConfig["kernelHeight"],
             morphOfKernel=getattr(cv2, lineRemoveConfig["morphOfKernel"]),
             showImagesInWindow=lineRemoveConfig["showImagesInWindow"])

        lineDetectorConfig = self.__config["NoteLineDetector"]
        self.__noteLineDetector = NoteLineDetector \
            (indexOfProcessMat=lineDetectorConfig["indexOfProcessMat"],
             maxGradeOfLinesInPx=lineDetectorConfig["maxGradeOfLinesInPx"],
             minDistanceToNextNoteRow=lineDetectorConfig["minDistanceToNextNoteRow"],
             marginTop=lineDetectorConfig["marginTop"],
             marginBottom=lineDetectorConfig["marginBottom"],
             cannyThreshold1=lineDetectorConfig["cannyThreshold1"],
             cannyThreshold2=lineDetectorConfig["cannyThreshold2"],
             cannyApertureSize=lineDetectorConfig["cannyApertureSize"],
             houghLinesRho=lineDetectorConfig["houghLinesRho"],
             houghLinesTheta=np.pi / 180 * lineDetectorConfig["houghLinesThetaInDegree"],
             houghLinesThreshold=lineDetectorConfig["houghLinesThreshold"],
             showImagesInWindow=lineDetectorConfig["showImagesInWindow"])

        tactDetectorConfig = self.__config["TactDetector"]
        self.__tactDetector = TactDetector \
            (indexOfProcessMat=tactDetectorConfig["indexOfProcessMat"],
             tactLineWidthMax=tactDetectorConfig["tactLineWidthMax"],
             tactLineHeightMin=tactDetectorConfig["tactLineHeightMin"],
             minWidthOfTactLine=tactDetectorConfig["minWidthOfTactLine"],
             findCountersMode=getattr(cv2, tactDetectorConfig["findCountersMode"]),
             findCountersMethode=getattr(cv2, tactDetectorConfig["findCountersMethode"]),
             showImagesInWindow=tactDetectorConfig["showImagesInWindow"])

        self.__clefClassifier = ClefTemplateClassifier(
            self.__config["ClefTemplateClassifier"])

        self.__timeClassifier = TimeTemplateClassifier(
            self.__config["TimeTemplateClassifier"])

        self.__keyClassifier = KeyTemplateClassifier(
            self.__config["KeyTemplateClassifier"])

        noteDetectorConfig = self.__config["NoteDetector"]
        self.__noteDetector = NoteDetector \
            (indexOfProcessMat=noteDetectorConfig["indexOfProcessMat"],
             minNoteWidth_WithStem=noteDetectorConfig["minNoteWidth_WithStem"],
             maxNoteWidth_WithStem=noteDetectorConfig["maxNoteWidth_WithStem"],
             minNoteHeight_WithStem=noteDetectorConfig["minNoteHeight_WithStem"],
             maxNoteHeight_WithStem=noteDetectorConfig["maxNoteHeight_WithStem"],
             minNoteWidth_WithoutStem=noteDetectorConfig["minNoteWidth_WithoutStem"],
             maxNoteWidth_WithoutStem=noteDetectorConfig["maxNoteWidth_WithoutStem"],
             minNoteHeight_WithoutStem=noteDetectorConfig["minNoteHeight_WithoutStem"],
             maxNoteHeight_WithoutStem=noteDetectorConfig["maxNoteHeight_WithoutStem"],
             noteImageWidth=noteDetectorConfig["noteImageWidth"],
             findCountersMode=getattr(cv2, noteDetectorConfig["findCountersMode"]),
             findCountersMethode=getattr(cv2, noteDetectorConfig["findCountersMethode"]),
             showImagesInWindow=noteDetectorConfig["showImagesInWindow"])

        # NoteHeightBlobClassifier wird nicht mehr benoetigt, da die
        # Notenhoehe von einem CNN klassifiziert wird.
        """
        noteDetectorConfig = self.__config["NoteDetector"]
        self.__noteHeightBlobClassifier = NoteHeightBlobClassifier \
            (indexOfProcessMatWithoutLines=noteDetectorConfig["indexOfProcessMatWithoutLines"],
             indexOfProcessMatWithLines=noteDetectorConfig["indexOfProcessMatWithLines"],
             maxGradeOfLinesInPx=noteDetectorConfig["maxGradeOfLinesInPx"],
             marginTop=noteDetectorConfig["marginTop"],
             marginBottom=noteDetectorConfig["marginBottom"],
             cannyThreshold1=noteDetectorConfig["cannyThreshold1"],
             cannyThreshold2=noteDetectorConfig["cannyThreshold2"],
             cannyApertureSize=noteDetectorConfig["cannyApertureSize"],
             houghLinesRho=noteDetectorConfig["houghLinesRho"],
             houghLinesTheta=np.pi / 180 * noteDetectorConfig["houghLinesThetaInDegree"],
             houghLinesThreshold=noteDetectorConfig["houghLinesThreshold"],
             showImagesInWindow=noteDetectorConfig["showImagesInWindow"])
        """

        fillerConfig = self.__config["ImageFiller"]
        self.__imageFiller = ImageFiller \
            (fillRows=fillerConfig["fillRows"],
             fillColumns=fillerConfig["fillColumns"],
             targetNumberOfRows=fillerConfig["targetNumberOfRows"],
             targetNumberOfColumns=fillerConfig["targetNumberOfColumns"],
             appendRowsTop=fillerConfig["appendRowsTop"],
             appendColumnsRight=fillerConfig["appendColumnsRight"],
             showImagesInWindow=fillerConfig["showImagesInWindow"])

        centeringConfig = self.__config["ObjectCentering"]
        self.__objectCentering = ObjectCentering \
            (indexOfProcessMat=centeringConfig["indexOfProcessMat"],
             targetNumberOfRows=centeringConfig["targetNumberOfRows"],
             targetNumberOfColumns=centeringConfig["targetNumberOfColumns"],
             useDeletingVerticalSpaces=centeringConfig["useDeletingVerticalSpaces"],
             useDeletingHorizontalSpaces=centeringConfig["useDeletingHorizontalSpaces"],
             findCountersMode=getattr(cv2, centeringConfig["findCountersMode"]),
             findCountersMethode=getattr(cv2, centeringConfig["findCountersMethode"]),
             colorOfBorder=centeringConfig["colorOfBorder"],
             showImagesInWindow=centeringConfig["showImagesInWindow"])

        resizerConfig = self.__config["ImageResizer"]
        self.__imageResizerForCnn = ImageResizer \
            (targetNumberOfRows=resizerConfig["targetNumberOfRows"],
             targetNumberOfColumns=resizerConfig["targetNumberOfColumns"],
             interpolation=getattr(cv2, resizerConfig["interpolation"]),
             showImagesInWindow=resizerConfig["showImagesInWindow"])

        dirname, _ = os.path.split(os.path.abspath(__file__))
        cnnConfig = self.__config["CnnNoteClassifier"]
        self.__cnnNoteClassifier = CnnNoteClassifier \
            (modelDir=dirname + cnnConfig["modelDir"],
             gdLearnRateForTypeModel=cnnConfig["gdLearnRateForTypeModel"],
             gdLearnRateForHightModel=cnnConfig["gdLearnRateForHightModel"],
             trainSteps=cnnConfig["trainSteps"],
             evalInterval=cnnConfig["evalInterval"],
             evalDataSize=cnnConfig["evalDataSize"],
             testDataSize=cnnConfig["testDataSize"],
             trainTypeModel = cnnConfig["trainTypeModel"],
             trainHightModel = cnnConfig["trainHightModel"])

        self.__logger.info("Finished __init__()",
                           "SheetMusicTemplateClassifier:__init__")

    def executeClassification(self, mat):
        """
        Führt die Klassifizierung auf einer Bildmatrix aus und gibt die erkannte IClassification zurück.

        Parameters
        ----------
        mat : Die Bildmatrix auf welche die Klassifizierung ausgeführt werden soll.

        Returns
        -------
        classification : IClassification
        Aus dem Eingabematrix erkannte IClassification (z.B. Note, Slur, Rest).

        Example
        -------
        >>> sheetMusicTemplateClassifier.executeClassification(mat)
        """
        self.__logger.info(
            "Starting executeClassification()",
            "SheetMusicTemplateClassifier:executeClassification")
        classification = SheetMusic()

        noteLinesWithoutHLines = self.__horizontalLineRemoveDetector.detect(
            mat)
        noteLines = self.__noteLineDetector.detect(noteLinesWithoutHLines)
        tacts = self.__tactDetector.detect(noteLines)

        # --- Takt Klassifikation ---
        elementCounter = 1
        lastClefLine = 0
        lastClefSign = ""

        # Führt für jeden erkannten Takt aus
        for i in range(0, len(tacts[0])):
            # self.__logger.debug("Analyzing Tact", image = tacts[0][i])

            tactInternalCounter = 1
            tactClassification = classification.creatTact(
                i + 1, elementCounter)  # Neuer Takt
            elementCounter += 1

            # ----- Clef -----
            clefClassification = tactClassification.creatClef(
                tactInternalCounter, elementCounter)

            if self.__clefClassifier.classify(
                    clefClassification,
                [tacts[0][i], tacts[1][i], tacts[2][i]]):
                if (clefClassification.sign != lastClefSign
                        or clefClassification.line != lastClefLine):
                    tactClassification.addClef(
                        clefClassification
                    )  # Füge Notenschlüssel zu Takt hinzu
                    elementCounter += 1
                    tactInternalCounter += 1
                    lastClefSign = clefClassification.sign
                    lastClefLine = clefClassification.line

            # ----- KeySignature -----
            keyClassification = tactClassification.creatKeySignature(
                tactInternalCounter, elementCounter)

            if self.__keyClassifier.classify(
                    keyClassification,
                [tacts[0][i], tacts[1][i], tacts[2][i]]):
                tactClassification.addKeySignatur(
                    keyClassification)  # Füge Tonhöheangabe zu Takt hinzu
                elementCounter += 1
                tactInternalCounter += 1

            # ----- Time -----
            timeClassification = tactClassification.creatTimeSignature(
                tactInternalCounter, elementCounter)

            if self.__timeClassifier.classify(
                    timeClassification,
                [tacts[0][i], tacts[1][i], tacts[2][i]]):
                tactClassification.addTimeSignatur(
                    timeClassification)  # Füge Rythmus zu Takt hinzu
                elementCounter += 1
                tactInternalCounter += 1

            classification.addTact(
                tactClassification)  # Füge Takt zur Klassifikation hinzu
        # --- Takt Klassifikation ---

        notes, noteCountPerTact = self.__noteDetector.detect(tacts)
        self.__logger.debug(
            "Return from noteDetector 0",
            "SheetMusicTemplateClassifier::executeClassification",
            notes[0][0])  # Ohne Linien
        self.__logger.debug(
            "Return from noteDetector 1",
            "SheetMusicTemplateClassifier::executeClassification",
            notes[1][0])  # Mit Linien

        filledNotes = self.__imageFiller.coreProcess(notes)
        centeredNotes = self.__objectCentering.coreProcess(filledNotes)
        cnnNotes = self.__imageResizerForCnn.coreProcess(centeredNotes)

        # notesHeight = self.__noteHeightBlobClassifier.classify(notes)
        # self.__logger.debug("Return from noteHeightBlobClassifier 0", "SheetMusicTemplateClassifier::executeClassification", notesHeight[0][0]) # Ohne Linien
        # self.__logger.debug("Return from noteHeightBlobClassifier 1", "SheetMusicTemplateClassifier::executeClassification", notesHeight[1][0]) # Mit Linien

        # ----- Classify Notes -----

        notes = self.__cnnNoteClassifier.classify(cnnNotes[0], cnnNotes[1])

        # Fülle die Takte mit den erkannten Noten und nutze zur Vermeidung von Fehlerfortpflanzung noteCountPerTact
        noteIndex = 0
        for t in range(0, len(noteCountPerTact)):
            for n in range(0, noteCountPerTact[t]):
                chord = classification.tacts[t].creatChord(
                    classification.tacts[t].tactNumber, n)
                note = chord.creatNote(classification.tacts[t].tactNumber, n,
                                       chord.chordInternalNumber)
                note.pitch = notes[noteIndex].pitch
                note.type = notes[noteIndex].type
                chord.addNote(note)
                classification.tacts[t].addChord(chord)
                noteIndex += 1
                self.__logger.debug(
                    ("Tact " + str(t) + " added Note on pos " + str(n) +
                     " type: " + note.type + " pitch: " + str(note.pitch)),
                    "SheetMusicTemplateClassifier:executeClassification")

        self.__logger.info(
            "Finished executeClassification()",
            "SheetMusicTemplateClassifier:executeClassification")
        return classification

    def buildTraindata(self, mat):
        """
        Interface Methode: Jeder FullClassifier muss diese realisieren.
        Erstellt Trainingdaten für das Trainieren seiner Classifier

        :param Bildmatrix : mat Die Bildmatrix aus welcher die Trainingdaten erstellt werden soll.
        :return: trainData : matArray Aus dem Eingabematrix erstellte Trainingdaten.
        """
        self.__logger.info("Starting buildTraindata()",
                           "SheetMusicTemplateClassifier:buildTraindata")

        noteLinesWithoutHLines = self.__horizontalLineRemoveDetector.detect(
            mat)
        noteLines = self.__noteLineDetector.detect(noteLinesWithoutHLines)
        tacts = self.__tactDetector.detect(noteLines)
        notes, _ = self.__noteDetector.detect(tacts)

        self.__logger.debug("Return from noteDetector 0",
                            "SheetMusicTemplateClassifier::buildTraindata",
                            notes[0][0])  # Ohne Linien
        self.__logger.debug("Return from noteDetector 1",
                            "SheetMusicTemplateClassifier::buildTraindata",
                            notes[1][0])  # Mit Linien

        filledNotes = self.__imageFiller.coreProcess(notes)
        centeredNotes = self.__objectCentering.coreProcess(filledNotes)
        cnnNotes = self.__imageResizerForCnn.coreProcess(centeredNotes)

        self.__logger.info("Finished executeClassification()",
                           "SheetMusicTemplateClassifier:buildTraindata")
        return cnnNotes

    def train(self, inputMatArray, lableArray):
        """
        Trainiert alle trainierbaren Classifier mit den gegebenen Trainingsdaten

        :param Bildmatrizen: inputMatArray Die Bildmatrizen für das Training.
        :param Lable: lableArray Die Lable zu den Bildmatrizen für das Training.
        :return: successful : boolean War das Training erfolgreich?
        """
        self.__logger.info("Started train()",
                           "SheetMusicTemplateClassifier:train")

        self.__cnnNoteClassifier.train(inputMatArray, lableArray)

        self.__logger.info("Finished train()",
                           "SheetMusicTemplateClassifier:train")
Exemplo n.º 2
0
class ClefDetector(IDetector):
    def __init__(self,
                 delimitWidthMax=30,
                 delimitWidthMin=20,
                 delimitHeightMin=20,
                 templateThreshold=0.55,
                 templateMethod=cv2.TM_CCOEFF_NORMED,
                 findCountersMode=cv2.RETR_LIST,
                 findCountersMethode=cv2.CHAIN_APPROX_NONE):
        """
        Konstruktor für den ClefDetector.

        :param delimitWidthMax:     Maximale Breite eines Notenschlüssels.
        :param delimitWidthMin:     Minimale Breite eines Notenschlüssels.
        :param delimitHeightMin:    Minimale Höhe eines Notenschlüssels.
        :param templateThreshold:   Der Wert den das Template-Matching mindestens erreichen muss, damit ein Bildauschnitt als der jeweilige Notenschlüssel erkannt wird
        :param templateMethod:      Methode des Template-Matchers
        :param findCountersMode:    Modus des Konturfindungs-Algorithmus
        :param findCountersMethode: Methode des Konturfindungs-Algorithmus
        """

        self.__logger = State().getLogger("DetectionCore_Component_Logger")
        self.__logger.info("Starting __init__()", "ClefDetector:__init__")

        self.__delimitWidthMax = delimitWidthMax
        self.__delimitWidthMin = delimitWidthMin
        self.__delimitHeightMin = delimitHeightMin
        self.__templateThreshold = templateThreshold
        self.__templateMethod = templateMethod
        self.__findCountersMode = findCountersMode
        self.__findCountersMethode = findCountersMethode

        self.__logger.info("Finished __init__()", "ClefDetector:__init__")

    def detect(self, matArray):
        """
        Detection Funktion. Geerbt von IDetector.

        :param matArray:        Liste von Bilder, welche die Takte enthalten
        :return:                Liste alles gefundenen Notenschlüssel mit und ohne Notenlinien
        """
        self.__logger.info("Starting detect()", "ClefDetector:detect")

        # Initialierung der Taktlisten:
        # 1. List ohne und die 2. Liste mit Notenlinien
        clefMatsNoLines = []
        clefMatsLines = []

        # Variablen zum Zeichnen
        lineThickness = 1
        rectangleColor = (0, 255, 0)

        for j in range(0, len(matArray[0])):
            mat = matArray[0][j].copy()  # Takt ohne Linien
            matLine = matArray[1][j].copy()

            xCoordinates = []
            xCoordinates.append([0, 0])

            self.__logger.debug("Starting detect Clefs for image",
                                "ClefDetector:detect", mat)

            # Finde alle Konturen im Takt
            _, contours, _ = cv2.findContours(
                image=mat,
                mode=self.__findCountersMode,
                method=self.__findCountersMethode)

            found = False
            for i in range(0, len(contours)):
                # Erstelle aus einem Konturelement ein Rechteck
                # und speichere die benoetigten parameter
                x, y, w, h = cv2.boundingRect(contours[i])

                if (self.__delimitWidthMin <= w and w < self.__delimitWidthMax
                        and h >= self.__delimitHeightMin):
                    found = True

                    # Falls es sich um einen Violinschlüssel handelt, im Bild markieren und koordinaten merken
                    if self.__isViolin(mat[:, x:x + w]):
                        xCoordinates.append([x, x + w])

                        cv2.rectangle(img=mat,
                                      pt1=(x, y),
                                      pt2=(x + w, y + h),
                                      color=rectangleColor,
                                      thickness=lineThickness)

                    # TODO an dieser Stelle die gefundenen prüfen ob vll ein Bassschlüssel

            if found:
                self.__logger.info("Detect following rectangle: ",
                                   "ClefDetector:detect", mat)

            # Sortieren der gefundenen Elemente von links nach rechts
            xCoordinates.sort(key=itemgetter(0))

            # Ueberpruefe alle gefundenen Noten auf ihre Mindestbreite
            for i in range(1, len(xCoordinates)):
                x0 = xCoordinates[i][0]
                x1 = xCoordinates[i][1]
                clefMatsNoLines.append(mat[:, x0:x1])
                clefMatsLines.append(matArray[1][j][:, x0:x1])

        for i in range(0, len(clefMatsNoLines)):
            self.__logger.info("Detected following clef: ",
                               "ClefDetector:detect", clefMatsNoLines[i])

        self.__logger.info("Finished detect()", "ClefDetector:detect")

        return clefMatsNoLines, clefMatsLines

    def __isViolin(self, image):
        """
        Funktion, welche feststellt ob es sich bei einem gegebenen Bildauschnitt um einen Violinschlüssel handelt oder nicht.

        :param image: Bildauschnitt, welcher untersucht wird.
        :return: [True] wenn ein Violinschlüssel, [False] falls nicht.
        """

        # Lade Template als Graustufenbild
        #template = cv2.cvtColor(cv2.imread("DetectionCore_Component/Detector/templates/clef_violin.jpg"), cv2.COLOR_BGR2GRAY)
        template = cv2.imread(
            "DetectionCore_Component/Detector/templates/clef_violin.jpg", 0)

        # Wenn Bild kleiner als Template ist, brich ab mit False
        if image.shape[0] >= template.shape[0] and image.shape[
                1] >= template.shape[1]:
            match = cv2.matchTemplate(image, template, self.__templateMethod)
        else:
            self.__logger.warning("Template to small",
                                  "ClefDetector:__isViolin")
            return False

        # Wenn einer der Werte im Match größer als der vordefinierte Threshold ist, handelt es sich um einen Violinschlüssel
        if (match >= self.__templateThreshold).any():
            return True
        else:
            return False
Exemplo n.º 3
0
class KeyDetector(IDetector):
    def __init__(self,
                 templateThreshold=0.75,
                 templateMethod=cv2.TM_CCOEFF_NORMED,
                 findCountersMode=cv2.RETR_LIST,
                 findCountersMethode=cv2.CHAIN_APPROX_NONE):
        """
        Konstruktor für den KeyDetector.

        :param templateThreshold:   Der Wert den das Template-Matching mindestens erreichen muss, damit ein Bildauschnitt als der jeweilige Key erkannt wird
        :param templateMethod:      Methode des Template-Matchers
        :param findCountersMode:    Modus des Konturfindungs-Algorithmus
        :param findCountersMethode: Methode des Konturfindungs-Algorithmus
        """

        self.__logger = State().getLogger("DetectionCore_Component_Logger")
        self.__logger.info("Starting __init__()", "KeyDetector:__init__")

        self.__templateThreshold = templateThreshold
        self.__templateMethod = templateMethod
        self.__findCountersMode = findCountersMode
        self.__findCountersMethode = findCountersMethode

        self.__logger.info("Finished __init__()", "KeyDetector:__init__")

    def detect(self, matArray):
        """
        Detection Funktion. Geerbt von IDetector.

        :param matArray:        Liste von Bilder, welche die Takte enthalten
        :return:                Liste alles gefundenen Keys mit und ohne Notenlinien
        """
        self.__logger.info("Starting detect()", "KeyDetector:detect")

        # Initialierung der Taktlisten:
        # 1. List ohne und die 2. Liste mit Notenlinien
        clefMatsNoLines = []
        clefMatsLines = []

        # Variablen zum Zeichnen
        lineThickness = 1
        rectangleColor = (0, 255, 0)

        for j in range(0, len(matArray[0])):
            mat = matArray[0][j].copy()  # Takt ohne Linien
            matLine = matArray[1][j].copy()  # Takt mit Linien

            self.__logger.debug("Starting detect Keys for image",
                                "KeyDetector:detect", mat)

            found = False
            template = cv2.imread(
                "DetectionCore_Component/Detector/templates/key_b.jpg", 0)
            w, h = template.shape[::-1]

            res = cv2.matchTemplate(mat, template, cv2.TM_CCOEFF_NORMED)
            loc = np.where(res >= self.__templateThreshold)

            for pt in zip(*loc[::-1]):
                found = True
                cv2.rectangle(mat, pt, (pt[0] + w, pt[1] + h), rectangleColor,
                              lineThickness)
                cv2.rectangle(matLine, pt, (pt[0] + w, pt[1] + h),
                              rectangleColor, lineThickness)
                clefMatsNoLines.append(mat[:, pt[0]:pt[0] + w])
                clefMatsLines.append(matLine[:, pt[0]:pt[0] + w])

            if found:
                self.__logger.info("Detect following rectangle: ",
                                   "KeyDetector:detect", mat)

        for i in range(0, len(clefMatsNoLines)):
            self.__logger.info("Detected following clef: ",
                               "KeyDetector:detect", clefMatsNoLines[i])

        self.__logger.info("Finished detect()", "KeyDetector:detect")

        return clefMatsNoLines, clefMatsLines
Exemplo n.º 4
0
class Input(IInput):
    def __init__(self, config):
        """
        Konstruktor
        :param config:
        """
        self.__logger = State().getLogger("Input_Component_Logger")
        self.__logger.info("Starting __init__()", "Input:__init__")

        self.__matParser = None
        self.__lableParser = None

        self.__matXMLPairCounter = 0
        self.__matFileNamesForTestDataCreation = 0
        self.__xmlFileNamesForTestDataCreation = 0

        self.__createTraindataPdfDir = config["pathToCreateTrainDataFolder"]
        self.__createTraindataXmlDir = config[
            "pathToCreateTrainDataLabelFolder"]
        self.__traindataDir = config["pathToTrainDataFolder"]
        self.__pathToFileToClassify = config["pathToClassifiactionImage"]
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_1.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_10.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_15.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_rest_9.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_middle_5.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_middle_7.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_elements.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_38.pdf"
        # self.__pathToFileToClassify = "./Input_Component\\Input\\clear_basic_41.pdf"

        self.__logger.info("Finished __init__()", "Input:__init__")

    def execute(self):
        """
        Führt den entsprechenden Einlesevorgang über einen Parser durch und erstellt die Bildmatrix.
        :return: mat Die Matrix des eingelesenen Bildes
        """
        self.__logger.info("Starting execute()", "Input:execute")

        filename, file_extension = os.path.splitext(
            self.__pathToFileToClassify)
        if file_extension == ".pdf":
            self.__logger.info("File is detected as PDF.", "Input:execute")
            self.__matParser = PdfToMatParser(self.__pathToFileToClassify)
        else:
            self.__logger.info("File looks like an image-datatype.",
                               "Input:execute")
            self.__matParser = PngToMatParser(self.__pathToFileToClassify)

        mat = self.__matParser.parseToMat()

        self.__logger.info("Readed following Image:", "Input:execute", mat)
        self.__logger.info("Finished execute()", "Input:execute")
        return mat

    def readNextImgXMLPair(self):
        """
        Führt den entsprechenden Einlesevorgang für die nächsten Files im Ordner
        über einen Parser durch und erstellt die Bildmatrix sowie das Lable.
        :return: mat Die Matrix des eingelesenen Bildes.
        :return: lable Das Lable zur Bildmatrix.
        """
        self.__logger.info("Starting readNextImgXMLPair()",
                           "Input:readNextImgXMLPair")

        # Falls es der erste Schritt ist, Filenamen einlesen
        if not self.__matXMLPairCounter:
            self.__matFileNamesForTestDataCreation = glob.glob(
                self.__createTraindataPdfDir + "*.pdf")
            self.__xmlFileNamesForTestDataCreation = glob.glob(
                self.__createTraindataXmlDir + "*.xml")
            self.__logger.info(
                "Found following files to create testdata:" +
                str(self.__matFileNamesForTestDataCreation) +
                str(self.__xmlFileNamesForTestDataCreation),
                "Input:readNextImgXMLPair")

        # Falls es der letzte Schritt ist, Counter zurücksetzen
        if (self.__matXMLPairCounter >= self.__matFileNamesForTestDataCreation.__len__()) \
                or (self.__matXMLPairCounter > self.__xmlFileNamesForTestDataCreation.__len__()):
            self.__logger.debug(
                "Max Filecount reached: reset matXMLPairCounter to 0",
                "Input:readNextImgXMLPair")
            self.__matXMLPairCounter = 0
            return None, None

        # Lese Mat und Lable und erhöhe Counter
        self.__matParser = PdfToMatParser(
            self.__matFileNamesForTestDataCreation[self.__matXMLPairCounter])
        # test with png:
        # self.__matParser = PngToMatParser(self.__pathToFileToClassify)
        self.__lableParser = XmlToLableParser(
            self.__xmlFileNamesForTestDataCreation[self.__matXMLPairCounter])
        mat = self.__matParser.parseToMat()
        lable = self.__lableParser.parseToLable()

        self.__matXMLPairCounter = self.__matXMLPairCounter + 1

        self.__logger.info("Finished readNextImgXMLPair()",
                           "Input:readNextImgXMLPair")
        return mat, lable

    def readNoteTrainData(self):
        """
        Führt den entsprechenden Einlesevorgang für einen Ordner über einen Parser durch und gibt die
        Notentrainingsdaten mit ihrem Label zurück.
        :return: matArray Die MAtrizen des eingelesenen Bildes.
        :return: lableArray Die Lable zu den Bildmatrizen.
        """
        self.__logger.info("Starting readNoteTrainData()",
                           "Input:readNoteTrainData")

        # Reading Filenames from traindata dir
        fileNames = glob.glob(self.__traindataDir + "*.png")

        matArray = []
        lableArray = []

        # For each Testdate Parse Mat and Lable
        for fileName in fileNames:
            # Prepare LableString for Parser
            name = fileName.split("\\")[-1]
            name = name.split(".")[0]
            lableArray = lableArray + FilenameToLableParser(
                name).parseToLable()
            matArray.append(PngToMatParser(fileName).parseToMat())
        self.__logger.info("Finished readNoteTrainData()",
                           "Input:readNoteTrainData")
        return matArray, lableArray