Python error: argument -c/--conf is required
Python error: argument -c/--conf is required
我是 python 的新手,我的母语是 C。我正在 python 中为使用 OpenCV 的运动触发的监视系统编写代码。我的代码基于 Adrian Rosebrock 在他的博客 pyimagesearch.com 中编写的代码。最初代码是为带有 Pi Camera 模块的 Raspiberry Pi 开发的,现在我正在尝试适应我笔记本的网络摄像头。他制作了一个关于运动检测的简单代码的更简单的教程,它在我的电脑上运行得非常好。但是我很难处理其他代码。可能这是一个愚蠢的错误,但作为初学者我找不到这个问题的具体答案。
此图像在屏幕左侧显示了导致错误的代码部分(第 15 行)和项目结构。
Image of python project for surveillance.
类似部分,原码:
# import the necessary packages
from pyimagesearch.tempimage import TempImage
from dropbox.client import DropboxOAuth2FlowNoRedirect
from dropbox.client import DropboxClient
from picamera.array import PiRGBArray
from picamera import PiCamera
import argparse
import warnings
import datetime
import imutils
import json
import time
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--conf", required=True,
help="path to the JSON configuration file")
args = vars(ap.parse_args())
# filter warnings, load the configuration and initialize the Dropbox
# client
warnings.filterwarnings("ignore")
conf = json.load(open(args["conf"]))
client = None
到目前为止我只改变了这些东西:
- 排除pi相机的进口亲属。
- 将
camera = PiCamera()
更改为 camera = cv2.VideoCapture(0)
。这样我就可以使用笔记本的网络摄像头了。
排除:
camera.resolution = tuple(conf["resolution"])
camera.framerate = conf["fps"]
rawCapture = PiRGBArray(camera, size=tuple(conf["resolution"]))
- 将行
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
替换为 while True:
。
- 排除程序中的两行
rawCapture.truncate(0)
。
可能还有更多的东西要修复,如果你现在请告诉我,但首先我想了解如何解决那个消息错误。我在 Windows 7 中使用 PyCharm 与 Python 2.7 和 OpenCV 3.1。抱歉没有 post 整个代码,但是一旦这是我在网站上的第一个问题并且我的声誉为 0,显然我只能 post 2 个链接。完整的原始代码在 pyimagesearch.com 中。感谢您的宝贵时间!
我想你可能 运行 不正确。错误信息很清楚。您正在添加参数,这意味着您需要在 运行 时提供它们,而您没有这样做。
在您提供的教程 link 中查看他 运行 这个方法
关于@Rhoit 中图 6 屏幕截图的通知 link。
python pi_surveillance.py --conf conf.json
程序已用名称和这些 --conf conf.json
个词初始化。
在您的代码中:
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--conf", required=True,
help="path to the JSON configuration file")
ap
是从命令行读取这些输入并解析信息的一段代码。此定义指定需要 --conf
参数,如图 6 所示。
错误表明您遗漏了这些信息:
argument -c/--conf is required
我是 python 的新手,我的母语是 C。我正在 python 中为使用 OpenCV 的运动触发的监视系统编写代码。我的代码基于 Adrian Rosebrock 在他的博客 pyimagesearch.com 中编写的代码。最初代码是为带有 Pi Camera 模块的 Raspiberry Pi 开发的,现在我正在尝试适应我笔记本的网络摄像头。他制作了一个关于运动检测的简单代码的更简单的教程,它在我的电脑上运行得非常好。但是我很难处理其他代码。可能这是一个愚蠢的错误,但作为初学者我找不到这个问题的具体答案。
此图像在屏幕左侧显示了导致错误的代码部分(第 15 行)和项目结构。
Image of python project for surveillance.
类似部分,原码:
# import the necessary packages
from pyimagesearch.tempimage import TempImage
from dropbox.client import DropboxOAuth2FlowNoRedirect
from dropbox.client import DropboxClient
from picamera.array import PiRGBArray
from picamera import PiCamera
import argparse
import warnings
import datetime
import imutils
import json
import time
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--conf", required=True,
help="path to the JSON configuration file")
args = vars(ap.parse_args())
# filter warnings, load the configuration and initialize the Dropbox
# client
warnings.filterwarnings("ignore")
conf = json.load(open(args["conf"]))
client = None
到目前为止我只改变了这些东西:
- 排除pi相机的进口亲属。
- 将
camera = PiCamera()
更改为camera = cv2.VideoCapture(0)
。这样我就可以使用笔记本的网络摄像头了。 排除:
camera.resolution = tuple(conf["resolution"]) camera.framerate = conf["fps"] rawCapture = PiRGBArray(camera, size=tuple(conf["resolution"]))
- 将行
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
替换为while True:
。 - 排除程序中的两行
rawCapture.truncate(0)
。
可能还有更多的东西要修复,如果你现在请告诉我,但首先我想了解如何解决那个消息错误。我在 Windows 7 中使用 PyCharm 与 Python 2.7 和 OpenCV 3.1。抱歉没有 post 整个代码,但是一旦这是我在网站上的第一个问题并且我的声誉为 0,显然我只能 post 2 个链接。完整的原始代码在 pyimagesearch.com 中。感谢您的宝贵时间!
我想你可能 运行 不正确。错误信息很清楚。您正在添加参数,这意味着您需要在 运行 时提供它们,而您没有这样做。
在您提供的教程 link 中查看他 运行 这个方法
关于@Rhoit 中图 6 屏幕截图的通知 link。
python pi_surveillance.py --conf conf.json
程序已用名称和这些 --conf conf.json
个词初始化。
在您的代码中:
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--conf", required=True,
help="path to the JSON configuration file")
ap
是从命令行读取这些输入并解析信息的一段代码。此定义指定需要 --conf
参数,如图 6 所示。
错误表明您遗漏了这些信息:
argument -c/--conf is required