0

完整的错误是:

Windows fatal exception: access violation

Current thread 0x0000160c (most recent call first):

  File "E:\ml\projects\face swap\New folder\app.py", line 36 in <module>
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 1272 in _execute_prepared_user_code
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 1200 in wrapper
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 1213 in wrapper
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 1259 in execute_source
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 815 in _execute_source
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 801 in _execute_file
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 403 in _cmd_Run
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 204 in handle_command
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend.py", line 146 in mainloop
  File "C:\Users\USER\AppData\Local\Programs\Thonny\lib\site-packages\thonny\backend_launcher.py", line 87 in <module>
Windows fatal exception: access violation

源代码是:

import cv2
# used for accessing url to download files
import urllib.request as urlreq
# used to access local directory
import os
# used to plot our images


pic = "dataset/face.jpg"


# read image with openCV
image = cv2.imread(pic)

# plot image with matplotlib package
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)

haarcascade = "dataset/cascade.xml"
detector = cv2.CascadeClassifier(haarcascade)
faces = detector.detectMultiScale(image_gray)
for face in faces:
#     save the coordinates in x, y, w, d variables
    (x,y,w,d) = face
    # Draw a white coloured rectangle around each face using the face's coordinates
    # on the "image_template" with the thickness of 2 
    cv2.rectangle(image_rgb,(x,y),(x+w, y+d),(255, 255, 255), 2)
#cv2.imshow('Image',image_rgb)
#cv2.waitKey(0)
#cv2.destoyAllWindows()

LBFmodel = "dataset/lbfmodel.yaml"

landmark_detector  = cv2.face.createFacemarkLBF()
landmark_detector.loadModel(LBFmodel)
_, landmarks = landmark_detector.fit(image_gray, faces)

这是 OpenCV 中的一个简单的人脸检测器应用程序,但我想在其中添加面部地标标记检测......一切正常,直到我添加最后三行代码导致整个应用程序崩溃

另外,我正在使用python 3.6.7,并故意将opencv的版本降级为3.4.6。

4

0 回答 0