简体   繁体   English

IndexError:列表索引超出范围:sys.argv[1] 超出范围

[英]IndexError: list index out of range: sys.argv[1] out of range

I'm trying to run the following code but keep running into an error,我正在尝试运行以下代码,但一直遇到错误,
"IndexError: list index out of range" “IndexError:列表索引超出范围”

I understand that this is todo with the sys.argv[1];我知道这与 sys.argv[1]; I have a basic idea that this function is call the first line of my project from the command line - when I try to run the project from CMD I run into the same error.我有一个基本想法,即这个 function 是从命令行调用我的项目的第一行 - 当我尝试从 CMD 运行项目时,我遇到了同样的错误。

The code:编码:

import cv2
import sys

cascadePath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascadePath)

video_capture = cv2.VideoCapture(0)


while True:
    ret, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

Error:错误:

Traceback (most recent call last):
  File "C:/Users/Niku/PycharmProjects/FaceDetection/FaceDetection.py", line 4, in <module>
    cascadePath = sys.argv[1]
IndexError: list index out of range

Any insight or advice would be greatly appreciated!任何见解或建议将不胜感激!

sys.argv[1] This code expects first command line argument. sys.argv[1]此代码需要第一个命令行参数。 If that's missing then you will encounter this error.如果缺少,那么您将遇到此错误。 Example:例子:

some_script.py some_script.py

import sys
sys.argv[1]

If you dont provide myfirst_agr (as shown below) then it will throw Index error what you are seeing.如果您不提供myfirst_agr (如下所示),那么它将抛出您所看到的索引错误。

some_script.py myfirst_agr

More examples are here更多示例在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sys.argv[1] 索引错误:列表索引超出范围 - sys.argv[1] IndexError: list index out of range driver.get(sys.argv[1]) 在 PC 上正常工作,而在其他 PC 上工作正常(sys.argv[1],IndexError: list index out of range 错误) - driver.get(sys.argv[1]) working fine on a PC and not on the other (sys.argv[1], IndexError: list index out of range error) Python GetHostId.py获取sys.argv [1] IndexError:列表索引超出范围 - Python GetHostId.py getting sys.argv[1] IndexError: list index out of range ds = data_set(sys.argv [1])IndexError:列表索引超出范围 - ds = data_set(sys.argv[1]) IndexError: list index out of range question_number = int(sys.argv[1]) IndexError:列表索引超出范围 - question_number = int(sys.argv[1]) IndexError: list index out of range 当我运行此命令“cascPath = sys.argv[1]”时,我收到错误 IndexError: list index out of range - When i run this command " cascPath = sys.argv[1] " i get error IndexError: list index out of range 读取 csv 文件错误:sys.argv[1], IndexError: list index out of range - Reading in csv file error: sys.argv[1], IndexError: list index out of range process_file(sys.argv [1])IndexError:列表索引超出范围 - process_file(sys.argv[1]) IndexError: list index out of range image_url = sys.argv [1] IndexError:列表索引超出范围 - image_url = sys.argv[1] IndexError: list index out of range fileku.write(sys.argv[i+3]+&#39;\\n&#39;) IndexError:列表索引超出范围 - fileku.write(sys.argv[i+3]+'\n') IndexError: list index out of range
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM