-1

Newbie here. I'm working with OpenCV to create a facial recognition program, but I'm getting a syntax error and cannot identify why it is happening

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()

The error I get is

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
Temp Estcrowd
  • 73
  • 1
  • 5
  • 1
    ON the previous line, you've failed to close all of the open parentheses. Your error is the sequence `, 3)\n resized` – Prune Aug 16 '19 at 19:24

2 Answers2

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

doesn't have a closing ')' for rectangle(

blueharen
  • 126
  • 5
1

You didn't close the parentheses in the previous line.

Jin
  • 304
  • 2
  • 10
  • Thankyou so much, but now in line 5 , for scale factor, I get the error that "NameError: name '_1' is not defined" – Temp Estcrowd Aug 16 '19 at 19:28
  • Because you never defined _1 in your code. You would want to have an integer for the scaleFactor. – Jin Aug 16 '19 at 19:43