【问题标题】:EOF error in VS-code (not Working in terminal also)VS 代码中的 EOF 错误(也不能在终端中工作)
【发布时间】: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


    【解决方案1】:

    您在这一行缺少括号:

    #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
    

    【讨论】:

    • 好的,所以我修复了它但是现在我有这个错误。我相信 open cv 实现有问题。如果您愿意帮助我,我将不胜感激
    • 回溯(最近一次调用最后一次):文件“/home/smokedpirate/Documents/1.Python_learning/3_recognition/Realtime_face_detector/Face_detector.py”,第 17 行,在 face_coordinates =trained_face_data.detectMultiScale (greyscaled_img)cv2.error:OpenCV(4.4.0)/tmp/pip-req-build-6179nsls/opencv/modules/objdetect/src/cascadedetect.cpp:1689:错误:(-215:断言失败)!empty( ) 在函数“detectMultiScale”中
    • 我建议看一些答案here。
    猜你喜欢
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    相关资源
    最近更新 更多