示例#1
0
    key = cv2.waitKey(1) & 0xFF
    if key == ord(' '):
        if len(rects) > 0:
            face = frame[rects[0][1]:rects[0][1] + rects[0][3],
                         rects[0][0]:rects[0][0] + rects[0][2]]
            box = [(rects[0][1], rects[0][0] + rects[0][2],
                    rects[0][1] + rects[0][3], rects[0][0])]
            encoding = face_recognition.face_encodings(rgb, box)[0]
            elist = encoding.tolist()

            faces = w.get(args['prefix'] + '/vectors/**')
            counter = 0
            for face in faces:
                chunks = face.path.split('/')
                name = chunks[-2]
                if name == args['name']:
                    if counter <= int(chunks[-1]):
                        counter = int(chunks[-1]) + 1

            uri = '{}/vectors/{}/{}'.format(args['prefix'], args['name'],
                                            str(counter))
            print('> Inserting face vector {}'.format(uri))
            w.put(uri, Value.Json(json.dumps(elist)))

    time.sleep(0.05)

    if key == ord('q'):
        exit(0)

z.close()
示例#2
0
faces = json.load(f)

print('[INFO] Open zenoh session...')
zenoh.init_logger()
z = Zenoh(conf)
w = z.workspace()
time.sleep(0.5)

# If not yet existing, add a memory storage that will store the dataset
try:
    storage_admin_path = '/@/router/local/plugin/storages/backend/memory/storage/facerecog-store'
    if not w.get(storage_admin_path):
        path_expr = '{}/vectors/**'.format(args['prefix'])
        print('Add storage: on {}'.format(path_expr))
        properties = {'path_expr': path_expr}
        w.put(storage_admin_path, properties)
        time.sleep(1)
except:
    e = sys.exc_info()[0]
    print('Error creating storage: {}'.format(e))

for k, vs in faces.items():
    for j, v in enumerate(vs):
        uri = '{}/vectors/{}/{}'.format(args['prefix'], k, j)
        print('> Inserting face {}'.format(uri))
        w.put(uri, Value.Json(json.dumps(v)))

z.close()

print('[INFO] Done.')