move functions
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ from torch.utils.data import Dataset
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||
from data.render import Render, DepthRenderer
|
||||
from superSMPL.IO import readPC2Frame, writePC2
|
||||
from utils.data_utils import Frame, read_frames_file, mask_faces, get_normals_from_depth
|
||||
from utils.data_utils import Frame, read_frames_file, mask_faces, get_normals_from_depth, get_camera
|
||||
from cloth3d.read import DataReader
|
||||
from cloth3d.util import quads2tris
|
||||
|
||||
|
||||
+5
-43
@@ -10,7 +10,7 @@ from deodr.pytorch.differentiable_renderer_pytorch import Scene3DPytorch, Camera
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||
from cloth3d.util import proj
|
||||
|
||||
from utils.data_utils import intrinsic, extrinsic, get_camera
|
||||
|
||||
class RenderCore:
|
||||
def __init__(self, max_depth=0, depth_scale=1):
|
||||
@@ -70,45 +70,6 @@ class RenderCore:
|
||||
return depth
|
||||
|
||||
|
||||
""" CAMERA """
|
||||
def intrinsic():
|
||||
RES_X = 640
|
||||
RES_Y = 480
|
||||
f_mm = 50 # blender default
|
||||
sensor_w_mm = 36 # blender default
|
||||
sensor_h_mm = sensor_w_mm * RES_Y / RES_X
|
||||
|
||||
fx_px = f_mm * RES_X / sensor_w_mm
|
||||
fy_px = f_mm * RES_Y / sensor_h_mm
|
||||
|
||||
u = RES_X / 2
|
||||
v = RES_Y / 2
|
||||
|
||||
return np.array([[fx_px, 0, u],
|
||||
[0, fy_px, v],
|
||||
[0, 0, 1]], np.float32)
|
||||
|
||||
|
||||
def extrinsic(camLoc):
|
||||
R_w2bc = np.array([[0, 1, 0],
|
||||
[0, 0, 1],
|
||||
[1, 0, 0]], np.float32)
|
||||
|
||||
T_w2bc = -1 * R_w2bc.dot(camLoc)
|
||||
|
||||
R_bc2cv = np.array([[1, 0, 0],
|
||||
[0, -1, 0],
|
||||
[0, 0, -1]], np.float32)
|
||||
|
||||
R_w2cv = R_bc2cv.dot(R_w2bc)
|
||||
T_w2cv = R_bc2cv.dot(T_w2bc)
|
||||
|
||||
return np.concatenate((R_w2cv, T_w2cv[:,None]), axis=1)
|
||||
|
||||
def proj(camLoc):
|
||||
return intrinsic().dot(extrinsic(camLoc))
|
||||
|
||||
|
||||
class Render:
|
||||
def __init__(self, max_depth=0, depth_scale=1, size=(640, 480)):
|
||||
self.render_core = RenderCore(max_depth=max_depth)
|
||||
@@ -161,16 +122,17 @@ class DepthRenderer(nn.Module):
|
||||
# R, T = look_at_view_transform(2.7, 0, 0)
|
||||
# cameras = FoVPerspectiveCameras(device='cuda', R=R, T=T)
|
||||
|
||||
ext = torch.tensor(extrinsic(cam).astype(np.float32), device='cuda')
|
||||
# ext = torch.tensor(extrinsic(cam).astype(np.float32), device='cuda')
|
||||
# ext = proj(cam)
|
||||
# fp = np.array([240 * (480 / 36), 320 * (640 / 36)], dtype=np.float32)
|
||||
img_size = np.array([480, 640], dtype=np.float32)
|
||||
# K = np.eye(4, dtype=np.float32)
|
||||
# K[:3,:3] = intrinsic()
|
||||
K = torch.tensor(intrinsic()[None, :, :], device='cuda')
|
||||
# K = torch.tensor(intrinsic()[None, :, :], device='cuda')
|
||||
# cameras = PerspectiveCameras(device='cuda', R=ext[None, :, :3], T=ext[None, :, 3], focal_length=1,)# principal_point=fp[None, :], image_size=img_size[None, :])
|
||||
|
||||
cameras = cameras_from_opencv_projection(R=ext[None, :, :3], tvec=ext[None, :, 3], camera_matrix=K, image_size=torch.tensor(img_size[None, :], device='cuda'))
|
||||
# cameras = cameras_from_opencv_projection(R=ext[None, :, :3], tvec=ext[None, :, 3], camera_matrix=K, image_size=torch.tensor(img_size[None, :], device='cuda'))
|
||||
cameras, K = get_camera(cam, [480, 640], verts.get_device())
|
||||
|
||||
raster_settings = RasterizationSettings(
|
||||
image_size=(480, 640),
|
||||
|
||||
@@ -5,6 +5,7 @@ import torch
|
||||
import numpy as np
|
||||
import scipy.io as sio
|
||||
from math import cos, sin
|
||||
from pytorch3d.utils import cameras_from_opencv_projection
|
||||
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||
@@ -59,3 +60,51 @@ def get_normals_from_depth(depth_image, depth_mask, camera_intrinsic):
|
||||
|
||||
def center_crop_resize(img, new_center, size):
|
||||
pass
|
||||
|
||||
|
||||
""" CAMERA """
|
||||
def intrinsic():
|
||||
RES_X = 640
|
||||
RES_Y = 480
|
||||
f_mm = 50 # blender default
|
||||
sensor_w_mm = 36 # blender default
|
||||
sensor_h_mm = sensor_w_mm * RES_Y / RES_X
|
||||
|
||||
fx_px = f_mm * RES_X / sensor_w_mm
|
||||
fy_px = f_mm * RES_Y / sensor_h_mm
|
||||
|
||||
u = RES_X / 2
|
||||
v = RES_Y / 2
|
||||
|
||||
return np.array([[fx_px, 0, u],
|
||||
[0, fy_px, v],
|
||||
[0, 0, 1]], np.float32)
|
||||
|
||||
|
||||
def extrinsic(camLoc):
|
||||
R_w2bc = np.array([[0, 1, 0],
|
||||
[0, 0, 1],
|
||||
[1, 0, 0]], np.float32)
|
||||
|
||||
T_w2bc = -1 * R_w2bc.dot(camLoc)
|
||||
|
||||
R_bc2cv = np.array([[1, 0, 0],
|
||||
[0, -1, 0],
|
||||
[0, 0, -1]], np.float32)
|
||||
|
||||
R_w2cv = R_bc2cv.dot(R_w2bc)
|
||||
T_w2cv = R_bc2cv.dot(T_w2bc)
|
||||
|
||||
return np.concatenate((R_w2cv, T_w2cv[:,None]), axis=1)
|
||||
|
||||
|
||||
def proj(camLoc):
|
||||
return intrinsic().dot(extrinsic(camLoc))
|
||||
|
||||
|
||||
def get_camera(cam, img_size, device):
|
||||
size = np.array(img_size, dtype=np.float32)
|
||||
ext = torch.tensor(extrinsic(cam).astype(np.float32), device=device)
|
||||
K = torch.tensor(intrinsic()[None, :, :], device=device)
|
||||
cameras = cameras_from_opencv_projection(R=ext[None, :, :3], tvec=ext[None, :, 3], camera_matrix=K, image_size=torch.tensor(size[None, :], device=device))
|
||||
return cameras, K
|
||||
|
||||
Reference in New Issue
Block a user