-1

新手来了 我正在使用 OpenCV 创建面部识别程序,但出现语法错误,无法确定发生的原因

import cv2

face_cascade = cv2.CascadeClassifier("D:\\Python\\Pycharm Projects\\haarcascade_frontalface_default.xml")
img = cv2.imread("E:\\pic\\Cam\\py.jpg")
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray_img, scaleFactor_=_1, minNeighbors=5)
print(type(faces))
print(faces)

for x, y, w, h in faces:
    img = cv2.rectangle(img, (int(img, (x,y), (x+w, y+h), (0, 255, 0), 3)

resized = cv2.resize(img, (int(img.shape[1]/2), int(img.shape[0]/2)))
cv2.imshow("Gray", resized)
cv2.waitkey(0)
cv2.destroyAllWindows()

我得到的错误是

File "C:/Users/Areeb Irfan/.PyCharmCE2018.3/config/scratches/facialdetect.py", line 14
resized = cv2.resize(img, (int(img.shape[1]/2), int(img.shape[0]/2)))
      ^
SyntaxError: invalid syntax
4

2 回答 2

2
img = cv2.rectangle(img, (int(img, (x,y), (x+w, y+h), (0, 255, 0), 3)

矩形没有结束 ')'(

于 2019-08-16T19:25:47.090 回答
1

您没有关闭上一行中的括号。

于 2019-08-16T19:23:29.357 回答