Camera UV mapping

Good night people,

is there any way to create a camera-based UV map for an object? Below is an example of the default mapping for a cube and on its right the form I would like to map.

I even have an idea, but I also do not know if it’s possible to do it. Is there any way to create the UV mapping from the vertices of a mesh via script? If yes I could use the WorldToScreen function to map the vertices the same way they appear in the camera.