Exemplo n.º 1
0
def inventoryshape(classdir):
    filecount = len(glob(classdir + "/*.jpg"))
    print('determining optimal image resolution...')
    db = Base('shape', save_to_file=False)
    db.create('filename', 'height', 'width', 'count')
    index = 0
    for imagePath in glob(classdir + "/*.jpg"):
        index = index + 1
        try:
            img = cv2.imread(imagePath)
            filename = os.path.basename(imagePath)
            shape = img.shape
            h = shape[0]
            w = shape[1]
            pre = db(height=h, width=w)
            # see if there is already an image of this shape in the DB...
            if pre:
                # ...if so - update the count
                rec_id = pre[0]['__id__']
                counter = int(pre[0]['count'])
                counter = counter + 1
                record = db[rec_id]
                db.update(record, count=counter)
            else:
                # ...if not - insert the new shape
                db.insert(filename=filename, height=h, width=w, count=1)
            sys.stdout.write("reading shape for image #{} of {} \r".format(
                index, filecount))
            sys.stdout.flush()
            time.sleep(0.1)
        except Exception, e:
            print('error processing image {}: {}'.format(imagePath, e))
            continue
Exemplo n.º 2
0
def pydblite():
    from pydblite.pydblite import Base
    db = Base('dummy', save_to_file=False)
    # create new base with field names
    db.create('name', 'age', 'size')
    # insert new record
    db.insert(name='homer', age=23, size=1.84)
    # records are dictionaries with a unique integer key __id__
    # simple selection by field value
    records = db(name="homer")
    # complex selection by list comprehension
    res = [r for r in db if 30 > r['age'] >= 18 and r['size'] < 2]
    print("res:", res)
    # delete a record or a list of records
    r = records[0]
    db.delete(r)

    list_of_records = []
    r = db.insert(name='homer', age=23, size=1.84)
    list_of_records.append(db[r])
    r = db.insert(name='marge', age=36, size=1.94)
    list_of_records.append(db[r])

    # or generator expression
    for r in (r for r in db if r['name'] in ('homer', 'marge')):
        # print "record:", r
        pass

    db.delete(list_of_records)

    rec_id = db.insert(name='Bart', age=15, size=1.34)
    record = db[rec_id]  # the record such that record['__id__'] == rec_id

    # delete a record by its id
    del db[rec_id]

    # create an index on a field
    db.create_index('age')
    # update
    rec_id = db.insert(name='Lisa', age=13, size=1.24)

    # direct access by id
    record = db[rec_id]

    db.update(record, age=24)
    # add and drop fields
    db.add_field('new_field', default=0)
    db.drop_field('name')
    # save changes on disk
    db.commit()
Exemplo n.º 3
0
def pydblite():
    from pydblite.pydblite import Base
    db = Base('dummy', save_to_file=False)
    # create new base with field names
    db.create('name', 'age', 'size')
    # insert new record
    db.insert(name='homer', age=23, size=1.84)
    # records are dictionaries with a unique integer key __id__
    # simple selection by field value
    records = db(name="homer")
    # complex selection by list comprehension
    res = [r for r in db if 30 > r['age'] >= 18 and r['size'] < 2]
    print "res:", res
    # delete a record or a list of records
    r = records[0]
    db.delete(r)

    list_of_records = []
    r = db.insert(name='homer', age=23, size=1.84)
    list_of_records.append(db[r])
    r = db.insert(name='marge', age=36, size=1.94)
    list_of_records.append(db[r])

    # or generator expression
    for r in (r for r in db if r['name'] in ('homer', 'marge')):
        # print "record:", r
        pass

    db.delete(list_of_records)

    rec_id = db.insert(name='Bart', age=15, size=1.34)
    record = db[rec_id]  # the record such that record['__id__'] == rec_id

    # delete a record by its id
    del db[rec_id]

    # create an index on a field
    db.create_index('age')
    # update
    rec_id = db.insert(name='Lisa', age=13, size=1.24)

    # direct access by id
    record = db[rec_id]

    db.update(record, age=24)
    # add and drop fields
    db.add_field('new_field', default=0)
    db.drop_field('name')
    # save changes on disk
    db.commit()