Ask Your Question

Tiaguituh05's profile - activity

2017-01-09 08:36:42 -0600 asked a question Getting eyes images with dlib

Hello, once again my question resumes to the following: I got the landmarks, and after that I want to get and save only the images of the eyes (separately) Im using the following scrip:

import sys
import os
import dlib
import glob
from skimage import io

if len(sys.argv) != 3:
        "Give the path to the trained shape predictor model as the first "
        "argument and then the directory containing the facial images.\n"
        "For example, if you are in the python_examples folder then "
        "execute this program by running:\n"
        "    ./ shape_predictor_68_face_landmarks.dat ../examples/faces\n"
        "You can download a trained facial shape predictor from:\n"

predictor_path = sys.argv[1]
faces_folder_path = sys.argv[2]

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
win = dlib.image_window()

for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")):
    print("Processing file: {}".format(f))
    img = io.imread(f)


    # Ask the detector to find the bounding boxes of each face. The 1 in the
    # second argument indicates that we should upsample the image 1 time. This
    # will make everything bigger and allow us to detect more faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))
    for k, d in enumerate(dets):
        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
            k, d.left(),, d.right(), d.bottom()))
        # Get the landmarks/parts for the face in box d.
        shape = predictor(img, d)
        print("Part 0: {}, Part 1: {} ...".format(shape.part(0),
        # Draw the face landmarks on the screen.


I tried all sort of things but I cant get the eyes images, does any1 know how to do so?

2017-01-09 08:15:02 -0600 commented question Save the eye image after the detection

@berak Hello again, I believe I found a code that uses dlib for landmarks, then align the face and finally gets the eye, but it is for video, and im working with images, I tried to adapt the code to my own needs but im failing to do so, if you are willing to help, I could really use a hand. Is there any other way we can communicate?

2017-01-09 06:18:50 -0600 commented question Save the eye image after the detection

@berak thats exacly the problem Im facing, the eye cascades are really not that accurate. My first try was exacly that one, the dlib landmarker, but I couldnt crop the eyes from that scrip

Awesome, changing to min_neighbours to 2 (5 made it only detect one eye) fixed the problem, at least for that image, I will try to test it on more later. I really would like to extract the eyes from the dlib landmarker, but I think its too much for me, im still a newbie on programming

2017-01-09 06:13:31 -0600 received badge  Supporter (source)
2017-01-09 06:12:27 -0600 commented question Save the eye image after the detection

@berak Is there anyway to tune up the eye haarcacade classifier? The photos I need to work with have a low resolution, and that leads to some errors. Example: link text Which then saves me a image of that part of the lip, and I wanted to try to reduce those liittle errors

2017-01-09 06:00:18 -0600 commented question Save the eye image after the detection

@berak yea I do. After a quick search here on the forum I found that some1 already had this question before Should had done the search before creating the post, im sorry :)

2017-01-09 05:51:19 -0600 commented question Save the eye image after the detection

@berak Used the nvidia DIGITS plattaform to create a caffe model using the CEW dataset (closed eyes in the wild)

2017-01-09 05:47:50 -0600 received badge  Editor (source)
2017-01-09 05:47:06 -0600 asked a question Save the eye image after the detection

Hello, So I was playing around with the face and eye detector with OpenCV

import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('image_020_1.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:

And I wanted to try to get it a little further, like saying If the eye is open or closed, for that I already trained a classifier, but I need to save the roi (in this case the eyes separetly) into a image file, I tried everything but I couldnt get anywhere, does any1 know how to do it?