示例#1
0
    #################################################
    allFiles = next(os.walk("../TrainingSet/Offline Forgeries"))[1]

    dataToTrain = {}

    for files in allFiles:
        folderFiles = next(os.walk("../TrainingSet/Offline Forgeries/" +
                                   files))[2]

        for signature in folderFiles:

            img = rz.resizeSignature("../TrainingSet/Offline Forgeries/" +
                                     files + "/" + signature)
            # Image filtering
            imgSmooted = GaussS.gaussianBlur(1, 0.55, img)
            imgFiltered = bN.filter(imgSmooted)

            # Calculate the ones in the matrix.
            blackPoints = bN.calculateBlackPoints(imgFiltered)

            # Calculate the center of mass
            centerMass = bN.centroid(blackPoints)

            # Calculate the eccentricity
            eccentricity = bN.calculateEccentricity(blackPoints)

            # Calculate the representative points of a signature
            # densePoints = bN.calculateDensePoints(blackPoints)

            # Calculate Kurtosis of blackpoints in signature
            kurtosis = bN.calculateKurtosis(blackPoints)
示例#2
0
    def loadImage(self):
        bashCommand = "rm test.PNG"
        import subprocess
        process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
        output, error = process.communicate()
        print output

        # first of all, the base transformation of the data points is needed
        base = plt.gca().transData
        rot = transforms.Affine2D().rotate_deg(270)

        filename = askopenfilename()
        img = rz.resizeSignature(filename)

        # Image filtering
        imgSmooted = GaussS.gaussianBlur(1, 0.5, img)
        imgFiltered = bN.filter(imgSmooted)

        # Calculate the ones in the matrix.
        blackPoints = bN.calculateBlackPoints(imgFiltered)

        # Calculate the center of mass
        centerMass = bN.centroid(blackPoints)
        self.CenterMass.setText(str(centerMass[1]))
        self.CenterMass_2.setText(str(centerMass[0]))

        # Calculate the eccentricity
        eccentricity = bN.calculateEccentricity(blackPoints)
        self.Eccentricity.setText(str(round(eccentricity,4)))

        # Calculate the representative points of a signature
        densePoints = bN.calculateDensePoints(blackPoints)
        listY = [y[0] for y in blackPoints]
        listX = [x[1] for x in blackPoints]
        plt.plot(listY, listX, "ro", transform=rot + base)

        # Print Center of mass
        plt.plot(centerMass[0], centerMass[1], "^", transform=rot + base)

        # Print dense points
        densePoints = densePoints.T
        plt.plot(densePoints[0], densePoints[1], "g+", transform=rot + base)

        kurtosis = bN.calculateKurtosis(blackPoints)
        self.kurtosis.setText(str(round(kurtosis[1], 4 )))
        self.kurtosis_2.setText(str(round(kurtosis[0], 4)))

        # Print skew detection
        testSkew = bN.skewDetection(imgFiltered)
        self.Skew.setText(str(round(testSkew)))

        # Calculate gradient in a grid 4x4 - Choosen just 2x2 important grid in the middle
        matrixGradient = bN.calculateGradient(blackPoints, imgFiltered.shape)
        self.Gradient.setRowCount(len(matrixGradient))
        self.Gradient.setColumnCount(len(matrixGradient[0]))
        for i, row in enumerate(matrixGradient):
            for j, val in enumerate(row):
                self.Gradient.setItem(i, j, QtGui.QTableWidgetItem(str(val)))

        self.Gradient.resizeColumnsToContents()
        self.Gradient.resizeRowsToContents()


        # Calculate pressure in a grid 4x4
        matrixPresure = np.around(bN.calculatePressure(imgSmooted), decimals=2)
        self.Presure.setRowCount(len(matrixPresure))
        self.Presure.setColumnCount(len(matrixPresure[0]))
        for i, row in enumerate(matrixPresure):
            for j, val in enumerate(row):
                self.Presure.setItem(i, j, QtGui.QTableWidgetItem(str(val)))

        self.Presure.resizeColumnsToContents()
        self.Presure.resizeRowsToContents()

        plt.axis('off')

        # Plot Ellipse
        subplot = plt.subplot()
        b, a = drawEllipse(blackPoints)
        ell = Ellipse((centerMass[1], centerMass[0] * -1), b + 10, a + 10, edgecolor='black', facecolor='none',
                      linewidth=5)
        subplot.add_patch(ell)

        # plt.plot([y positions of the points], [x positions of the points])
        # plt.plot([testSkewLeft[1], testSkewRight[1]], [testSkewLeft[0], testSkewRight[0]], 'k')
        # plt.plot([testSkewLeft[1], testSkewLeft[1]], [testSkewLeft[0], testSkewRight[0]], 'k')
        # Save Scanned Signature
        plt.savefig("test.PNG", dpi=700)
        plt.close()

        ############################################
        # Signature image
        ############################################
        logoPic1 = QPixmap(filename)
        self.signature.setPixmap(logoPic1.scaled(291,255,Qt.KeepAspectRatio))
        self.signature.show()

        ############################################
        # Signature Feature
        ############################################

        search_pixmap = QtGui.QPixmap()
        search_pixmap.load('test.PNG')
        self.featureSignature.setPixmap(search_pixmap.scaled(291, 255, Qt.KeepAspectRatio))
        self.featureSignature.show()



        ########################
        # Save test image
        ##########################
        vectorFeature = []
        vectorFeature.append(round(centerMass[0], 4))
        vectorFeature.append(round(centerMass[1], 4))
        vectorFeature.append(round(eccentricity, 4))
        vectorFeature.append(round(kurtosis[0], 4))
        vectorFeature.append(round(kurtosis[1], 4))
        vectorFeature.append(round(matrixGradient[0][0][0], 4))
        vectorFeature.append(round(matrixGradient[0][0][1], 4))
        vectorFeature.append(round(matrixGradient[0][1][0], 4))
        vectorFeature.append(round(matrixGradient[0][1][1], 4))
        vectorFeature.append(round(matrixGradient[0][2][0], 4))
        vectorFeature.append(round(matrixGradient[0][2][1], 4))
        vectorFeature.append(round(matrixGradient[0][3][0], 4))
        vectorFeature.append(round(matrixGradient[0][3][1], 4))
        vectorFeature.append(round(matrixGradient[1][0][0], 4))
        vectorFeature.append(round(matrixGradient[1][0][1], 4))
        vectorFeature.append(round(matrixGradient[1][1][0], 4))
        vectorFeature.append(round(matrixGradient[1][1][1], 4))
        vectorFeature.append(round(matrixGradient[1][2][0], 4))
        vectorFeature.append(round(matrixGradient[1][2][1], 4))
        vectorFeature.append(round(matrixGradient[1][3][0], 4))
        vectorFeature.append(round(matrixGradient[1][3][1], 4))
        vectorFeature.append(round(matrixPresure[0][0], 4))
        vectorFeature.append(round(matrixPresure[0][1], 4))
        vectorFeature.append(round(matrixPresure[0][2], 4))
        vectorFeature.append(round(matrixPresure[0][3], 4))
        vectorFeature.append(round(matrixPresure[1][0], 4))
        vectorFeature.append(round(matrixPresure[1][1], 4))
        vectorFeature.append(round(matrixPresure[1][2], 4))
        vectorFeature.append(round(matrixPresure[1][3], 4))
        vectorFeature.append(round(matrixPresure[2][0], 4))
        vectorFeature.append(round(matrixPresure[2][1], 4))
        vectorFeature.append(round(matrixPresure[2][2], 4))
        vectorFeature.append(round(matrixPresure[2][3], 4))
        vectorFeature.append(round(matrixPresure[3][0], 4))
        vectorFeature.append(round(matrixPresure[3][1], 4))
        vectorFeature.append(round( matrixPresure[3][2], 4))
        vectorFeature.append(round(matrixPresure[3][3], 4))

        label = 0
        if len(filename.split('/')[len(filename.split('/'))-1]) < 11:
            label = int(filename.split('/')[len(filename.split('/'))-2])
        # print label

        matrixData = []
        vectorTarget = []
        with open('../LearningInformation/learningBayesianMulticlassGenuine.csv') as f:
            readerGenuine = csv.reader(f)

            readerGenuine.next()
            for i in readerGenuine:
                matrixData.append(map(float, i[:len(i) - 1]))
                # matrixData.append(map(float, i[2:5] + i[25:len(i) - 1]))
                vectorTarget.append(int(i[len(i) - 1]))

        with open('../LearningInformation/learningBayesianMulticlassForgeries.csv') as f:
            readerForgeriestmp = csv.reader(f)
            readerForgeriestmp.next()
            for i in readerForgeriestmp:
                matrixData.append(map(float, i[:len(i) - 1]))
                # matrixData.append(map(float, i[2:5] + i[25:len(i) - 1]))
                vectorTarget.append(int(i[len(i) - 1]))

        matrixData = np.array(matrixData)
        vectorTarget = np.array(vectorTarget)

        asdsada = TemplateClassifier().fit(matrixData, vectorTarget)
        y_predict_X = asdsada.predict(vectorFeature)[0]

        self.realLabelText = label
        self.predicted = y_predict_X