kod

 avatar
unknown
python
4 years ago
1.5 kB
5
Indexable
import cv2
import numpy as np
import dlib


def kutuYarat(resim,noktalar,olcek=5):
    kutu = cv2.boundingRect(noktalar)
    x,y,w,h=kutu
    kesilmisResim = resim[y:y+h,x:x+w]
    
    kesilmisResim = cv2.resize(kesilmisResim,(0,0),None,olcek,olcek)
    
    return kesilmisResim



def dudakKes(resimYolu):
    resim = cv2.imread(resimYolu)
    resim = cv2.resize(resim,(0,0),None,0.5,0.5)
    orjinalResim = resim.copy()
    
    
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
    
    griResim = cv2.cvtColor(resim,cv2.COLOR_BGR2GRAY )
    
    yuzler = detector(griResim)
    
    for yuz in yuzler :
        x1,y1 = yuz.left(),yuz.top()
        x2,y2= yuz.right(),yuz.bottom()
        
        orjinalResim = cv2.rectangle(resim, (x1,y1), (x2,y2),(0,255,0),2)
        landmarks = predictor(griResim,yuz)
        noktalar =[]
        for n in range(68):
            x= landmarks.part(n).x
            y=landmarks.part(n).y
            noktalar.append([x,y]) 
            #cv2.circle(orjinalResim,(x,y),5,(50,50,255),cv2.FILLED)
    
    noktalar = np.array(noktalar)
    dudakResmi = kutuYarat(resim,noktalar[48:61])
    return dudakResmi
    
    


def anaMethod():
    kesilmisResim =dudakKes('3.jpg')
    cv2.imshow('',kesilmisResim)
    cv2.waitKey(0)
    cv2.destroyAllWindows()



if __name__=='__main__':
    anaMethod()

Editor is loading...