Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCv在Python上的挣扎_Python_Python 3.x_Opencv - Fatal编程技术网

OpenCv在Python上的挣扎

OpenCv在Python上的挣扎,python,python-3.x,opencv,Python,Python 3.x,Opencv,我安装了OpenCv并找到了一个示例代码。但令人惊讶的是,它没有起作用。我在运行时收到此错误消息 import cv2 import sys # Get user supplied values imagePath = sys.argv[1] cascPath = sys.argv[2] # Create the haar cascade faceCascade = cv2.CascadeClassifier(cascPath) # Read the image image = cv2

我安装了OpenCv并找到了一个示例代码。但令人惊讶的是,它没有起作用。我在运行时收到此错误消息

import cv2  
import sys

# Get user supplied values
imagePath = sys.argv[1]
cascPath = sys.argv[2]

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30)
    #flags = cv2.CV_HAAR_SCALE_IMAGE
)

print("Found {0} faces!".format(len(faces)))

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Faces found", image)
cv2.waitKey(0)  

我该怎么办

该错误消息意味着它没有找到预期的命令行参数;图像的路径。您如何调用脚本?您需要类似python3 script.py imagepath cascpath的内容。该错误消息可能重复,这意味着它没有找到预期的命令行参数;图像的路径。您如何调用脚本?您需要类似python3 script.py imagepath的东西。可能是
Traceback (most recent call last):
  File "/Users/Esat/Desktop/Python/Softwares/untitled.py", line 5, in <module>
    imagePath = sys.argv[1]
IndexError: list index out of range