Exemplo n.º 1
0
def tran_src(src_img, src_points, dst_points, face_area=None):
    # print(1111111)
    print(src_img.shape)
    jaw = core.JAW_END

    dst_list = dst_points \
               + core.matrix_rectangle(face_area[0], face_area[1], face_area[2], face_area[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])

    src_list = src_points \
               + core.matrix_rectangle(face_area[0], face_area[1], face_area[2], face_area[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])

    jaw_points = []

    for i in range(0, jaw):
        # print(i)
        jaw_points.append(dst_list[i])
        jaw_points.append(src_list[i])

    warp_jaw = cv2.convexHull(np.array(jaw_points), returnPoints=False)
    warp_jaw = warp_jaw.tolist()

    for i in range(0, len(warp_jaw)):
        warp_jaw[i] = warp_jaw[i][0]

    warp_jaw.sort()

    if len(warp_jaw) <= jaw:
        dst_list = dst_list[jaw - len(warp_jaw):]
        src_list = src_list[jaw - len(warp_jaw):]
        for i in range(0, len(warp_jaw)):
            dst_list[i] = jaw_points[int(warp_jaw[i])]
            src_list[i] = jaw_points[int(warp_jaw[i])]
    else:
        for i in range(0, jaw):
            if len(warp_jaw) > jaw and warp_jaw[i] == 2 * i and warp_jaw[
                    i + 1] == 2 * i + 1:
                warp_jaw.remove(2 * i)

            dst_list[i] = jaw_points[int(warp_jaw[i])]

    dt = core.measure_triangle(src_img, dst_list, src_points, dst_points)

    res_img = np.zeros(src_img.shape, dtype=src_img.dtype)

    for i in range(0, len(dt)):
        t_src = []
        t_dst = []

        for j in range(0, 3):
            t_src.append(src_list[dt[i][j]])
            t_dst.append(dst_list[dt[i][j]])
        if (checkLine(t_src) or checkLine(t_dst)):
            # print("not checked")
            continue
        else:
            core.affine_triangle(src_img, res_img, t_src, t_dst)

    return res_img
Exemplo n.º 2
0
def tran_src(src_img, src_points, dst_points, face_area=None):
    jaw = core.JAW_END

    newface = get_auto_facearae(src_points, src_img)
    dst_list = dst_points \
               + core.matrix_rectangle(newface[0], newface[1], newface[2], newface[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])

    src_list = src_points \
               + core.matrix_rectangle(newface[0], newface[1], newface[2], newface[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])
    jaw_points = []

    for i in range(0, jaw):
        jaw_points.append(dst_list[i])
        jaw_points.append(src_list[i])

    warp_jaw = cv2.convexHull(np.array(jaw_points), returnPoints=False)
    warp_jaw = warp_jaw.tolist()

    for i in range(0, len(warp_jaw)):
        warp_jaw[i] = warp_jaw[i][0]

    warp_jaw.sort()

    if len(warp_jaw) <= jaw:
        dst_list = dst_list[jaw - len(warp_jaw):]
        src_list = src_list[jaw - len(warp_jaw):]
        for i in range(0, len(warp_jaw)):
            dst_list[i] = jaw_points[int(warp_jaw[i])]
            src_list[i] = jaw_points[int(warp_jaw[i])]
    else:
        for i in range(0, jaw):
            if len(warp_jaw) > jaw and warp_jaw[i] == 2 * i and warp_jaw[
                    i + 1] == 2 * i + 1:
                warp_jaw.remove(2 * i)

            dst_list[i] = jaw_points[int(warp_jaw[i])]

    dt = core.measure_triangle(src_img, dst_list)

    res_img = np.zeros(src_img.shape, dtype=src_img.dtype)

    for i in range(0, len(dt)):

        t_src = []
        t_dst = []

        for j in range(0, 3):
            t_src.append(src_list[dt[i][j]])
            t_dst.append(dst_list[dt[i][j]])

        core.affine_triangle(src_img, res_img, t_src, t_dst)

    return res_img
Exemplo n.º 3
0
def tran_src(src_img, src_points, dst_points, face_area=None):
    # jaw = core.JAW_END

    dst_list = dst_points \
               + core.matrix_rectangle(face_area[0], face_area[1], face_area[2], face_area[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])

    src_list = src_points \
               + core.matrix_rectangle(face_area[0], face_area[1], face_area[2], face_area[3]) \
               + core.matrix_rectangle(0, 0, src_img.shape[1], src_img.shape[0])

    # jaw_points = []

    # for i in range(0, jaw):
    #     jaw_points.append(dst_list[i])
    #     jaw_points.append(src_list[i])

    # warp_jaw = cv2.convexHull(np.array(jaw_points), returnPoints=False)
    # warp_jaw = warp_jaw.tolist()

    # for i in range(0, len(warp_jaw)):
    #     warp_jaw[i] = warp_jaw[i][0]

    # warp_jaw.sort()

    # if len(warp_jaw) <= jaw:
    #     dst_list = dst_list[jaw - len(warp_jaw):]
    #     src_list = src_list[jaw - len(warp_jaw):]
    #     for i in range(0, len(warp_jaw)):
    #         dst_list[i] = jaw_points[int(warp_jaw[i])]
    #         src_list[i] = jaw_points[int(warp_jaw[i])]
    # else:
    #     for i in range(0, jaw):
    #         if len(warp_jaw) > jaw and warp_jaw[i] == 2 * i and warp_jaw[i + 1] == 2 * i + 1:
    #             warp_jaw.remove(2 * i)

    #         dst_list[i] = jaw_points[int(warp_jaw[i])]

    dt = core.measure_triangle(src_img.shape, dst_list)

    res_img = np.zeros(src_img.shape, dtype=src_img.dtype)

    for i in range(0, len(dt)):
        t_src = []
        t_dst = []

        for j in range(0, 3):
            t_src.append(src_list[dt[i][j]])
            t_dst.append(dst_list[dt[i][j]])

        core.affine_triangle(src_img, res_img, t_src, t_dst)

    return res_img