Errore EOF nel codice VS (non funziona anche nel terminale)
Aug 23 2020
Uso vs-code su Manjaro ann Ho avuto numerosi problemi con esso spiegato in questa domanda 👇seguendo errori VS- CODE su manjaro, chiusura automatica, impossibile aprire la cartella
Ho il codice seguente
import cv2
from random import randrange
#load data
trained_face_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
#Choose image
webcam = cv2.VideoCapture(0)
while True:
successful_frame_read, frame = webcam.read()
#convert to greyscale
greyscaled_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#detect faces
face_coordinates = trained_face_data.detectMultiScale(greyscaled_img)
#Draw a rectangle around the Face
for (x, y, w, h) in face_coordinates:
cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0, 10)
#Display the image with the faces spotted
cv2.imshow('Face detector', frame)
key = cv2.waitKey(1)
#stop if Q is pressed
if key==81 or key==113:
break
webcam.release()
print("code completed")
All'inizio, ho avuto un errore di sintassi in
File "Face_detector.py", line 24
cv2.imshow('Face detector', frame)
^
SyntaxError: invalid syntax
Ho commentato la riga ma ho ricevuto lo stesso errore nella riga successiva
File "Face_detector.py", line 25
key = cv2.waitKey(1)
^
SyntaxError: invalid syntax
Quindi sono andato avanti e ho commentato ogni riga di canto fino alla fine e ora ho ricevuto un errore EOF
File "Face_detector.py", line 33
^
SyntaxError: unexpected EOF while parsing
Ho provato a eseguire lo script dal terminale ma ha ancora lo stesso identico errore
Ecco un'immagine dell'esecuzione del codice non commentato dal terminale
Ecco un'immagine dell'esecuzione del codice finale commentato dal terminale
Risposte
sanitizedUser Aug 23 2020 at 20:53
Manca una parentesi su questa riga:
#Draw a rectangle around the Face
for (x, y, w, h) in face_coordinates:
cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0, 10) # <-- Missing parentheses here