我是 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"]))
- 用
while True:
替换行for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
。 - 排除程序中的两行
rawCapture.truncate(0)
。
可能还有更多的东西要修复,如果你现在请告诉我,但首先我想了解如何解决那个 mensage 错误。我在带有 Python 2.7 和 OpenCV 3.1 的 Windows 7 中使用 PyCharm。抱歉没有发布完整的代码,但是一旦这是我在网站上的第一个问题并且我的声誉为 0,显然我可以发布 2 个链接。完整的原始代码在 pyimagesearch.com 中。感谢您的宝贵时间!
最佳答案
我认为您可能没有正确运行它。错误信息很清楚。您正在添加参数,这意味着您需要在运行时提供它们,而您没有这样做。
在您提供的教程链接中查看他是如何运行的
关于json - Python 错误 : argument -c/--conf is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35692350/