json - Python 错误 : argument -c/--conf is required

标签 json python-2.7 opencv camera argparse


我是 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 中。感谢您的宝贵时间!

最佳答案

我认为您可能没有正确运行它。错误信息很清楚。您正在添加参数,这意味着您需要在运行时提供它们,而您没有这样做。

在您提供的教程链接中查看他是如何运行的

http://www.pyimagesearch.com/2015/06/01/home-surveillance-and-motion-detection-with-the-raspberry-pi-python-and-opencv#crayon-56d3c5551ac59089479643

关于json - Python 错误 : argument -c/--conf is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35692350/

相关文章:

php - 修改从 PDO 和 PHP 生成的 json

python - 将 jsonString 转换为 Python 中可解析的内容?

java - 使用 Gson 将 Json 解析为具有通用字段的项目列表

json - 如何循环遍历单个 JSON 文件以使每个对象出现在 Ionic tinder 卡片上?

python - print 是如何准确处理逗号的?

Python file.write 随着输出文件变大而变慢

使用 NumPy 数据类型的 Python 字典查找速度

c++ - OPENCV C 和 C++ API 的不同结果(边界插值差异)

java - 从 org.bytedeco.javacv.Frame 转换为 matlab 图像

c++ - ../main : error while loading shared libraries: libopencv_highgui. so.4.0: 无法打开共享对象文件: 没有这样的文件或目录