Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

(This is not an answer; it is meant to point out the difficulties in this task.)


Disclaimer.

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.


My view of the situation.

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).


Problem 1 - too little overlap between the two views.

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.


Problem 2 - using geometrical symmetry instead of point correspondence.

One could argue that they can still be stitched together, based on a human's intuition:

  • The midfield line (and geometrically, the two endpoints that mark the line segment) is visible in both images.
  • Two of the four corners of the field appear in each image.
  • Straight lines can be drawn so that the corners and the endpoints of the midfield line form straight lines.
  • These straight lines are either parallel or perpendicular to each other.

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.


Solving the problem with human insight.

Realize that one can find a transformation matrix between

  • A quadrilateral ( (x11, y11), (x12, y12), (x21, y21), (x22, y22) ) lying on a 2D plane, and
  • Another quadrilateral ( (u11, v11), (u12, v12), (u21, v21), (u22, v22) ) lying on another 2D plane.

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,

  • Transform the soccer field as seen on the first image so that the left side of the soccer field becomes a rectangle. The rectangle shall have the same aspect ratio as one-half of a real soccer field.
  • Likewise, transform the soccer field as seen on the second image so that the right side of the soccer field becomes the rectangle. Use the same widths and heights.
  • Just put these two images side by side.