【发布时间】:2020-12-12 04:41:50
【问题描述】:
我在 Manjaro ann 上使用 vs-code 我在这个问题中解释了很多问题 ????following 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, 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
【问题讨论】:
标签: python-3.x linux visual-studio-code manjaro