@geopavlakos @dimtzionas @vchoutas @MichaelJBlack @nghorbani Dears,When I finish the fitting, I print the camera parameter like:
So I write a code like this
"
def get_camera_intrinsic(focal_length, camera_center):
K = np.array([
[focal_length, 0, camera_center[0]],
[0, focal_length, camera_center[1]],
[0, 0, 1]
], dtype=np.float32)
return K
print(projected_points_2d)
color = (0, 0, 255) # BGR格式
对每个二维点进行绘制
img = cv2.imread("../DATA_FOLDER/images/01_img.jpg")
for point in projected_points_2d.astype(int):
cv2.circle(img, tuple(point), radius=1, color=color, thickness=-1) # thickness=-1 表示填充圆
cv2.imwrite('projected_points_cv2.png', img)
"
But I get result like this:
@geopavlakos @dimtzionas @vchoutas @MichaelJBlack @nghorbani Dears,When I finish the fitting, I print the camera parameter like:![image](https://github.com/vchoutas/smplify-x/assets/9246739/35851af8-d4bf-40b7-a5c9-09e3e7914299)
So I write a code like this " def get_camera_intrinsic(focal_length, camera_center): K = np.array([ [focal_length, 0, camera_center[0]], [0, focal_length, camera_center[1]], [0, 0, 1] ], dtype=np.float32) return K
def project_points(mesh_points, camera_transl, camera_intrinsic): R = np.eye(3) t = camera_transl.reshape(3, 1) T = np.hstack((R, t)) ones = np.ones((mesh_points.shape[0], 1)) homogenous_points = np.hstack((mesh_points, ones)) camera_points = homogenous_points.dot(T.T) projected_points = camera_points.dot(camera_intrinsic.T) projected_points_2d = projected_points[:, :2] / projected_points[:, 2, np.newaxis] return projected_points_2d[:, :2] # 只取x, y坐标
相机参数
camera_center = np.array([800., 600.], dtype=np.float32) camera_transl = np.array([-0.04409692, 0.26306236, 8.006923], dtype=np.float32) focal_length = 5000.0 K = get_camera_intrinsic(focal_length, camera_center) out_mesh = trimesh.load_mesh("../OUTPUT_FOLDER/meshes/01_img/000.obj") mesh_points = np.array(out_mesh.vertices)
投影三维点到二维
projected_points_2d = project_points(mesh_points, camera_transl, K) projected_points_2d[:, 1] = H - 1 - projected_points_2d[:, 1]
打印投影结果
print(projected_points_2d) color = (0, 0, 255) # BGR格式
对每个二维点进行绘制
img = cv2.imread("../DATA_FOLDER/images/01_img.jpg") for point in projected_points_2d.astype(int): cv2.circle(img, tuple(point), radius=1, color=color, thickness=-1) # thickness=-1 表示填充圆 cv2.imwrite('projected_points_cv2.png', img) " But I get result like this:![projected_points_cv2](https://github.com/vchoutas/smplify-x/assets/9246739/43e56838-cbcb-4212-a4f3-80d169b1da56)
What is wrong? Can u help me to fix my code?