Mapping 3d Vertex To Pixel Using Pyreder/pyglet/opengl
I'm implementing new algorithm for 3d point estimation using images, and right now I'm trying to test it over 3d virtual models before I'll move to real objects. The algorithm inpu
Solution 1:
I figured out how goes the calculation, I don't know why, but the library pyrender (that uses OpenGL methods), use the inverse matrix of the view matrix I set as an input.
the exact function to set a pixel is:
from numpy.linalg import inv
def map_to_pixel(point3d,w,h,projection,view):
p=projection@inv(view)@point3d.T
p=p/p[3]
p[0]=(w/2*p[0]+w/2) #tranformation from [-1,1] ->[0,width]
p[1]=h-(h/2*p[1]+h/2) #tranformation from [-1,1] ->[0,height] (top-left image)
return p
I have tested the rendered images across this function, and all the vertices have been mapped perfectly into the pixels.
Post a Comment for "Mapping 3d Vertex To Pixel Using Pyreder/pyglet/opengl"