VS 代码中的 EOF 错误(也不适用于终端)
EOF error in VS-code (not Working in terminal also)
我在 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
我尝试了 运行 来自终端的脚本,但仍然有完全相同的错误
Here is an image of running the uncommented code from the terminal
Here is an image of running the final commented out code from the terminal
您在这一行缺少括号:
#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