Esempio n. 1
0
 def __init__( self, image_path, env ):
     state( 'Opening image...' )
     self.env = env
     if( self.setImage( image_path ) ):
         comment( '- Image opened successfully.')
     else:
         error( 'Could not set image from path in ProcessImage.' )
 def test_state(self):
     """
         Test whether a successful state message can be made to the console.
     """
     self.assertEqual(
         state('Testing a state message').success, True,
         'A successful state message should return a success status of True.'
     )
    def __init__(self, env, feature: str, path=None):
        state('Setting up the image pipeline.')
        self._e = env

        if (path != None):
            directories = self.getDirectories(path)
            if (directories.success):
                # Inside each sample folder there are images for lines and words, which are folders.
                self.subject = ask('Would you like to use [words] or [lines]?',
                                   readInput.readline())
                while (not (self.subject.payload == 'words'
                            or self.subject.payload == 'lines')):
                    self.subject = ask('Type either [words] or [lines]?',
                                       readInput.readline())

                tmp_create_paths = self.setPaths(self.subject.payload)
                if (tmp_create_paths.success):
                    comment(tmp_create_paths.payload)
                    feature_files = self.getFeatureFiles()

                    available_features = self.getListOfAvailableFeatures()

                    comment('Adding features.')

                    for feature_class in available_features:
                        self.save(
                            self.generateFeatures(feature_files,
                                                  feature_class),
                            feature_class)

                else:
                    error(tmp_create_paths.payload)

                    raise IOError(tmp_create_paths.payload)
            else:
                error(directories.payload)
Esempio n. 4
0
        os.chdir( name )    
        count = 1

        output_file = { 'author': filename.split('-')[0], 'line_count':0, 'lines': [], 'features': [] }
        for line in lines:
            output_file[ 'lines' ].append( '{0}_{1}.tif'.format( filename, count ) )
            try:
                cv2.imwrite( '{0}_{1}.tif'.format( filename, count ), line[ 'image' ])
                count += 1
            except:
                error( f'Could not write line to {filename}_{count}.tif')
        output_file[ 'line_count' ] = count-1
        open( '{0}.json'.format( filename ), 'a' ).write( json.dumps( output_file, indent = 4, sort_keys = True ) )
        os.chdir( '..' )  

state( 'Cropping and preparing images:' )

class ImagePipeline:
    def __init__( self, env, directory, dataset ):
        self.env = env
        try:
            self.processImages( f'{directory}{dataset}/', 'tif' )
        except:
            error( 'Could not process selected dataset.' )       

    '''
        This function adds the '.' before the given extension if one is needed. After this step the getFiles() function is called and the list of files is then passed on the the extraction class. Finally the results from the extraction class is written to actual directories and files on the system.

        - ARGUMENTS
            > self: is used to read the env variable from the class.
            > dir: the directory that is searched for the relevant files.
Esempio n. 5
0
from base import console_message as out
from base.environment import Environment
from base.extract import ImagePipeline
from base.feature import FeaturePipeline
from base.image_utils import openImage, showImage

import os
import cv2
import numpy as np
from PIL import Image

out.state('Running the main application.')
e = Environment(out, os.getcwd())

if (out.confirm('Extract words from images').success):
    dataset = out.ask('What dataset would you like to use?')
    if (dataset.success):
        try:
            for key in e.paths.content.keys():
                if (key == dataset.payload):
                    ImagePipeline(e, f'{os.getcwd()}/images/', dataset.payload)
        except:
            out.error('Extracting failed')

if (out.confirm('Would you like to add a feature?').success):
    dataset = out.ask('What dataset would you like to use?')
    if (dataset.success):
        try:
            for key in e.paths.content.keys():
                if (key == dataset.payload):
                    features_pipe = FeaturePipeline(