Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data explaination #205

Open
013292 opened this issue May 23, 2023 · 0 comments
Open

Data explaination #205

013292 opened this issue May 23, 2023 · 0 comments

Comments

@013292
Copy link

013292 commented May 23, 2023

image
I've replicated the result mesh and saved it as a .vtp 3d model.
Now I'm trying to do the projection with these parameters to see if the projection could fit the 2d image.
But I cannot get the correct projection:
image
Here is my way to do the projection:

reader = vtk.vtkSTLReader()
reader.SetFileName('data/lego.stl')
reader.Update()
# Get the 3D points
polydata = reader.GetOutput()
points = np.asarray(polydata.GetPoints().GetData())
points_homog_0 = np.hstack((points, np.ones((len(points), 1))))

para = json_read('data/transforms_train.json')
view_angle = np.rad2deg(para['camera_angle_x'])
frame = para['frames'][0]
extrinsic_matrix = np.linalg.inv(frame['transform_matrix'])
extrinsic_matrix = extrinsic_matrix

pic_size = 800
focal_length = (1 / 2) / np.tan(np.radians(view_angle / 2))
intrinsic_matrix = np.array([[focal_length * pic_size, 0, pic_size / 2, 0],
                             [0, focal_length * pic_size, pic_size / 2, 0],
                             [0, 0, 1, 0],
                             [0, 0, 0, 1]])

project_matrix = intrinsic_matrix @ extrinsic_matrix
points_homog = np.dot(project_matrix, points_homog_0.T).T
points_proj = points_homog[:, :2] / points_homog[:, 2:3]

fig, ax = plt.subplots(1, 1)
image = np.asarray(Image.open('data/r_0.png'))
ax.imshow(image)
ax.scatter(points_proj[:, 0], points_proj[:, 1], s=0.1, c='r')
plt.show()

I'm confused about the meaning of each item in the .json, could you please give me a hint?
Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant