'**SUMMARY**
findKeypointMatch allows you to match a template image with another image using
SURF keypoints. The method extracts keypoints from each image, uses the Fast Local
Approximate Nearest Neighbors algorithm to find correspondences between the feature
points, filters the correspondences based on quality, and then, attempts to calculate
a homography between the two images. This homography allows us to draw a matching
bounding box in the source image that corresponds to the template. This method allows
you to perform matchs the ordinarily fail when using the findTemplate method.
This method should be able to handle a reasonable changes in camera orientation and
illumination. Using a template that is close to the target image will yield much
better results.
.. Warning::
This method is only capable of finding one instance of the template in an image.
If more than one instance is visible the homography calculation and the method will
fail.
**PARAMETERS**
* *template* - A template image.
* *quality* - The feature quality metric. This can be any value between about 300 and 500. Higher
values should return fewer, but higher quality features.
* *minDist* - The value below which the feature correspondence is considered a match. This
is the distance between two feature vectors. Good values are between 0.05 and 0.3
* *minMatch* - The percentage of features which must have matches to proceed with homography calculation.
A value of 0.4 means 40% of features must match. Higher values mean better matches
are used. Good values are between about 0.3 and 0.7
**RETURNS**
If a homography (match) is found this method returns a feature set with a single
KeypointMatch feature. If no match is found None is returned.
**EXAMPLE**
>>> template = Image("template.png")
>>> img = camera.getImage()
>>> fs = img.findKeypointMatch(template)
>>> if( fs is not None ):
>>>      fs.draw()
>>>      img.show()
**NOTES**
If you would prefer to work with the raw keypoints and descriptors each image keeps
a local cache of the raw values. These are named:
| self._mKeyPoints # A Tuple of keypoint objects
| self._mKPDescriptors # The descriptor as a floating point numpy array
| self._mKPFlavor = "NONE" # The flavor of the keypoints as a string.
| `See Documentation <http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_feature_detectors.html#keypoint-keypoint>`_
**SEE ALSO**
:py:meth:`_getRawKeypoints`
:py:meth:`_getFLANNMatches`
:py:meth:`drawKeypointMatches`
:py:meth:`findKeypoints`'

def findKeypointMatch(self, template, quality=500.0, minDist=0.2, minMatch=0.4):

    try:
        import cv2
    except:
        warnings.warn("Can't    Match    Keypoints    without    OpenCV    >=    2.3.0")
        return
    if (template == None):
        return None
    fs = FeatureSet()
    (skp, sd) = self._getRawKeypoints(quality)
    (tkp, td) = template._getRawKeypoints(quality)
    if ((skp == None) or (tkp == None)):
        warnings.warn("I    didn't    get    any    keypoints.    Image    might    be    too    uniform    or    blurry.")
        return None
    template_points = float(td.shape[0])
    sample_points = float(sd.shape[0])
    magic_ratio = 1.0
    if (sample_points > template_points):
        magic_ratio = (float(sd.shape[0]) / float(td.shape[0]))
    (idx, dist) = self._getFLANNMatches(sd, td)
    p = dist[:, 0]
    result = ((p * magic_ratio) < minDist)
    pr = (result.shape[0] / float(dist.shape[0]))
    if ((pr > minMatch) and (len(result) > 4)):
        lhs = []
        rhs = []
        for i in range(0, len(idx)):
            if result[i]:
                lhs.append((tkp[i].pt[1], tkp[i].pt[0]))
                rhs.append((skp[idx[i]].pt[0], skp[idx[i]].pt[1]))
        rhs_pt = np.array(rhs)
        lhs_pt = np.array(lhs)
        if ((len(rhs_pt) < 16) or (len(lhs_pt) < 16)):
            return None
        homography = []
        (homography, mask) = cv2.findHomography(lhs_pt, rhs_pt, cv2.RANSAC, ransacReprojThreshold=1.0)
        w = template.width
        h = template.height
        pts = np.array([[0, 0], [0, h], [w, h], [w, 0]], dtype='float32')
        pPts = cv2.perspectiveTransform(np.array([pts]), homography)
        pt0i = (pPts[0][0][1], pPts[0][0][0])
        pt1i = (pPts[0][1][1], pPts[0][1][0])
        pt2i = (pPts[0][2][1], pPts[0][2][0])
        pt3i = (pPts[0][3][1], pPts[0][3][0])
        fs = FeatureSet()
        fs.append(KeypointMatch(self, template, (pt0i, pt1i, pt2i, pt3i), homography))
        return fs
    else:
        return None
