【opencv+python探索】使用argparser报错:error: the following arguments are required: -i/--image

前方Bug预警:xxx .py: error: the following arguments are required: -i/--image

在学习opencv+python时,遇到下面这个Bug,查阅资料后终解决,现在将解决办法分享给大家。

Bug图

 

程序部分源码

ap = argparse.ArgumentParser()

ap.add_argument("-i", "--image", required=True,help="path to the input image")

args = vars(ap.parse_args())

bug:error: the following arguments are required: -i/--image

在网上也有网友出现过类似的问题:

错误分析:

需要在cmd终端或pycharm终端,用python调用并传入参数即可解决

解决:

在 cmd 中输入代码:

python argparser.py  --image  konglong.jpg    

效果如下图(cmd终端图 + 实现效果图):

 

cmd终端调用图

注意:图中的路径可以修改,根据自己的来。

实现效果图 konglong

查找问题中用到的-参考链接-

1.  http://tieba.baidu.com/p/4971726758?pid=103728845409&cid=0#103728845409

2. https://zhidao.baidu.com/question/2271396862409494588.html

3. https://blog.ixxoo.me/argparse.html

4. 如果在cmd中没有python命令可用, 那么你需要添加一下环境变量了。参考这个链接:

https://jingyan.baidu.com/article/8ebacdf02d3c2949f65cd5d0.html

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值