Ejemplo n.º 1
0
def depth(img, ver_lst, show_flag=False, wfp=None, with_bg_flag=True):
    if with_bg_flag:
        overlap = img.copy()
    else:
        overlap = np.zeros_like(img)

    for ver_ in ver_lst:
        ver = _to_ctype(ver_.T)  # transpose

        z = ver[:, 2]
        z_min, z_max = min(z), max(z)

        z = (z - z_min) / (z_max - z_min)

        # expand
        z = np.repeat(z[:, np.newaxis], 3, axis=1)

        overlap = rasterize(ver, tri, z, bg=overlap)

    if wfp is not None:
        cv2.imwrite(wfp, overlap)
        print(f'Save visualization result to {wfp}')

    if show_flag:
        plot_image(overlap)

    return overlap
Ejemplo n.º 2
0
def render(img,
           ver_lst,
           tri,
           alpha=0.6,
           show_flag=False,
           wfp=None,
           with_bg_flag=True):
    if with_bg_flag:
        overlap = img.copy()
    else:
        overlap = np.zeros_like(img)

    for ver_ in ver_lst:
        ver = _to_ctype(ver_.T)  # transpose
        overlap = render_app(ver, tri, overlap)

    if with_bg_flag:
        res = cv2.addWeighted(img, 1 - alpha, overlap, alpha, 0)
    else:
        res = overlap

    if wfp is not None:
        cv2.imwrite(wfp, res)
        print(f'Save visualization result to {wfp}')

    if show_flag:
        plot_image(res)

    return res
Ejemplo n.º 3
0
def uv_tex(img,
           ver_lst,
           uv_h=256,
           uv_w=256,
           uv_c=3,
           show_flag=False,
           wfp=None):
    uv_coords = process_uv(g_uv_coords, uv_h=uv_h, uv_w=uv_w)

    res_lst = []
    for ver_ in ver_lst:
        ver = _to_ctype(ver_.T)  # transpose to m x 3
        colors = bilinear_interpolate(img, ver[:, 0], ver[:, 1]) / 255.
        # `rasterize` here serves as texture sampling, may need to optimization
        res = rasterize(uv_coords,
                        tri,
                        colors,
                        height=uv_h,
                        width=uv_w,
                        channel=uv_c)
        res_lst.append(res)

    # concat if there more than one image
    res = np.concatenate(res_lst, axis=1) if len(res_lst) > 1 else res_lst[0]

    if wfp is not None:
        cv2.imwrite(wfp, res)
        print(f'Save visualization result to {wfp}')

    if show_flag:
        plot_image(res)

    return res
Ejemplo n.º 4
0
def pncc(img, ver_lst, show_flag=False, wfp=None, with_bg_flag=True):
    ncc_code = _load(make_abs_path('../configs/ncc_code.npy'))

    if with_bg_flag:
        overlap = img.copy()
    else:
        overlap = np.zeros_like(img)

    # rendering pncc
    for ver_ in ver_lst:
        ver = _to_ctype(ver_.T)  # transpose
        overlap = rasterize(ver, tri, ncc_code.T, bg=overlap)  # m x 3

    if wfp is not None:
        cv2.imwrite(wfp, overlap)
        print(f'Save visualization result to {wfp}')

    if show_flag:
        plot_image(overlap)

    return overlap