簡體   English   中英

我發生了錯誤異常:TypeError 元組索引必須是整數或切片,而不是 str (Open CV)?

[英]i had Error Exception has occurred: TypeError tuple indices must be integers or slices, not str (Open CV)?

任何人都可以幫助我,我被困在 argparse 上進行 objectdetection open cv,首先我使用

args = vars(ap.parse_args()) 

有一個錯誤 systemExit2 但現在使用 args['bal..bla'], ['bla..bla'] 時很好,但下一個錯誤 TypeError 元組索引必須是整數或切片,而不是 str

#start from here
ap = argparse.ArgumentParser()
ap.add_argument("-p", '-f',"--prototxt", required=True,
help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True, 
help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.2,
    help="minimum probability to filter weak detections")
args = ['prototxt'], ['model']


CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
    "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
    "dog", "horse", "motorbike", "person", "pottedplant", "sheep",
    "sofa", "train", "tvmonitor"]
COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3))

#Error on this section
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args['prototxt'],['model'])'''

我正在使用導入

 from imutils.video import VideoStream
 from imutils.video import FPS
 import numpy as np
 import argparse
 import imutils
 import time
 import cv2
 import sys
 import os

我正在使用 Visual Studio 使用 python 3.6.5 opencv 4.2.0

您正在為args創建一個常量值元組:

args = ['prototxt'], ['model']

您需要從參數解析器中獲取args的值。

args = ap.parse_args()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM