Camera Calculation for an odd situation

Hello,
It is far out of my math skills, currently I have four points on a plane, which can make a quads(not a rect or square). I wanna know if I can find a perspective camera which have exactly the image in it. I’ll give an for instance since my English is not cool enough. Here is the four random points on a picture:

And I want to find a perspective camera which can give me a rect view like this:
55621-target.jpg
I’ve searched on the internet and there is few solution for question like how to calculate the camera position and field of view. Will be cool if you can give me some advise or just a way how to do this. Thanks very much!

Like @tanoshimi said it’ not possible to just adjust the projection matrix to get that view from the current camera position. It is even almost possible to calculate a camera position and rotation so that the cameras 4-corner-rays go through the 4 specified points since not every convex possible trapezoid represents a plane intersection with the viewing frustum.

There are endless trapezoids which never form a rectangle no matter from where you view it. For example this one.

The next problem is apart from the trapezoid problem (just guess you calculate the closest one that form a rectangle) is that you specifying points in 2d but it when you change the cameras position and rotation to make it match that trapezoid it matters where in the 3d space those points are defined. For example if you imagine them to be on the near clipping plane of the original camera the camera won’t view the book but aim somewhere above it. If the points are on the far clipping plane the camera would be way below the book. So the positions of the points need to be placed around the object you actually want to see.

So far that’s the possibilities for camera adjustments. Another way is to render your original camera image to a render texture and simply render a fullscreen quad with those points as uv parameters. That way you get the distortion you might be looking for.

If the quality is too bad because the area you want to show is just a tiny fraction of the actual render texture, you could adjust the camera rotation and field of view to enclose those for points as best as possible. That way your render texture has almost the actual resolution as your selected pseudo view.

The rectangle you want to view would be simply the screen space bounding box of your 4 points. So simply min / max all coordinates.

If I understand your question correctly, what you’re asking is impossible. (not for Unity, but just generally mathematically!).
It is not possible to define a unique perspective camera that would distort an arbitrary quad to fit into a rectangular frame - perspective cameras “distort” features based on standard optic calculations using the camera’s field of view/aspect ratio - they do not apply an arbitrary skew/shear. So, while it’s easy to define a perspective camera that would encompass the four points chosen, it would not distort the image in the way you have shown.

To do that, you would have to do some manipulation of the way in which the texture is mapped, as @saschandroid has already commented.