Exemple #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Usage: db_prep.py -d <data> -l <label> -n <ndim> -o <outfile>

Options:
   -h --help   show this message
"""


def parse_args():
    args = docopt(__doc__)
    data = args['<data>']
    label = args['<label>']
    ndim = int(args['<ndim>'])
    outfile = args['<outfile>']
    return data, label, ndim, outfile

if __name__ == '__main__':
    from docopt import docopt
    from numpy import load
    from mscr.bovw import BoVW

    data, label, ndim, outfile = parse_args()
    X, y = load(data), load(label)
    bbb = BoVW()
    bbb.fit(X, y, ndim)
    bbb.save_prep(outfile)
Exemple #2
0
    from docopt import docopt
    from os.path import join as pjoin
    from os.path import basename as pbase
    from mscr.util import load_gray, MyKNN, imshow, AddSuffix
    from mscr.bovw import BoVW
    from mscr.blocks import TrivialBlockIter
    from mscr.blockVote import Vote, BlockVote, Votes2Img
    from mscr.grid import Grid, GridClassifier

    imgf, model, w, h, nn, display, save = parse_args()
    img = load_gray(imgf)

    print '#-----------------------'
    print imgf

    bvw = BoVW()
    bvw.load(model)

    ubv = BlockVote(Vote(bvw), TrivialBlockIter(w, h))
    votes = ubv.run(img)

    coarse = Votes2Img(img.shape[:2]).run(votes)

    grid = GridClassifier(MyKNN(labels, nn=nn), Grid(microsize))
    grid.run(img, coarse)
    grid.finalize()
    res = grid.show()

    if display:
        imshow(res)