コード例 #1
0
    output_op = db.sinks.FrameColumn(columns={'image': encoded_image})

    job = Job(
        op_args={
            encoded_image: {
                'paths': image_files,
                **params
            },
            output_op: 'edge_detect',
        })

    [_out_table] = db.run(output_op, [job],
                          force=True,
                          tasks_in_queue_per_pu=1)
    print(db.summarize())

    encoded_image = db.sources.FrameColumn()
    frame = db.ops.ImageDecoder(img=encoded_image)

    my_edge_detection_class = db.ops.EdgeDetection(frame=frame,
                                                   model_path='model.yml.gz')
    output_op = db.sinks.FrameColumn(
        columns={'frame': my_edge_detection_class})

    job = Job(
        op_args={
            encoded_image: db.table('edge_detect').column('image'),
            output_op: 'edge_output',
        })
コード例 #2
0
ファイル: 00_basic.py プロジェクト: sjoerdapp/scanner
def main():
    # Initialize a connection to the Scanner database. Loads configuration from the
    # ~/.scanner.toml configuration file.
    db = Database()

    # Create a Scanner table from our video in the format (table name,
    # video path). If any videos fail to ingest, they'll show up in the failed
    # list. If force is true, it will overwrite existing tables of the same
    # name.
    example_video_path = util.download_video()
    _, failed = db.ingest_videos([('example', example_video_path),
                                  ('example2', example_video_path),
                                  ('thisshouldfail', 'thisshouldfail.mp4')],
                                 force=True)

    print(db.summarize())
    print('Failures:', failed)

    # Scanner processes videos by forming a graph of operations that operate
    # on input frames from a table and produce outputs to a new table.

    # FrameColumn declares that we want to read from a table column that
    # represents a video frame.
    frame = db.sources.FrameColumn()

    # These frames are input into a Histogram op that computes a color histogram
    # for each frame.
    hist = db.ops.Histogram(frame=frame)

    # Finally, any columns provided to Output will be saved to the output
    # table at the end of the computation. Here, 'hist' is the name of the
    # column for the output table.
    output_op = db.sinks.Column(columns={'hist': hist})

    # A job defines a table you want to create. In op_args, we bind the
    # FrameColumn from above to the table we want to read from and name
    # the output table 'example_hist' by binding a string to output_op.
    job = Job(op_args={
        frame: db.table('example').column('frame'),
        output_op: 'example_hist'
    })

    job2 = Job(op_args={
        frame: db.table('example2').column('frame'),
        output_op: 'example_hist2'
    })

    # This executes the job and produces the output table. You'll see a progress
    # bar while Scanner is computing the outputs.
    output_tables = db.run(output=output_op, jobs=[job, job2], force=True)

    # Load the histograms from a column of the output table. The
    # readers.histograms function converts the raw bytes output by Scanner
    # into a numpy array for each channel.
    video_hists = output_tables[0].column('hist').load(readers.histograms)

    # Loop over the column's values, a set of 3 histograms (for each color channel) per element.
    num_rows = 0
    for frame_hists in video_hists:
        assert len(frame_hists) == 3
        assert frame_hists[0].shape[0] == 16
        num_rows += 1
    assert num_rows == db.table('example').num_rows()