【发布时间】:2020-08-31 20:11:50
【问题描述】:
我有以下从命令行获取输入的代码。我想在 streamlit 中运行此代码,而不是从命令行获取参数的值,而是将它们设置为一些默认值,例如“-i”,我希望它默认打开相机。我怎样才能做到这一点?
def build_argparser():
parser = ArgumentParser()
general = parser.add_argument_group('General')
general.add_argument('-i', '--input', metavar="PATH", default='0',
help="(optional) Path to the input video " \
"('0' for the camera, default)")
general.add_argument('-o', '--output', metavar="PATH", default="",
help="(optional) Path to save the output video to")
general.add_argument('--no_show', action='store_true',
help="(optional) Do not display output")
general.add_argument('-tl', '--timelapse', action='store_true',
help="(optional) Auto-pause after each frame")
general.add_argument('-cw', '--crop_width', default=0, type=int,
help="(optional) Crop the input stream to this width " \
"(default: no crop). Both -cw and -ch parameters " \
"should be specified to use crop.")
general.add_argument('-ch', '--crop_height', default=0, type=int,
help="(optional) Crop the input stream to this height " \
"(default: no crop). Both -cw and -ch parameters " \
"should be specified to use crop.")
general.add_argument('--match_algo', default='HUNGARIAN', choices=MATCH_ALGO,
help="(optional)algorithm for face matching(default: %(default)s)")
【问题讨论】:
-
您是只想运行脚本名称而没有其他内容,还是希望在运行脚本时指定标志并希望这些标志默认运行某些操作?
-
我不想在运行脚本时指定标志。我想默认设置所有的标志。
-
如果您不需要任何命令行参数,则不要使用任何命令行参数。只需在脚本中定义所有路径和引用。另外,如果您使用的是相机,请查看 opencv 库,它可以帮助您运行和更改视频帧。
标签: python command-line-arguments streamlit