1 | initial version |
(This is not an answer; it is meant to point out the difficulties in this task.)
I have not actually used the OpenCV stitching library myself; however I studied the algorithms while in school with a MATLAB implementation written by someone else.
This seems to be a case that is difficult to process automatically. A lot of manual work is needed. If you have access to MATLAB it will be easier. If you don't, it is quite difficult, or maybe you'll need to do a lot of math yourself (i.e. pen and paper).
Stitching is usually done when the views contain significant overlap. For example, if there is a sequence of views of a panorama, then it is expected that view 1 and view 2 will overlap significantly; so are view 2 and view 3; and so on. Taken together these views span a large area of the scenery.
One could argue that they can still be stitched together, based on a human's intuition:
Given the above geometrical symmetry, it is sufficient for a 3D geometry or computer vision student to calculate the homography. (A computer algebra or matrix-solving system such as MATLAB may be needed to solve 4x4 matrices, but that's it.)
Unfortunately, this is not the usage scenario that is targeted by the stitching library. The stitching library is focused primarily on point-based correspondence. It is intended to support both automatically-established point correspondence (RANSAC, etc), or manually added point pairs (with a GUI).
The "outside the box" knowledge that a human has of a soccer field cannot be easily described to the point-based correspondence library.
Realize that one can find a transformation matrix between
Projection is involved, so the transformation matrix looks like http://research.microsoft.com/pubs/75695/Szeliski-FnT06.pdf
Also realize that you can set the second quadrilateral anyway you want. For example, if you know the widths and lengths of a real soccer field (e.g. in meters or feet), you can scale these numbers and solve a transformation matrix between the image coordinates and the soccer field coordinates.
Stitching the two images is, thus,