Exemplo n.º 1
0
def LoadTextures():

    imagesDirectory = "Images\\Textures"
    trainImages = []
    testImages = []

    for directoryName in os.listdir(imagesDirectory):

        subDirectory = os.path.join(imagesDirectory, directoryName)
        if ("train" in directoryName):

            for trainSubdirectory in os.listdir(subDirectory):

                subDirectory2 = os.path.join(subDirectory, trainSubdirectory)
                trainLabel = trainSubdirectory

                for trainObject in os.listdir(subDirectory2):
                    fullFilePath = os.path.join(subDirectory2, trainObject)
                    trainImages.append(ImObj.ImageData(trainLabel, imagePath=fullFilePath))

        elif ("test" in directoryName):

            for testObject in os.listdir(subDirectory):

                fullFilePath = os.path.join(subDirectory, testObject)
                testImages.append(ImObj.ImageData(testObject, imagePath=fullFilePath))

    return (trainImages, testImages)
Exemplo n.º 2
0
def LoadNumbersImages():
    numbersImagesDirectory = "Images\\NumberImages"

    for filename in os.listdir(numbersImagesDirectory):

        if ("." in filename):
            oldFileName = os.path.join(numbersImagesDirectory, filename)
            newFileName = oldFileName.replace(".", "-")

            os.rename(oldFileName, newFileName)

    mndata = MNIST(numbersImagesDirectory)
    trainImages, trainLabels = mndata.load_training()
    testImages, testLabels = mndata.load_testing()

    trainImageObjects = []
    testImageObjects = []

    for image, label in zip(trainImages, trainLabels):
        trainImageObjects.append(ImObj.ImageData(label, image=image))
        # ImObj.ImageData.image

    for image, label in zip(testImages, testLabels):
        testImageObjects.append(ImObj.ImageData(label, image=image))

    # Wyswietla 10 element zbioru
    # print(mndata.display(trainImages[10]))

    return (trainImageObjects, testImageObjects)
Exemplo n.º 3
0
    def updateTowerScales(self):
        '''
        This method updates the vars holding the scales and distance from camera of the object.
        :return: None
        '''

        boundingRect = self.calculateBoundingRect()
        if boundingRect is not None:
            (x, y, w, h) = boundingRect
            if self.currentImageObject is None:
                DFC = self.distanceHelper.getDistanceFromTower(
                    h, self.robotObject, self.TOWER_HEIGHT)
                self.currentImageObject = ImageObject(w, h, x, y, DFC)
            else:
                DFC = self.distanceHelper.getDistanceFromTower(
                    h, self.robotObject, self.TOWER_HEIGHT)
                self.currentImageObject.objectHeight = h
                self.currentImageObject.objectWidth = w
                self.currentImageObject.objectX = x
                self.currentImageObject.objectY = y
                self.currentImageObject.distanceFromCamera = DFC

                azimuthalAngle = self.distanceHelper.getAzimuthalAngle(
                    [self.imageWidth, self.imageHeight],
                    self.currentImageObject, self.HAX)
                polarAngle = self.distanceHelper.getPolarAngle(
                    [self.imageWidth, self.imageHeight],
                    self.currentImageObject, self.HAY)
                self.currentImageObject.azimathalAngle = azimuthalAngle
                self.currentImageObject.polarAngle = polarAngle

            self.currentImageObject.didUpdateVar = True
Exemplo n.º 4
0
def detect_dir(sourceDirectory, outputDirectory, blockSize=32):
    """
    Detects all images under a directory
    :param sourceDirectory: directory that contains images to be detected
    :param outputDirectory: output directory
    :param blockSize: the block size of the image pointer (eg. 32, 64, 128)
    The smaller the block size, the more accurate the result is, but takes more time, vice versa.
    :return: None
    """

    timeStamp = time.strftime("%Y%m%d_%H%M%S")  # get current timestamp
    os.makedirs(outputDirectory +
                timeStamp)  # create a folder named as the current timestamp

    if not os.path.exists(sourceDirectory):
        print "Error: Source Directory did not exist."
        return
    elif not os.path.exists(outputDirectory):
        print "Error: Output Directory did not exist."
        return

    for fileName in os.listdir(sourceDirectory):
        anImage = ImageObject.ImageObject(sourceDirectory, fileName, blockSize,
                                          outputDirectory + timeStamp + '/')
        anImage.run()

    print "Done."
Exemplo n.º 5
0
def detect(sourceDirectory, fileName, outputDirectory, blockSize=32):
    """
    Detects an image under a specific directory
    :param sourceDirectory: directory that contains images to be detected
    :param fileName: name of the image file to be detected
    :param outputDirectory: output directory
    :param blockSize: the block size of the image pointer (eg. 32, 64, 128)
    The smaller the block size, the more accurate the result is, but takes more time, vice versa.
    :return: None
    """

    if not os.path.exists(sourceDirectory):
        print "Error: Source Directory did not exist."
        return
    elif not os.path.exists(sourceDirectory + fileName):
        print "Error: Image file did not exist."
        return
    elif not os.path.exists(outputDirectory):
        print "Error: Output Directory did not exist."
        return

    singleImage = ImageObject.ImageObject(sourceDirectory, fileName, blockSize,
                                          outputDirectory)
    imageResultPath = singleImage.run()

    print "Done."
    return imageResultPath
Exemplo n.º 6
0
def detect(imagefilename, blockSize=32):
    """
    Detects an image under a specific directory
    :param sourceDirectory: directory that contains images to be detected
    :param fileName: name of the image file to be detected
    :param outputDirectory: output directory
    :param blockSize: the block size of the image pointer (eg. 32, 64, 128)
    The smaller the block size, the more accurate the result is, but takes more time, vice versa.
    :return: None
    """

    singleImage = ImageObject.ImageObject(imagefilename, blockSize)
    status = singleImage.run()

    print "Image checked for copy-move editings."
    return status
Exemplo n.º 7
0
def detect(sourceDir, fileName, destinationDir, blockSize=32):
    """
    Fungsi untuk melakukan deteksi copy-move pada satu citra
    :param sourceDir: direktori citra
    :param filename: nama citra
    :param destinationDir: direktori hasil
    :param blockSize: ukuran blok citra (misal 32, 64, 128)
    :return: None
    """
    if not os.path.exists(sourceDir):
        print "Error: Direktori masukan salah."
        return
    elif not os.path.exists(sourceDir+fileName):
        print "Error: Nama file salah."
        return
    elif not os.path.exists(destinationDir):
        print "Error: Direktori keluaran salah."
        return


    singleImage = ImageObject.ImageObject(sourceDir, fileName, blockSize, destinationDir)
    imageResultPath = singleImage.run()
    print "Selesai."
    return imageResultPath
Exemplo n.º 8
0
def detect_dir(sourceDir, destinationDir, blockSize=32):
    """
    Fungsi untuk melakukan deteksi copy-move pada semua citra yang berada di sebuah direktori
    :param sourceDir: direktori masukan
    :param destinationDir: direktori keluaran
    :param blockSize: ukuran block citra (misal 32, 64, 128)
    :return: None
    """

    timestr = time.strftime("%Y%m%d_%H%M%S")
    os.makedirs(destinationDir+timestr)

    if not os.path.exists(sourceDir):
        print "Error: Direktori masukan salah."
        return
    elif not os.path.exists(destinationDir):
        print "Error: Direktori keluaran salah."
        return

    for filename in os.listdir(sourceDir):
        singleImage = ImageObject.ImageObject(sourceDir, filename, blockSize, destinationDir+timestr+'/')
        singleImage.run()

    print "Selesai."