'facial recognition project Exit code 132 error: does anybody know what might be the cause to this?
Hi I have been working on a facial recognition project on my mac with an M1 processor, using the facial recognition and opencv library in python, I created a Conda environment for this project and installed my packages inside but somehow I ran into this error.
Process finished with exit code 132 (interrupted by signal 4: SIGILL)
Would someone have an idea as to why this is happening? I would really appreciate any help.
Here is my code:
import face_recognition as fr
import numpy as np
import cv2
#create encoding profiles:
face_1 = fr.load_image_file('assets/Seica.JPG')
face_1_encoding = fr.face_encodings(face_1)[0]
face_2 = fr.load_image_file('assets/Person photo.JPG')
face_2_encoding = fr.face_encodings(face_2)[0]
face_3 = fr.load_image_file('assets/Person2.JPG')
face_3_encoding = fr.face_encodings(face_3)[0]
known_face_encodings = [face_1_encoding,face_2_encoding,face_3_encoding]
known_face_names = ["Seica","Ambrose","Sahil"]
#Run Face Recognition on unknown faces
cap = cv2.VideoCapture(0)
while True:
ret,frame = cap.read()
unknown = fr.load_image_file(frame)
face_locations = fr.face_locations(frame)
face_encodings = fr.face_encodings(frame,face_locations)
for (top,right,bottom,left),face_encodings in zip(face_locations,face_encodings):
matches = fr.compare_faces(known_face_encodings,face_encodings)
name = "Unkown"
#which one is best matched index
face_distances = fr.face_distance(known_face_encodings,face_encodings)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
cv2.rectangle(frame,(left,top),(right,bottom),(0,255,0),3)
cv2.putText(frame,name,(left,top-20),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2,cv2.LINE_AA)
cv2.imshow('frame',frame)
if cv2.waitKey(1)==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Solution 1:[1]
Seems that this problem happens when you have multiple python interpreters installed, and some of them are for different architectures (x86_64 vs arm64). You need to make sure that the correct python interpreter is being used, if you installed Apple's version of OpenCV Python packages, then that probably requires an arm64 interpreter.
If you use rosetta (Apple's x86_64 emulator) then you need to use a x86_64 python interpreter, if you somehow load the arm64 python interpreter, you will get the illegal instruction error (which totally makes sense).
If you use any script that installs new python interpreters, then you need to make sure the correct interpreter for the architecture is installed (most likely arm64).
Overall I think this problem happens because the python environment setup is not made for systems that can run multiple instruction sets/architectures, pip does check the architecture of packages and the host system but seems you can run a x86_64 interpreter to load a package meant for arm64 and this produces the problem.
For reference you can check : https://opencv.org/opencv-python-for-apples-m1-chip-a-detective-story-with-a-happy-ending/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |