2016-02-29 40 views
0


我是新的python,我的母語是C.我正在做一個代碼在python監控系統觸發運動使用OpenCV。我在Adrian Rosebrock的博客 pyimagesearch.com中編寫了我的代碼。最初的代碼是爲Raspiberry Pi開發的,並附有Pi Camera模塊,現在我正在嘗試適應我筆記本的攝像頭。他爲一個簡單的運動檢測代碼編寫了一個簡單的教程,並且在我的電腦中運行得非常好。但是我對這個其他代碼很困難。也許這是一個愚蠢的錯誤,但作爲begginer我找不到這個問題的具體答案。Python錯誤:參數-c/- conf是必需的


此圖像包含導致錯誤(第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)


可能還有更多的事情要修復,如果你現在請告訴我,但首先我想了解如何解決mensage錯誤。我在Windows 7中使用Python 2.7和OpenCV 3.1中的PyCharm。對不起,沒有發佈整個代碼,但一旦這是我在網站上的第一個問題,我有0的聲望,顯然我可以發佈2個鏈接。整個原始代碼位於pyimagesearch.com。感謝您的時間!

回答

0

通知。

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 
+0

感謝您的指示hpaulij。我正在執行PyCharm的代碼。當我運行在win7 cmd下面的命令py py_surveillance.py --conf conf.json時,前面的錯誤消失。 – Oshio

相關問題