VSコードのEOFエラー(ターミナルでも機能しません)

Aug 23 2020

私はManjaroでvs-codeを使用しています。この質問で説明されている問題が多数あります👇manjaroでのVS- CODEエラーに続いて、自動終了し、フォルダーを開くことができません

私は次のコードを持っています

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

初めに、私はで構文エラーがありました

  File "Face_detector.py", line 24
    cv2.imshow('Face detector', frame)
    ^
SyntaxError: invalid syntax

行をコメントアウトしましたが、次の行で同じエラーが発生しました

  File "Face_detector.py", line 25
    key = cv2.waitKey(1)
    ^
SyntaxError: invalid syntax

だから私は先に進んで最後まですべての歌の行をコメントアウトしましたそして今私はEOFエラーを受け取りました

 File "Face_detector.py", line 33

                            ^
SyntaxError: unexpected EOF while parsing

ターミナルからスクリプトを実行しようとしましたが、それでもまったく同じエラーが発生します

これは、コメントされていないコードを端末から実行するイメージです。

これは、ターミナルからコメントアウトされた最終的なコードを実行する画像です。

回答

sanitizedUser Aug 23 2020 at 20:53

この行に括弧がありません:

#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