Ejemplo n.º 1
0
    def stitch(self):
        scribe = Scribe(self.path)
        slidegrabber = Slidegrabber(self.path)

        slides = slidegrabber.get_slides()
        scribe.scribble()
        scripts = scribe.get_papyrus()

        counter = 0

        print("Stitching timestamps together...")
        for slide_timestamp, slide_path in slides:

            slide_start, slide_end = slide_timestamp[0], slide_timestamp[1]

            script = list()

            while (counter < len(scripts)
                   and scripts[counter][0][0] < slide_end):
                # append a list of strings
                script.append(scripts[counter][1])
                counter += 1

            timestamp = (slide_start, slide_end)
            self.quilt.append(Patch(timestamp, slide_path, script))
Ejemplo n.º 2
0
    def testReadingEvent(self):
        q = MockQueue()
        s = Scribe(q, self.config)
        e = TemperatureSummaryEvent(1, 22, 60)
        s.processEvent(e)

        e = HeaterStatusEvent("on")
        s.processEvent(e)
Ejemplo n.º 3
0
 def getScribe(self, chat):
     cid = str(chat.id)
     if cid not in self.scriptorium:
         scribe = Scribe.FromChat(chat, self.archivist, newchat=True)
         self.scriptorium[cid] = scribe
         return scribe
     else:
         return self.scriptorium[cid]
Ejemplo n.º 4
0
 def recall(self, filename):
     # print("Loading chat: " + path)
     file = open(self.chatdir + filename, "rb")
     scribe = None
     try:
         scribe = Scribe.Recall(pickle.load(file), self)
         self.logger.info("Unpickled {}{}".format(self.chatdir, filename))
     except pickle.UnpicklingError:
         file.close()
         file = open(self.chatdir + filename, "r")
         try:
             scribe = Scribe.Recall(file.read(), self)
             self.logger.info("Read {}{} text file".format(
                 self.chatdir, filename))
         except Exception as e:
             self.logger.error("Failed reading {}{}".format(
                 self.chatdir, filename))
             self.logger.exception(e)
             raise e
     file.close()
     return scribe
Ejemplo n.º 5
0
    output_fname = '-'.join(sorted(sys.argv[1:]))
    output_fname = output_fname.replace('.ast', '').replace('/', '').replace('configs', '')
else:
    output_fname = "default"
network_fname = '{}.pkl'.format(output_fname)
output_fname += '_' + dt.now().strftime('%y%m%d_%H%M') + '.txt'
distances, wts = [], []
print("Output will be written to: ", output_fname)

# Initialize Language
lang.select_labeler(args['labeler'])
alphabet_size = len(lang.symbols)

# Initialize Scriber
scribe_args['dtype'] = th.config.floatX
scriber = Scribe(lang, **scribe_args)
printer = utils.Printer(lang.symbols)

sys.setrecursionlimit(1000000)

# Initialize the Neural Network
if os.path.exists(network_fname):
    print('Loading existing network file')
    with open(network_fname, 'rb') as fh:
        ntwk = pickle.load(fh)
else:
    print('Building the Network')
    ntwk = nn.NeuralNet(scriber.height, alphabet_size, **nnet_args)
    with open(network_fname, 'wb') as fh:
        pickle.dump(ntwk, fh)
Ejemplo n.º 6
0
    return im.fromarray((255 * (1 - arr)).astype("uint8"))


options = {
    'size': 24,
    'maxangle': 0,
    'dtype': 'float32',
    'vbuffer': 0,
    'noise': 0.05,
    'hbuffer': 5,
    'nchars_per_sample': 1,
    'height': 45
}
alphabet_size = len(telugu.symbols)

scriber = Scribe(language=telugu, **options)

if len(sys.argv) > 1:
    target_dir = sys.argv[1]
    samples = int(sys.argv[2])
else:
    samples = 100
    target_dir = 'data'

print(samples, target_dir)

try:
    os.makedirs(target_dir)
except FileExistsError:
    pass
Ejemplo n.º 7
0
###########################################################################

out_file_name = args.output_name
out_file_name += ".pkl" if not out_file_name.endswith(".pkl") else ""

if args.alphabet == "ascii":
    alphabet = ascii_alphabet
else:
    alphabet = hindu_alphabet

print(alphabet)
scribe = Scribe(
    alphabet=alphabet,
    noise=args.noise,
    vbuffer=args.vbuffer,
    hbuffer=args.hbuffer,
    avg_seq_len=args.avg_seq_len,
    varying_len=args.varying_len,
    nchars=args.nchars,
)


# inputs = ocrolib.glob_all(['/media/onina/SSD/fhtw2016/contestHTRtS/BenthamData/1stBatch/Images/Lines/*.png'])
# training_examples = []
# training_examples2 = [ word.strip() for word in open('dictionary.txt') ]
# charset = sorted(list(set(list(ocrolib.lstm.ascii_labels) + list(ocrolib.chars.default))))
# charset = [""," ","~",]+[c for c in charset if c not in [" ","~"]]
# print("# charset size",len(charset))
#
# if len(charset)<200:
#     print( "["+"".join(charset)+"]")
Ejemplo n.º 8
0
    return im.fromarray((255 * (1 - arr)).astype("uint8"))


options = {
    'size': 24,
    'maxangle': 0,
    'dtype': 'float32',
    'vbuffer': 0,
    'noise': 0.05,
    'hbuffer': 5,
    'nchars_per_sample': 30,
    'height': 45
}
alphabet_size = len(telugu.symbols)

scriber = Scribe(language=telugu, **options)

if len(sys.argv) > 1:
    target_dir = sys.argv[1]
    samples = int(sys.argv[2])
else:
    samples = 1000
    target_dir = '../data/train/3/'

print(samples, target_dir)

try:
    os.makedirs(target_dir)
except FileExistsError:
    pass
Ejemplo n.º 9
0
 def wakeScribe(self, filepath):
     file = open(filepath.format(filename="card", ext=".txt"), "r")
     card = file.read()
     file.close()
     return Scribe.FromFile(card, self)
Ejemplo n.º 10
0
if len(sys.argv) > 1:
    output_fname = '-'.join(sorted(sys.argv[1:]))
    output_fname = output_fname.replace('.ast', '').replace('/', '').replace('configs', '')
else:
    output_fname = "default"
output_fname += '_' + dt.now().strftime('%y%m%d_%H%M') + '.txt'
distances, wts = [], []
print("Output will be written to: ", output_fname)

# Initialize Language
lang.select_labeler(args['labeler'])
alphabet_size = len(lang.symbols)

# Initialize Scriber
scribe_args['dtype'] = th.config.floatX
scriber = Scribe(lang, **scribe_args)
printer = utils.Printer(lang.symbols)

# Initialize the Neural Network
print('Building the Network')
ntwk = nn.NeuralNet(scriber.height, alphabet_size, **nnet_args)

# Print
print('\nArguments:')
utils.write_dict(args)
print('FloatX: {}'.format(th.config.floatX))
print('Alphabet Size: {}'.format(alphabet_size))

################################ Train
print('Training the Network')
for epoch in range(num_epochs):
Ejemplo n.º 11
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c",
                        "--config",
                        dest="filename",
                        help="load configuration file",
                        required=True)
    config_filename = parser.parse_args().filename
    config = Configuration(config_filename)
    logging.basicConfig(filename=config.logging_path,
                        level=config.logging_level)
    logger = logging.getLogger('SpeedTrap')
    logger.info("SpeedTrap Starting")
    logger.info("Configuration file successfully loaded")
    logger.debug("%s", config)
    if config.clear_local_on_start:
        LocalTools.clean_local(config)
    # log_speed = LogSpeed(config)
    execute_loop = True
    radar = Radar(config)

    # Create pipes for inter-process communication
    video_queue = Queue()  # Video Ring Buffer

    logger.debug("Starting video capture Process")
    capture_video = CaptureVideo(config)
    capture_parent, capture_child = Pipe()
    capture_speed_parent, capture_speed_child = Pipe()
    capture_process = Process(target=capture_video.capture,
                              args=(capture_child, capture_speed_child,
                                    video_queue))
    capture_process.start()
    logger.info("Video capture Process started")

    logger.debug("Starting video record Process")
    record_video = RecordVideo(config)
    record_parent, record_child = Pipe()
    record_process = Process(target=record_video.record,
                             args=(record_child, video_queue))
    record_process.start()
    logger.info("Video record Process started")

    logger.debug("Starting scribe Process")
    data_recorder = Scribe(config)
    data_parent, data_child = Pipe()
    data_process = Process(target=data_recorder.capture, args=(data_child, ))
    data_process.start()
    logger.info("Scribe Process started")

    # Tracking if we are currently recording so we don't accidentally create a race condition
    recording = False
    speed = 0
    logger.debug("Starting radar polling loop")
    while execute_loop:
        try:
            if record_parent.poll():
                record_result = record_parent.recv()
                logger.debug("Message received on record_parent Pipe()")
                if type(record_result) is SpeedRecord:
                    logger.debug("Received message is a SpeedRecord")
                    logger.debug("Sending message on data_parent Pipe()")
                    data_parent.send(record_result)  # Log Data
                    # Change the behavior of the capture process back to its default.
                    recording = False
                    capture_parent.send(0)
            current_report = radar.read_serial_buffer()
            if len(current_report) > 0:
                try:
                    current_report_json = json.loads(current_report)
                    speed = abs(float(current_report_json['speed']))
                except:
                    pass
            else:
                speed = 0
            logger.debug("Current speed is %s", speed)
            logger.debug(
                "Sending message of %s to capture_speed_parent Pipe()", speed)
            capture_speed_parent.send(speed)
            if speed > config.record_threshold and recording is False:
                recording = True
                # Change the behavior of the video capture and recording process to record mode
                logger.debug("Sending message of 1 to capture_parent Pipe()")
                capture_parent.send(1)
                logger.debug("Sending message of 1 to record_parent Pipe()")
                record_parent.send(1)
        except KeyboardInterrupt:
            execute_loop = False
    logger.info("SpeedTrap Terminating")