【问题标题】:Image manipulation dlib argparse.ArgumentParser() problem?图像处理 dlib argparse.ArgumentParser() 问题?
【发布时间】:2021-01-23 23:39:16
【问题描述】:

我们正在和我的朋友一起做一个项目,但我们还没有解决一个大问题。我们尝试了很多方法,但无法解决问题。该问题与“argparse.ArgumentParser()”有关。

错误部分:

usage: detect_drowsiness.py [-h] -p SHAPE_PREDICTOR [-a ALARM] [-w WEBCAM]
detect_drowsiness.py: error: the following arguments are required: -p/--shape-predictor

代码部分:

ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,
    help="path to facial landmark predictor")
ap.add_argument("-a", "--alarm", type=str, default="",
    help="path alarm .WAV file")
ap.add_argument("-w", "--webcam", type=int, default=0,
    help="index of webcam on system")
args = vars(ap.parse_args())

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])

文件内容: shape_predictor_68_face_landmarks.dat 和 detect_drowsiness.py(文件名)

为什么会出现这个问题?

【问题讨论】:

    标签: python command-line-arguments argparse


    【解决方案1】:

    如果你注意到了,

    ap.add_argument("-p", "--shape-predictor", required=True,
        help="path to facial landmark predictor")
    

    -p/--shape-predictor 参数是必需的。因此,在运行 python 文件时应该执行以下操作:

    python detect_drowsiness.py -p shape_predictor_68_face_landmarks.dat
    

    python detect_drowsiness.py --shape-predictor shape_predictor_68_face_landmarks.dat 
    

    【讨论】:

    • 我很感谢你。谢谢.. :) 每次我想打开程序时都必须这样做。还有其他方法吗?我可以将它传递给代码或定义这个参数吗?
    猜你喜欢
    • 2016-08-11
    • 2016-08-04
    • 1970-01-01
    • 2019-05-02
    • 2019-04-26
    • 2017-12-08
    • 2021-01-17
    • 2015-11-25
    • 1970-01-01
    相关资源
    最近更新 更多