Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'import face_recognition' Not found #5

Open
SajjaManojKumar opened this issue May 22, 2020 · 2 comments
Open

'import face_recognition' Not found #5

SajjaManojKumar opened this issue May 22, 2020 · 2 comments

Comments

@SajjaManojKumar
Copy link

I follow your blog on COVID-19 face mask detection.
I wanted to reproduce my own dataset. so i referred to this repository. I cloned a copy to use it.
In .\observations-master\mask_classifier\Data_Generator\mask.py line 67 you've imported face_recognition. But then you never mentioned from where you imported. It would be easy if you share even that part or even mention what is alternative way.
Thank you.

@arkothiwala
Copy link

face_recognition is used at just three locations:
(1) to read image -> use cv2.imread(address)
(2) to detect face -> you can use dlib.get_frontal_face_detector() ref - pyimagesearch post
(3) to get face_landmarks ->
predictor = dlib.shape_predictor('model.dat')
landmarks = predictor(gray_image, face_locations[0]) # just take first face
You need to convert laandmarks falling in nose and chin region into dict as the following function expects in that manner only
face_landmark = {}
face_landmark['nose_bridge'] = landmarks[27:36]
face_landmark['chin'] = landmarks[0:17]

now you have got everything to run main function i.e.
_mask_face(self, face_landmark: dict)

Again this is just for just one face. Please put this in for loop to handle multiple faces

@ninenerd
Copy link

ninenerd commented Aug 4, 2020

@arkothiwala Hi, I made changes as you suggested. but getting error.

face_landmark['nose_bridge'] = landmarks[27:36]
TypeError: 'dlib.full_object_detection' object is not subscriptable

       face_image_np=cv2.imread(self.face_path)
       face_locations= dlib.get_frontal_face_detector() 
       print(face_locations)
       predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
       gray_image=cv2.cvtColor(np.array(face_image_np),cv2.COLOR_BGR2GRAY)
       rects = face_locations(gray_image, 1)

       landmarks = predictor(gray_image, rects[0])
       
       face_landmark = {}
       face_landmark['nose_bridge'] = landmarks[27:36]
       face_landmark['chin'] = landmarks[0:17]
       
       self._face_img = Image.fromarray(face_image_np)
       self._mask_img = Image.open(self.mask_path)

Can you help me here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants