如何解决VS代码中的EOF错误也无法在终端中工作
我在Manjaro上使用vs代码ann在这个问题中得到了很多解释,“ VS- CODE errors on manjaro,auto quit,can't open folder
之后我有以下代码
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,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,10) # <-- Missing parentheses here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。