3

the full error is:

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

The Source code is:

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)

It is a simple Face detector app in OpenCV but I wanter to add Facial landmark mark detection in this... everything works fine until I add the last three lines of code which crashes the whole app

Also, I am using python 3.6.7 and purposefully downgraded the version of opencv to 3.4.6.

vIvId_gOat
  • 358
  • 2
  • 13
  • Can you please post the whole traceback? The error that you posted doesn't clarify where the problem occurs – Francesco Montesano Nov 04 '20 at 13:05
  • 1
    @FrancescoMontesano I have updated The question and it seems that my IDE died... so I tried the default Python IDE and It didn't even throwback an error instead it just restarted two times... I can also say it didn't run because at the end of the program I asked it to display the final image and it didn't – vIvId_gOat Nov 04 '20 at 13:27
  • Can you add also the traceback that you get when running the script directly from the python interpreter? I think that under Windows is something like `py my_script.py` or `python my_script.py` – Francesco Montesano Nov 04 '20 at 19:49
  • Well if I run the same script in Python IDE restars twice and ends without any traceback or error – vIvId_gOat Nov 05 '20 at 11:09
  • In your traceback I see a lot of references to Thonny: if I understand correctly this is an Ide. If you run your script from somewhere else, e.g. some terminal, why should there be so many references to Thonny? – Francesco Montesano Nov 05 '20 at 11:40
  • 2
    Have you found out the cause of this issue? If so, what was it? – MMM Nov 01 '22 at 13:11

0 Answers0