Exemplo n.º 1
0
    def standard_render(self):

        ## Create OpenDR renderer
        rn = ColoredRenderer()

        ## Assign attributes to renderer
        w, h = (640, 480)

        rn.camera = ProjectPoints(v=self.m,
                                  rt=np.zeros(3),
                                  t=np.array([0, 0, 2.]),
                                  f=np.array([w, w]) / 2.,
                                  c=np.array([w, h]) / 2.,
                                  k=np.zeros(5))
        rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
        rn.set(v=self.m, f=self.m.f, bgcolor=np.zeros(3))

        ## Construct point light source
        rn.vc = LambertianPointLight(f=self.m.f,
                                     v=rn.v,
                                     num_verts=len(self.m),
                                     light_pos=np.array([-1000, -1000, -2000]),
                                     vc=np.ones_like(self.m) * .9,
                                     light_color=np.array([1., 1., 1.]))

        ## Show it using OpenCV
        import cv2
        cv2.imshow('render_SMPL', rn.r)
        print('..Print any key while on the display window')
        cv2.waitKey(0)
        cv2.destroyAllWindows()
Exemplo n.º 2
0
def render(verts, faces, w=640, h=480):
    # Frontal view
    verts[:, 1:3] = -verts[:, 1:3]

    # Create OpenDR renderer
    rn = ColoredRenderer()

    # Assign attributes to renderer
    rn.camera = ProjectPoints(v=verts,
                              rt=np.zeros(3),
                              t=np.array([0., 0., 2.]),
                              f=np.array([w, h]) / 2.,
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=verts, f=faces, bgcolor=np.zeros(3))

    # Construct point light source
    rn.vc = LambertianPointLight(f=rn.f,
                                 v=rn.v,
                                 num_verts=len(verts),
                                 light_pos=np.array([1000, -1000, -2000]),
                                 vc=np.ones_like(verts) * .9,
                                 light_color=np.array([1., 1., 1.]))

    return rn.r
Exemplo n.º 3
0
def Render():

    verts = np.load('../../resault/verts.npy')
    faces = np.load('../../resault/faces.npy')

    rn = ColoredRenderer()
    w, h = (640, 480)

    rn.camera = ProjectPoints(v=verts,
                              rt=np.zeros(3),
                              t=np.array([0, 0, 2.]),
                              f=np.array([w, w]) / 2.,
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 0.8, 'far': 16., 'width': w, 'height': h}
    rn.set(v=verts, f=faces, bgcolor=np.array([255, 255, 255]))

    rn.vc = LambertianPointLight(f=faces,
                                 v=rn.v,
                                 num_verts=len(verts),
                                 light_pos=np.array([-1000, -1000, -2000]),
                                 vc=np.ones_like(verts) * .9,
                                 light_color=np.array([1., 1., 1.]))

    # import cv2
    #
    # cv2.imshow('render_SMPL', rn.r)
    # cv2.waitKey(0)
    import matplotlib.pyplot as plt
    plt.ion()
    plt.axis('off')
    plt.imshow(rn.r)
    raw_input()
    plt.show()
Exemplo n.º 4
0
def renderBody(m):
    from opendr.camera import ProjectPoints
    from opendr.renderer import ColoredRenderer
    from opendr.lighting import LambertianPointLight
    # Create OpenDR renderer
    rn = ColoredRenderer()
    # Assign attributes to renderer
    w, h = (640, 480)
    rn.camera = ProjectPoints(v=m,
                              rt=np.zeros(3),
                              t=np.array([0, 0, 2.]),
                              f=np.array([w, w]) / 2.,
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=m, f=m.f, bgcolor=np.zeros(3))
    # Construct point light source
    rn.vc = LambertianPointLight(f=m.f,
                                 v=rn.v,
                                 num_verts=len(m),
                                 light_pos=np.array([-1000, -1000, -2000]),
                                 vc=np.ones_like(m) * .9,
                                 light_color=np.array([1., 1., 1.]))
    plt.ion()
    plt.imshow(np.fliplr(rn.r))  # FLIPPED!
    plt.show()
    plt.xticks([])
    plt.yticks([])
Exemplo n.º 5
0
def create_synth(verts, joints, skin_color, f, ss, tu, tv, rot, w, h, bg):
       rn = ColoredRenderer()
       R = cv2.Rodrigues(rot)[0]
       verts = np.transpose(np.matmul(R, np.transpose(verts)))
       joints = np.transpose(np.matmul(R, np.transpose(joints)))
       verts_3d = verts
       joints_3d = joints

       verts = np.array([[ss, ss, 1], ] * 778) * verts
       joints = np.array([[ss, ss, 1], ] * 21) * joints

       verts = verts + np.array([[tu, tv, 0], ] * 778)
       joints = joints + np.array([[tu, tv, 0], ] * 21)

       umax = np.max(verts[:, 0])
       umin = np.min(verts[:, 0])
       vmax = np.max(verts[:, 1])
       vmin = np.min(verts[:, 1])
       if ((umin < 0.) or (vmin < 0.) or (umax > w) or (vmax > h)):
              print('mesh outside')

       verts[:, 2] = 10. + (verts[:, 2] - np.mean(verts[:, 2]))
       verts[:, :2] = verts[:, :2] * np.expand_dims(verts[:, 2], 1)

       rn.camera = ProjectPoints(v=verts, rt=np.zeros(3), t=np.array([0, 0, 0]), f=np.array([1, 1]),
                                 c=np.array([0, 0]), k=np.zeros(5))

       rn.frustum = {'near': 1., 'far': 20., 'width': w, 'height': h}
       rn.set(v=verts, f=f, bgcolor=np.zeros(3))
       rn.vc = np.ones((778, 3))

       mask = rn.r.copy()
       mask = mask[:, :, 0].astype(np.uint8)

       rn.vc = skin_color
       hand = rn.r.copy() * 255.

       image = (1 - np.expand_dims(mask, 2)) * bg + np.expand_dims(mask, 2) * hand
       image = image.astype(np.uint8)

       image = Image.fromarray(image).resize((224, 224), Image.LANCZOS)
       return image, mask, verts_3d, joints_3d, verts, joints
Exemplo n.º 6
0
def mesh2Image(vertices,
               faces,
               batch,
               path,
               name,
               height,
               width,
               vertices_num=6890):
    # Create OpenDR renderer
    rn = ColoredRenderer()

    rt_1 = np.zeros(3)

    rn.camera = ProjectPoints(
        v=vertices,  # vertices
        # v=m,
        rt=rt_1,
        # x, y, z translation of the camera, z>=0    0 0 2
        t=np.array([0, 0, 0]),
        # f=np.array([w,w])/2, # focus length? just scaling the picture
        # c=np.array([w,h])/2, #  just move the picture along top-left axis? not sure
        f=np.array([1, 1]),
        c=np.array([0, 0]),
        k=np.zeros(5))
    rn.frustum = {'near': 1, 'far': 15, 'width': width, 'height': height}
    rn.set(v=vertices, f=faces, bgcolor=np.zeros(3))

    # Construct point light source
    rn.vc = LambertianPointLight(
        f=faces,  # face
        v=vertices,
        # v=rn.v, #vertex?
        num_verts=len(vertices),
        light_pos=np.array([-1000, -1000, -2000]),  # point light position
        vc=np.ones_like(vertices) * .9,  # albedo per vertex
        light_color=np.array([1., 1.,
                              1.]))  # Blue, Green, Red; light intensity

    # make the image binary(black and white); these are actually magic steps
    rn.change_col(np.ones((vertices_num, 3)))
    #mask = rn.r.copy()  # takes lots of time

    mask = rn.r * 255
    import cv2
    if batch == 1:
        cv2.imwrite('%s/%s.png' % (path, name), mask)
    else:
        cv2.imwrite('%s/%s_%d.png' % (path, name, i), mask)
    '''
Exemplo n.º 7
0
def render_smpl(m):
    # Create OpenDR renderer
    rn = ColoredRenderer()
    # Assign attributes to renderer
    w, h = (640, 480)
    rn.camera = ProjectPoints(v=m, rt=np.zeros(3), t=np.array(
        [0, 0, 2.]), f=np.array([w, w])/2., c=np.array([w, h])/2., k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=m, f=m.f, bgcolor=np.zeros(3))
    # Construct point light source
    rn.vc = LambertianPointLight(
        f=m.f,
        v=rn.v,
        num_verts=len(m),
        light_pos=np.array([-1000, -1000, -2000]),
        vc=np.ones_like(m)*.9,
        light_color=np.array([1., 1., 1.]))
    image = rn.r * 255
    return image
Exemplo n.º 8
0
def render_smpl(par, theta, beta, img_out_file, model_path, front_view=False):
    m = load_model(model_path)
    ## Assign the given pose
    m.pose[:] = theta
    m.betas[:] = beta
    # Define specific parameters for showing a front view of the rendering
    if front_view:
        m.pose[:3] = np.array([np.pi, 0, 0], dtype=np.float32)
        rt = np.zeros(3)
        light_source = np.array([-1000, -1000, -2000])
    else:
        rt = np.array([3.14, 0, 0])
        light_source = np.array([1000, 1000, 2000])

    ## Create OpenDR renderer
    rn = ColoredRenderer()
    ## Assign attributes to renderer
    w, h = (640, 480)
    rn.camera = ProjectPoints(v=m,
                              rt=rt,
                              t=np.array([0, 0, 2.]),
                              f=np.array([w, w]) / 2.,
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=m, f=m.f, bgcolor=np.zeros(3))

    ## Construct point light source
    rn.vc = LambertianPointLight(
        f=m.f,
        v=rn.v,
        num_verts=len(m),
        #light_pos=np.array([-1000,-1000,-2000]),
        light_pos=light_source,
        vc=np.ones_like(m) * .9,
        light_color=np.array([1., 1., 1.]))

    cv2.imwrite(img_out_file, rn.r * 255.0)
    mesh[:, 2] = 10.0 + (mesh[:, 2] - np.mean(mesh[:, 2]))
    mesh[:, :2] = mesh[:, :2] * np.expand_dims(mesh[:, 2], 1)

    rn.camera = ProjectPoints(v=mesh,
                              rt=np.zeros(3),
                              t=np.array([0, 0, 0]),
                              f=np.array([1, 1]),
                              c=np.array([0, 0]),
                              k=np.zeros(5))

    rn.frustum = {'near': 1., 'far': 20., 'width': w, 'height': h}
    rn.set(v=mesh, f=m.f, bgcolor=np.zeros(3))
    rn.vc = LambertianPointLight(f=m.f,
                                 v=mesh,
                                 num_verts=len(m),
                                 light_pos=np.array([0, 0, 0]),
                                 vc=np.ones_like(m) * .9,
                                 light_color=np.array([1., 1., 1.]))

    mod = i % bg_number
    bg = misc.imread(os.path.join(bg_pth, '%d.png' % (mod)))

    rn.change_col(np.ones((778, 3)))

    mask = rn.r.copy()
    mask = mask[:, :, 0].astype(np.uint8)

    rn.change_col(colors[random.randint(0, 26)])

    hand = rn.r.copy() * 255.
    image = (1 - np.expand_dims(mask, 2)) * bg + np.expand_dims(mask, 2) * hand
Exemplo n.º 10
0
rn1.camera = ProjectPoints(v=m1, rt=np.zeros(3), t=np.array([0, 0, 2.]), f=np.array([w, w]) / 2.,
                          c=np.array([w, h]) / 2., k=np.zeros(5))
rn1.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
rn1.set(v=m1, f=m1.f, bgcolor=np.zeros(3))

rn2.camera = ProjectPoints(v=m2, rt=np.zeros(3), t=np.array([0, 0, 2.]), f=np.array([w, w]) / 2.,
                          c=np.array([w, h]) / 2., k=np.zeros(5))
rn2.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
rn2.set(v=m2, f=m2.f, bgcolor=np.zeros(3))

## Construct point light source
rn1.vc = LambertianPointLight(
    f=m1.f,
    v=rn1.v,
    num_verts=len(m1),
    light_pos=np.array([-1000, -1000, -2000]),
    vc=np.ones_like(m1) * .9,
    light_color=np.array([1., 1., 1.]))

rn2.vc = LambertianPointLight(
    f=m2.f,
    v=rn2.v,
    num_verts=len(m2),
    light_pos=np.array([-1000, -1000, -2000]),
    vc=np.ones_like(m2) * .9,
    light_color=np.array([1., 1., 1.]))
###################### Finish of Initialization of SMPL body model #############

########## path of the input file
Result_path = '/data/Guha/GR/Output/TestSet/13/'
Exemplo n.º 11
0
    def render(self, image, K, verts):

        ## Create OpenDR renderer
        rn = ColoredRenderer()

        ## Assign attributes to renderer
        w, h = (224 * self.ratio, 224 * self.ratio)

        f = np.array([K[0, 0, 0], K[0, 1, 1]]) * float(self.ratio)
        c = np.array([K[0, 0, 2], K[0, 1, 2]]) * float(self.ratio)

        rn.camera = ProjectPoints(v=verts,
                                  rt=np.zeros(3),
                                  t=np.array([0, 0, 5.]),
                                  f=f,
                                  c=c,
                                  k=np.zeros(5))

        rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}

        albedo = np.ones_like(self.m) * .9

        color1 = np.array([0.85490196, 0.96470588, 0.96470588])
        # light steel blue
        color2 = np.array([i / 255. for i in [181, 178, 146]])
        color3 = np.array([i / 255. for i in [190, 178, 167]])
        # beige
        # color4 = np.array([i / 255. for i in [245, 245, 220]])
        # wheat
        color4 = np.array([i / 255. for i in [245, 222, 179]])
        # thistle
        # color5 = np.array([i / 255. for i in [216, 191, 216]])
        color5 = np.array([i / 255. for i in [183, 166, 173]])

        # aqua marine
        color6 = np.array([i / 255. for i in [127, 255, 212]])
        # turquoise
        color7 = np.array([i / 255. for i in [64, 224, 208]])
        # medium turquoise
        color8 = np.array([i / 255. for i in [72, 209, 204]])
        # honeydew
        color9 = np.array([i / 255. for i in [240, 255, 240]])
        # burly wood
        color10 = np.array([i / 255. for i in [222, 184, 135]])
        # sandy brown
        color11 = np.array([i / 255. for i in [244, 164, 96]])
        # floral white
        color = np.array([i / 255. for i in [255, 250, 240]])

        rn.set(v=verts, f=self.m.f, vc=color, bgcolor=np.zeros(3))

        yrot = np.radians(120)
        rn.vc = LambertianPointLight(f=rn.f,
                                     v=rn.v,
                                     num_verts=len(rn.v),
                                     light_pos=rotateY(
                                         np.array([-200, -100, -100]), yrot),
                                     vc=albedo,
                                     light_color=np.array([1, 1, 1]))

        # Construct Left Light
        rn.vc += LambertianPointLight(f=rn.f,
                                      v=rn.v,
                                      num_verts=len(rn.v),
                                      light_pos=rotateY(
                                          np.array([800, 10, 300]), yrot),
                                      vc=albedo,
                                      light_color=np.array([1, 1, 1]))

        # Construct Right Light
        rn.vc += LambertianPointLight(f=rn.f,
                                      v=rn.v,
                                      num_verts=len(rn.v),
                                      light_pos=rotateY(
                                          np.array([-500, 500, 1000]), yrot),
                                      vc=albedo,
                                      light_color=np.array([.7, .7, .7]))

        img_orig = np.transpose(image, (1, 2, 0))
        img_resized = resize(
            img_orig,
            (img_orig.shape[0] * self.ratio, img_orig.shape[1] * self.ratio),
            anti_aliasing=True)

        img_smpl = img_resized.copy()
        img_smpl[rn.visibility_image != 4294967295] = rn.r[
            rn.visibility_image != 4294967295]

        rn.set(v=rotateY(verts, np.radians(90)),
               f=self.m.f,
               bgcolor=np.zeros(3))
        render_smpl = rn.r

        smpl_rgba = np.zeros((render_smpl.shape[0], render_smpl.shape[1], 4))
        smpl_rgba[:, :, :3] = render_smpl
        smpl_rgba[:, :, 3][rn.visibility_image != 4294967295] = 255

        return img_orig, img_resized, img_smpl, smpl_rgba
Exemplo n.º 12
0
## Create OpenDR renderer
rn = ColoredRenderer()

## Assign attributes to renderer
w, h = (640, 480)

rn.camera = ProjectPoints(v=m, rt=np.zeros(3), t=np.array([0, 0, 2.]), f=np.array([w,w])/2., c=np.array([w,h])/2., k=np.zeros(5))
rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
rn.set(v=m, f=m.f, bgcolor=np.zeros(3))

## Construct point light source
rn.vc = LambertianPointLight(
    f=m.f,
    v=rn.v,
    num_verts=len(m),
    light_pos=np.array([-1000,-1000,-2000]),
    vc=np.ones_like(m)*.9,
    light_color=np.array([1., 1., 1.]))


## Show it using OpenCV
import cv2
cv2.imwrite( "./test.png", rn.r )
print 'image saved'

# cv2.imshow('render_SMPL', rn.r)
# print ('..Print any key while on the display window')
# cv2.waitKey(0)
# cv2.destroyAllWindows()
fff = model.f.copy()
vvv = model.r.copy()

rn.camera = ProjectPoints(f=ch.array([KKK[0, 0], KKK[1, 1]]),
                          rt=cv2.Rodrigues(RRR)[0].flatten(),
                          t=ch.array(TTT),
                          k=ch.array([0, 0, 0, 0]),
                          c=ch.array([KKK[0, 2], KKK[1, 2]]))
rn.frustum = {'near': 0.1, 'far': 15., 'width': w, 'height': h}
rn.set(v=vvv, f=fff, bgcolor=ch.zeros(3))
rn.background_image = img / 255. if img.max() > 1 else img

# Construct point light source
rn.vc = LambertianPointLight(f=model.f,
                             v=rn.v,
                             num_verts=len(model),
                             light_pos=ch.array([0, 0, 0]),
                             vc=np.ones_like(model) * .5,
                             light_color=ch.array([-100., -100., -100.]))

if toOpenGL:
    cv2.imshow('render_SMPL', rn.r)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
else:
    smpl_vertices = model.r
    proj_smpl_vertices = chf.project_vertices(smpl_vertices, KKK, RT)
    proj_smpl_joints = chf.project_vertices(model.J_transformed.r, KKK, RT)
    proj_joints3d_vertices = chf.project_vertices(pose3d, KKK, RT)

    plt.imshow(img)
    # plt.scatter(proj_smpl_vertices[:, 0], proj_smpl_vertices[:, 1], 1)
Exemplo n.º 14
0
    def render(self, image, cam, K, verts, face, draw_id=''):

        # roll_axis = torch.Tensor([1, 0, 0]).unsqueeze(0)  # .expand(1, -1)
        # alpha = torch.Tensor([np.pi] * 1).unsqueeze(1) * 0.5
        # pose[0, :3] = axis_angle_add(pose[0, :3].unsqueeze(0), roll_axis, alpha)
        # pose[:3] *= torch.Tensor([1, -1, -1])

        # self.m.betas[:] = shape.numpy()[0]
        # self.m.pose[:] = pose.numpy()[0]

        # m.betas[:] = np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
        # m.betas[:] = np.array([0.]*10)
        # m.pose[:] = np.array([0.]*72)
        # m.pose[0] = -np.pi
        # m.pose[2] = 0.5
        # m.pose[2] = np.pi
        # m.betas[0] = 0.5

        ## Create OpenDR renderer
        rn = ColoredRenderer()

        # print(rn.msaa)
        #
        # rn.msaa = True

        ## Assign attributes to renderer
        w, h = (224 * self.ratio, 224 * self.ratio)
        # w, h = (1000, 1000)

        f = np.array([K[0, 0], K[1, 1]]) * float(self.ratio)
        c = np.array([K[0, 2], K[1, 2]]) * float(self.ratio)
        t = np.array([cam[1], cam[2], 2 * K[0, 0] / (224. * cam[0] + 1e-9)])
        # t = np.array([0, 0, 5.])

        # c = np.array([K[0, 0, 2], 112 - K[0, 1, 1] * float(cam[0, 2])]) * float(self.ratio)

        # rn.camera = ProjectPoints(v=m*np.array([1,-1,-1]), rt=np.zeros(3), t=np.array([0, 0, 5.]), f=f, c=c, k=np.zeros(5))
        rn.camera = ProjectPoints(v=verts,
                                  rt=np.zeros(3),
                                  t=t,
                                  f=f,
                                  c=c,
                                  k=np.zeros(5))

        rn.frustum = {'near': 1., 'far': 100., 'width': w, 'height': h}

        # [:, [1, 0, 2]]

        albedo = np.ones_like(verts) * .9
        # albedo(6890, 3)(6890, 3)(13776, 3)

        color1 = np.array([0.85490196, 0.96470588, 0.96470588])
        # light steel blue
        # color1 = np.array([i / 255. for i in [176, 196, 222]])
        # color1 = np.array([i / 255. for i in [168, 173, 180]])
        # color2 = np.array([i / 255. for i in [255, 244, 229]])
        color2 = np.array([i / 255. for i in [181, 178, 146]])
        color3 = np.array([i / 255. for i in [190, 178, 167]])
        # beige
        # color4 = np.array([i / 255. for i in [245, 245, 220]])
        # wheat
        color4 = np.array([i / 255. for i in [245, 222, 179]])
        # thistle
        # color5 = np.array([i / 255. for i in [216, 191, 216]])
        color5 = np.array([i / 255. for i in [183, 166, 173]])

        # aqua marine
        color6 = np.array([i / 255. for i in [127, 255, 212]])
        # turquoise
        color7 = np.array([i / 255. for i in [64, 224, 208]])
        # medium turquoise
        color8 = np.array([i / 255. for i in [72, 209, 204]])
        # honeydew
        color9 = np.array([i / 255. for i in [240, 255, 240]])
        # burly wood
        color10 = np.array([i / 255. for i in [222, 184, 135]])
        # sandy brown
        color11 = np.array([i / 255. for i in [244, 164, 96]])
        # floral white Ours
        color12 = np.array([i / 255. for i in [255, 250, 240]])
        # medium slate blue SPIN
        color13 = np.array([i / 255. for i in [72 * 2.5, 61 * 2.5, 255]])

        # color_list = [color1, color2, color3, color4, color5]
        color_list = [
            color6, color7, color8, color9, color10, color11, color12, color13
        ]
        # color_list = color_list + [color13]

        # color = color_list[int(len(color_list) * float(np.random.rand(1)))]
        # color = color_list[-1]
        if self.color in ['white']:
            color = color12
            color0 = np.array([1, 1, 1])
            color1 = np.array([1, 1, 1])
            color2 = np.array([0.7, 0.7, 0.7])
        elif self.color in ['blue']:
            color = color13
            color0 = color
            color1 = color
            color2 = color

        # rn.set(v=m*np.array([1,-1,1]), f=m.f, bgcolor=np.zeros(3))
        rn.set(v=verts, f=face, vc=color, bgcolor=np.zeros(3))
        # rn.set(v=rotateY(verts, np.radians(90)), f=self.m.f, bgcolor=np.zeros(3))

        ## Construct point light source
        # rn.vc = LambertianPointLight(
        #     f=m.f,
        #     v=rn.v,
        #     num_verts=len(m),
        #     light_pos=np.array([-1000,-1000,-2000]),
        #     vc=np.ones_like(m)*.9,
        #     light_color=np.array([1., 1., 1.]))
        yrot = np.radians(120)
        '''
        rn.vc = LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=np.array([-200, -100, -100]),
            vc=albedo,
            light_color=color)

        # Construct Left Light
        rn.vc += LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=np.array([500, 10, -200]),
            vc=albedo,
            light_color=color)

        # Construct Right Light
        rn.vc += LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=np.array([-300, 100, 600]),
            vc=albedo,
            light_color=color)
        '''
        # 1. 1. 0.7
        rn.vc = LambertianPointLight(f=rn.f,
                                     v=rn.v,
                                     num_verts=len(rn.v),
                                     light_pos=rotateY(
                                         np.array([-200, -100, -100]), yrot),
                                     vc=albedo,
                                     light_color=color0)

        # Construct Left Light
        rn.vc += LambertianPointLight(f=rn.f,
                                      v=rn.v,
                                      num_verts=len(rn.v),
                                      light_pos=rotateY(
                                          np.array([800, 10, 300]), yrot),
                                      vc=albedo,
                                      light_color=color1)

        # Construct Right Light
        rn.vc += LambertianPointLight(f=rn.f,
                                      v=rn.v,
                                      num_verts=len(rn.v),
                                      light_pos=rotateY(
                                          np.array([-500, 500, 1000]), yrot),
                                      vc=albedo,
                                      light_color=color2)

        # render_smpl = rn.r

        ## Construct point light source
        # rn.vc += SphericalHarmonics(light_color=np.array([1., 1., 1.]))

        img_orig = np.transpose(image, (1, 2, 0))
        img_resized = resize(
            img_orig,
            (img_orig.shape[0] * self.ratio, img_orig.shape[1] * self.ratio),
            anti_aliasing=True)

        # ax_smpl = plt.subplot(2, 2, 2)
        # plt.imshow(rn.r)
        # plt.axis('off')

        # print(max(rn.r))
        # print(min(rn.r))
        # fig = plt.figure()

        img_smpl = img_resized.copy()
        img_smpl[rn.visibility_image != 4294967295] = rn.r[
            rn.visibility_image != 4294967295]
        '''
        ax_stack = plt.subplot(2, 2, 3)
        ax_stack.imshow(img_smpl)
        plt.axis('off')
        '''

        rn.set(v=rotateY(verts, np.radians(90)), f=face, bgcolor=np.zeros(3))
        render_smpl = rn.r

        # rn.set(v=rotateY(verts, np.radians(90)), f=self.m.f, bgcolor=np.zeros(3))

        render_smpl_rgba = np.zeros(
            (render_smpl.shape[0], render_smpl.shape[1], 4))
        render_smpl_rgba[:, :, :3] = render_smpl
        render_smpl_rgba[:, :, 3][rn.visibility_image != 4294967295] = 255
        '''
        ax_img = plt.subplot(2, 2, 1)
        ax_img.imshow(np.transpose(image, (1, 2, 0)))
        plt.axis('off')
        ax_smpl = plt.subplot(2, 2, 2)
        ax_smpl.imshow(render_smpl_rgba)
        plt.axis('off')
        '''

        return img_orig, img_resized, img_smpl, render_smpl_rgba

        # img_uv = np.transpose(uvimage_front[0].cpu().numpy(), (1, 2, 0))
        # # img_uv = resize(img_uv, (img_uv.shape[0], img_uv.shape[1]), anti_aliasing=True)
        # img_uv[img_uv == 0] = img_show[img_uv == 0]

        # plt.show()

        # save_path = './notebooks/output/upimgs/'
        save_path = './notebooks/output/demo_results-v2/'
        if not os.path.exists(save_path):
            os.makedirs(save_path)

        matplotlib.image.imsave(save_path + 'img_' + draw_id + '.png',
                                img_orig)
        matplotlib.image.imsave(save_path + 'img_smpl_' + draw_id + '.png',
                                img_smpl)
        matplotlib.image.imsave(save_path + 'smpl_' + draw_id + '.png',
                                render_smpl_rgba)
    def render(self, image, cam, K, verts, face):
        ## Create OpenDR renderer
        rn = ColoredRenderer()

        ## Assign attributes to renderer
        w, h = (224 * self.ratio, 224 * self.ratio)

        f = np.array([K[0, 0], K[1, 1]]) * float(self.ratio)
        c = np.array([K[0, 2], K[1, 2]]) * float(self.ratio)
        t = np.array([cam[1], cam[2], 2 * K[0, 0] / (224. * cam[0] + 1e-9)])
        rn.camera = ProjectPoints(v=verts, rt=np.zeros(3), t=t, f=f, c=c, k=np.zeros(5))

        rn.frustum = {'near': 1., 'far': 100., 'width': w, 'height': h}

        albedo = np.ones_like(verts)*.9

        if self.color is not None:
            color0 = self.color
            color1 = self.color
            color2 = self.color
        else:
            # white
            color0 = np.array([1, 1, 1])
            color1 = np.array([1, 1, 1])
            color2 = np.array([0.7, 0.7, 0.7])

        rn.set(v=verts, f=face, bgcolor=np.zeros(3))

        yrot = np.radians(120)

        rn.vc = LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=rotateY(np.array([-200, -100, -100]), yrot),
            vc=albedo,
            light_color=color0)

        # Construct Left Light
        rn.vc += LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=rotateY(np.array([800, 10, 300]), yrot),
            vc=albedo,
            light_color=color1)

        # Construct Right Light
        rn.vc += LambertianPointLight(
            f=rn.f,
            v=rn.v,
            num_verts=len(rn.v),
            light_pos=rotateY(np.array([-500, 500, 1000]), yrot),
            vc=albedo,
            light_color=color2)

        img_orig = np.transpose(image, (1, 2, 0))
        img_resized = resize(img_orig, (img_orig.shape[0] * self.ratio, img_orig.shape[1] * self.ratio), anti_aliasing=True)

        img_smpl = img_resized.copy()
        img_smpl[rn.visibility_image != 4294967295] = rn.r[rn.visibility_image != 4294967295]

        rn.set(v=rotateY(verts, np.radians(90)), f=face, bgcolor=np.zeros(3))
        render_smpl = rn.r

        render_smpl_rgba = np.zeros((render_smpl.shape[0], render_smpl.shape[1], 4))
        render_smpl_rgba[:, :, :3] = render_smpl
        render_smpl_rgba[:, :, 3][rn.visibility_image != 4294967295] = 255

        return img_orig, img_resized, img_smpl, render_smpl_rgba
Exemplo n.º 16
0
    rn = ColoredRenderer()

    # Assign attributes to renderer
    w, h = (640, 480)

    rn.camera = ProjectPoints(v=smpl,
                              rt=np.zeros(3),
                              t=np.array([0, 0, 3.]),
                              f=np.array([w, w]),
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=smpl, f=smpl.f, bgcolor=np.zeros(3))

    # Construct point light source
    rn.vc = LambertianPointLight(f=smpl.f,
                                 v=rn.v,
                                 num_verts=len(smpl),
                                 light_pos=np.array([-1000, -1000, -2000]),
                                 vc=np.ones_like(smpl) * .9,
                                 light_color=np.array([1., 1., 1.]))

    # Show it using OpenCV
    import cv2

    cv2.imshow('render_SMPL', rn.r)
    print('..Print any key while on the display window')
    cv2.waitKey(0)
    cv2.destroyAllWindows()
Exemplo n.º 17
0
    ## Assign attributes to renderer
    w, h = (640, 480)

    rn.camera = ProjectPoints(v=m,
                              rt=np.zeros(3),
                              t=np.array([0, 0, 2.]),
                              f=np.array([w, w]) / 2.,
                              c=np.array([w, h]) / 2.,
                              k=np.zeros(5))
    rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
    rn.set(v=m, f=m.f, bgcolor=np.ones(3))

    ## Construct point light source
    rn.vc = LambertianPointLight(f=m.f,
                                 v=rn.v,
                                 num_verts=len(m),
                                 light_pos=np.array([-1000, -1000, -6000]),
                                 vc=np.ones_like(m) * .9,
                                 light_color=np.array([1., 1., 1.]))

    ## Show it using Open12
    INPUT = (rn.r).copy()
    cv2.imwrite('VISUALIZATION/' + expmtname + '/INPUT/' + str(i) + '.jpg',
                rn.r * 255)
    ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
    m.pose[3:] = predictions[i, :]
    # Create OpenDR renderer
    rn = ColoredRenderer()
    ## Assign attributes to renderer
    w, h = (640, 480)

    rn.camera = ProjectPoints(v=m,