faceRecognize.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Girl-s-Camera 作者: SHANEGU56 项目源码 文件源码
def face_beautify(image,cascade, cascade2, processed_image):
    image1 = image[y:y+height, x:x+width]
    image_high = image1
    eyes = cascade2.detectMultiScale(image1)
    for (ex, ey, ew, eh) in eyes:
        center_x = ex + ew * 0.5
        center_y = ey + eh * 0.5
        eyes1 = image1[ey:ey+eh, ex:ex+ew]
        eyes2 = eyes1
        kernel_radius = min(ew, eh) * 0.4
        for r in range(eh):
            for c in range(ew):
                diff_x = c - ew*0.5
                diff_y = r - eh*0.5
                distance = math.sqrt(diff_x * diff_x + diff_y * diff_y)
                p_x = 0
                p_y = 0
                if distance <= kernel_radius:
                    re = (1 - math.cos(distance / kernel_radius * 2 * math.pi)) * 2.5
                    p_x = -diff_x * (re / kernel_radius)
                    p_y = -diff_y * (re / kernel_radius)
                if p_x < 0 : 
                    p_x  = 0
                if p_y < 0 : 
                    p_y = 0
                eyes2[r,c] = eyes1[int(r + p_y),int(c + p_x)]
        image1[ey:ey+eh, ex:ex+ew] = eyes2  
    image_high1 = cv2.bilateralFilter(image_high, 15, 37, 37)
    #image_high2 = image_high1 - image1 + 128 
    image_high3 = cv2.GaussianBlur(image_high1,(1, 1),0)
    #image_high4 = image1 + 2 * image_high3 - 255
    #final = image1 * 0.45 + image_high4 * 0.55
    c_x = x + width * 0.5
    c_y = y + height * 0.5
    radius = min(width, height) * 2
    image_high4 = image_high3
    for row in range(height):
        for col in range(width):
            diff_x = col - width * 0.5
            diff_y = col - height * 0.5
            distance = math.sqrt(square(col - width*0.5) + square(row - height*0.5))
            m_x = 0
            m_y = 0
            if distance <= radius:
                re = (1 - math.cos(distance / radius * 2 * math.pi)) * 2
                m_x = -diff_x * (re / radius)
                m_y = -diff_y * (re / radius)
            if m_x < 0:
                m_x = 0
            if m_y < 0:
                m_y = 0
            image_high4[row,col] = image_high3[int(row + m_y), int(col + m_x)]
    image[y:y+height, x:x+width] = image_high4
    return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号