Ask Your Question

Minu's profile - activity

2020-03-27 03:39:32 -0500 received badge  Popular Question (source)
2017-01-09 06:13:31 -0500 received badge  Student (source)
2016-11-01 10:36:48 -0500 asked a question Facial LandMarks extraction Python

Hey there! I am trying to extract 6-8 face landmarks. I use Python as compiler, face detection from OpenCV and facial landmarks detection from Dlib. The thing is the program extracts 68 of them. And i want some specifics one. The code is:

import cv2
import dlib
import numpy 

PREDICTOR_PATH = "C:\Python27\Lib\site-packages\dlib\shape_predictor_68_face_landmarks.dat"
predictor = dlib.shape_predictor(PREDICTOR_PATH)
cascade_path='C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml'
cascade = cv2.CascadeClassifier(cascade_path)

def get_landmarks(im):
    rects = cascade.detectMultiScale(im, 1.3,5)
    x,y,w,h =rects[0]
    rect=dlib.rectangle(x,y,x+w,y+h)
    return numpy.matrix([[p.x, p.y] for p in predictor(im, rect).parts()])

def annotate_landmarks(im, landmarks):
    im = im.copy()
    for idx, point in enumerate(landmarks):
        pos = (point[0, 0], point[0, 1])
        cv2.putText(im, str(idx), pos,
                    fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
                    fontScale=0.4,
                    color=(0, 0, 255))
        cv2.circle(im, pos, 3, color=(0, 255, 255))
        print point, idx
    return im

im=cv2.imread('fa.jpg')
cv2.imshow('Result',annotate_landmarks(im,get_landmarks(im)))
cv2.waitKey(0)
cv2.destroyAllWindows()

There is a line code i don't understand and i believe it's the key for specific marks extraction.

pos = (point[0, 0], point[0, 1])< If i change the lane for idx, point in enumerate(landmarks): to for idx, point in enumerate(landmarks[8]): i will get only one facial mark (the chin one. 8 is the index of that point). But i can't put more specific points there because i will get this error:

TypeError: 'list' object cannot be interpreted as an index

Any idea guys? ^^

2016-10-23 13:20:10 -0500 commented answer Crop ROI from Face-Eye detection

I really appreciate your help and answers! I'm a newbie in programming at all, not only python. I have to do some work for my degree with it :). Before your answer i was using: For face crop:

cropped = roi_color[y:y+h, x:x+w]
cv2.imshow ("cropped", cropped)
cv2.waitKey(0)

Idem for eyes, but i was able to get just one of them. Your idea of code definetly fits better since i have to take every frame and apply several imaging processes to identify the iris and its center.

Thanks again for your time!

2016-10-23 03:45:51 -0500 asked a question Crop ROI from Face-Eye detection

Hey there guys!

I'm a newbie in python thing. I'm trying to crop the ROI from video stream. But i got no result at the moment. The code i'm using is:

import numpy as np
import cv2


face_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('C:\opencv\sources\data\haarcascades\haarcascade_eye.xml')

cap = cv2.VideoCapture(0)

while 1:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        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:
            cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

    cv2.imshow('img',img)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

crop_img = roi_color[?]
cv2.imwrite("path", roi_color)

Any advice is welcome! Have a nice day

2016-10-23 02:54:16 -0500 received badge  Enthusiast
2016-10-22 14:18:22 -0500 commented question OpenCV - Python Install Error

Hey again! I would like you to thanks for your time first. The problem is solved. I think i have used the wrong versions. At the moment i'm using opencv 3.1.0, python 2.7.3, numpy 1.9.1 and its working :). Have a nice day!

2016-10-20 10:18:09 -0500 received badge  Editor (source)
2016-10-20 10:17:31 -0500 asked a question OpenCV - Python Install Error

Hello there!

I have to do some work for my degree in Python. I need the OpenCV libraries too. I followed up the tutorial from OpenCV-Python installation and it went good up to last phase where i had to write import cv2. The error was about some DLLs file missing. I tried to reinstall, i've done the same thing again and again with different versions. Nothing seems to change it. Im open to any suggestion. I use windows 10 if it makes any sense.

Thanks

2016-10-18 08:47:00 -0500 asked a question OpenCV - Python Instalation

Hey there boys and girls!

I'm kind of new to programming business. I am trying to instal OpenCV-Python from source (via http://docs.opencv.org/3.1.0/d5/de5/t... tutorial). At the moment i am stucked at point after 7d.(after i click finish). The error looks like this:image description(/upfiles/14767981729825897.png) . I'm trying to get this installed on a windows10. I've done every step from the tutorial.

Do you have any idea what would be wrong?

Thanks, Minu