繁体   English   中英

命令行中的Openbr python包装器

[英]Openbr python wrapper from command line

我正在尝试从命令行执行此文件test.py:

from brpy import init_brpy
import requests # or whatever http request lib you prefer
import MagicalImageURLGenerator # made up



# br_loc is /usr/local/lib by default,
# you may change this by passing a different path to the shared objects

br = init_brpy(br_loc='/path/to/libopenbr')
br.br_initialize_default()
br.br_set_property('algorithm','CatFaceRecognitionModel') # also made up
br.br_set_property('enrollAll','true')

mycatsimg = open('mycats.jpg', 'rb').read() # cat picture not provided =^..^=
mycatstmpl = br.br_load_img(mycatsimg, len(mycatsimg))
query = br.br_enroll_template(mycatstmpl)
nqueries = br.br_num_templates(query)

scores = []
for imurl in MagicalImageURLGenerator():
# load and enroll image from URL
img = requests.get(imurl).content
tmpl = br.br_load_img(img, len(img))
targets = br.br_enroll_template(tmpl)
ntargets = br.br_num_templates(targets)

# compare and collect scores
scoresmat = br.br_compare_template_lists(targets, query)
for r in range(ntargets):
    for c in range(nqueries):
        scores.append((imurl, br.br_get_matrix_output_at(scoresmat, r, c)))

# clean up - no memory leaks
br.br_free_template(tmpl)
br.br_free_template_list(targets)

# print top 10 match URLs
scores.sort(key=lambda s: s[1])

for s in scores[:10]:
print(s[0])

# clean up - no memory leaks
br.br_free_template(mycatstmpl)
br.br_free_template_list(query)
br.br_finalize()

该脚本文件为/ myfolder /,而库brpy位于/ myfolder / scripts / brpy中。

brpy文件夹包含3个文件:“ face_cluster_viz.py”,“ html_viz.py”和“ init .py”。

当我尝试从cmd执行此文件时,显示错误:

NameError; 名称'init_brpy'未定义

为什么? 我在哪里做错了? 是否可以从命令行执行此脚本?

谢谢

问题是以下行:

br = init_brpy(br_loc='/path/to/libopenbr')

您必须设置openbr库的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM