next up previous contents
Next: Computing a 2D affine Up: Computing a homography between Previous: Computing a homography between   Contents

Computing a 2D homography from an array of feature matches

The above routines are designed for incremental computation of the homography $P$ as more point/line feature matches become available. An alternative is to store all the feature matches in an array of match structures; indeed the array can in practice be the result of feature matching. The match structure defined here has the same match options as the above routines, encapsulated into the following enumerated type.
      /* type of matching feature when computing 2D homography */
      typedef enum { GAN_HOMOG33_POINT, /* Match scene point to image point */
                     GAN_HOMOG33_LINE, /* Match scene line to image line */
                     GAN_HOMOG33_LINE_ENDPOINTS, /* Match scene line endpoints to
                                                    image line */
                     GAN_HOMOG33_IGNORE } /* rejected match */
where GAN_HOMOG33_IGNORE denotes a match that has been rejected. The match structure contains the details of the match:
      /* structure to hold details of scene and image data to be used in
       * computing 2D homographies
      typedef struct
         Gan_Homog33MatchType type;
            struct { Gan_Vector3 X, x; } p; /* point --> point match */
            struct { Gan_Vector3 L, l; } l; /* line --> line match */
            struct { Gan_Vector3 X1, X2, l; } le; /* line endpoints --> line match */
         } d;
      } Gan_Homog33Match;
Given an array of the Gan_Homog33Match structures, you can compute the homography from scene to image by calling
      Gan_Homog33Match *aMatch;
      unsigned uiNoMatches;
      Gan_Matrix33 m33P;

      /* ... create and fill array of matches, set uiNoMatches to the number
             of structures in the array ... */

      /* fit projective 2D homography */
      gan_homog33_fit ( aMatch, uiNoMatches, &m33P );

Error detection: gan_homog33_fit() returns a boolean value; hence GAN_FALSE is returned on error and the Gandalf error handler is invoked.