从命令行打开python包装器



我试图从命令行执行这个文件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文件夹包含三个文件:"face_cluster_viz.py", "html_viz.py"one_answers"init.py"。

当我尝试从cmd执行这个文件时,它显示一个错误:

NameError;名称"init_brpy"未定义

为什么?我哪里做错了?有可能从命令行执行这个脚本吗?

谢谢

问题出在下面一行:

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

你必须设置openbr库的路径

相关内容

  • 没有找到相关文章

最新更新