Beispiel #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))
Beispiel #2
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)
    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
Beispiel #4
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")