'.. _getRawKeypoints:
This method finds keypoints in an image and returns them as the raw keypoints
and keypoint descriptors. When this method is called it caches a the features
and keypoints locally for quick and easy access.
Parameters:
min_quality - The minimum quality metric for SURF descriptors. Good values
range between about 300.00 and 600.00
flavor - a string indicating the method to use to extract features.
A good primer on how feature/keypoint extractiors can be found here:
http://en.wikipedia.org/wiki/Feature_detection_(computer_vision)
http://www.cg.tu-berlin.de/fileadmin/fg144/Courses/07WS/compPhoto/Feature_Detection.pdf
"SURF" - extract the SURF features and descriptors. If you don\'t know
what to use, use this.
See: http://en.wikipedia.org/wiki/SURF
"STAR" - The STAR feature extraction algorithm
See: http://pr.willowgarage.com/wiki/Star_Detector
"FAST" - The FAST keypoint extraction algorithm
See: http://en.wikipedia.org/wiki/Corner_detection#AST_based_feature_detectors
All the flavour specified below are for OpenCV versions >= 2.4.0 :
"MSER" - Maximally Stable Extremal Regions algorithm
See: http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions
"Dense" - Dense Scale Invariant Feature Transform.
See: http://www.vlfeat.org/api/dsift.html
"ORB" - The Oriented FAST and Rotated BRIEF
See: http://www.willowgarage.com/sites/default/files/orb_final.pdf
"SIFT" - Scale-invariant feature transform
See: http://en.wikipedia.org/wiki/Scale-invariant_feature_transform
"BRISK" - Binary Robust Invariant Scalable Keypoints
See: http://www.asl.ethz.ch/people/lestefan/personal/BRISK
"FREAK" - Fast Retina Keypoints
See: http://www.ivpe.com/freak.htm
Note: It\'s a keypoint descriptor and not a KeyPoint detector. SIFT KeyPoints
are detected and FERAK is used to extract keypoint descriptor.
highQuality - The SURF descriptor comes in two forms, a vector of 64 descriptor
values and a vector of 128 descriptor values. The latter are "high"
quality descriptors.
forceReset - If keypoints have already been calculated for this image those
keypoints are returned veresus recalculating the values. If
force reset is True we always recalculate the values, otherwise
we will used the cached copies.
Returns:
A tuple of keypoint objects and optionally a numpy array of the descriptors.
Example:
>>> img = Image("aerospace.jpg")
>>> kp,d = img._getRawKeypoints()
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
See: http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_feature_detectors.html#keypoint-keypoint
self._mKPDescriptors # The descriptor as a floating point numpy array
self._mKPFlavor = "NONE" # The flavor of the keypoints as a string.
See Also:
ImageClass._getRawKeypoints(self,thresh=500.00,forceReset=False,flavor="SURF",highQuality=1)
ImageClass._getFLANNMatches(self,sd,td)
ImageClass.findKeypointMatch(self,template,quality=500.00,minDist=0.2,minMatch=0.4)
ImageClass.drawKeypointMatches(self,template,thresh=500.00,minDist=0.15,width=1)'

def _getRawKeypoints(self, thresh=500.0, flavor='SURF', highQuality=1, forceReset=False):

    try:
        import cv2
        ver = cv2.__version__
        new_version = 0
        if (not ver.startswith('$Rev:')):
            if (int(ver.replace('.', '0')) >= 20400):
                new_version = 1
    except:
        warnings.warn("Can't    run    Keypoints    without    OpenCV    >=    2.3.0")
        return (None, None)
    if forceReset:
        self._mKeyPoints = None
        self._mKPDescriptors = None
    _detectors = ['SIFT', 'SURF', 'FAST', 'STAR', 'FREAK', 'ORB', 'BRISK', 'MSER', 'Dense']
    _descriptors = ['SIFT', 'SURF', 'ORB', 'FREAK', 'BRISK']
    if (flavor not in _detectors):
        warnings.warn('Invalid    choice    of    keypoint    detector.')
        return (None, None)
    if ((self._mKeyPoints != None) and (self._mKPFlavor == flavor)):
        return (self._mKeyPoints, self._mKPDescriptors)
    if hasattr(cv2, flavor):
        if (flavor == 'SURF'):
            detector = cv2.SURF(thresh, 4, 2, highQuality, 1)
            if (new_version == 0):
                (self._mKeyPoints, self._mKPDescriptors) = detector.detect(self.getGrayNumpy(), None, False)
            else:
                (self._mKeyPoints, self._mKPDescriptors) = detector.detectAndCompute(self.getGrayNumpy(), None, False)
            if (len(self._mKeyPoints) == 0):
                return (None, None)
            if (highQuality == 1):
                self._mKPDescriptors = self._mKPDescriptors.reshape(((-1), 128))
            else:
                self._mKPDescriptors = self._mKPDescriptors.reshape(((-1), 64))
        elif (flavor in _descriptors):
            detector = getattr(cv2, flavor)()
            (self._mKeyPoints, self._mKPDescriptors) = detector.detectAndCompute(self.getGrayNumpy(), None, False)
        elif (flavor == 'MSER'):
            if hasattr(cv2, 'FeatureDetector_create'):
                detector = cv2.FeatureDetector_create('MSER')
                self._mKeyPoints = detector.detect(self.getGrayNumpy())
    elif (flavor == 'STAR'):
        detector = cv2.StarDetector()
        self._mKeyPoints = detector.detect(self.getGrayNumpy())
    elif (flavor == 'FAST'):
        if (not hasattr(cv2, 'FastFeatureDetector')):
            warnings.warn('You    need    OpenCV    >=    2.4.0    to    support    FAST')
            return (None, None)
        detector = cv2.FastFeatureDetector(int(thresh), True)
        self._mKeyPoints = detector.detect(self.getGrayNumpy(), None)
    elif hasattr(cv2, 'FeatureDetector_create'):
        if (flavor in _descriptors):
            extractor = cv2.DescriptorExtractor_create(flavor)
            if (flavor == 'FREAK'):
                if (new_version == 0):
                    warnings.warn('You    need    OpenCV    >=    2.4.3    to    support    FAST')
                flavor = 'SIFT'
            detector = cv2.FeatureDetector_create(flavor)
            self._mKeyPoints = detector.detect(self.getGrayNumpy())
            (self._mKeyPoints, self._mKPDescriptors) = extractor.compute(self.getGrayNumpy(), self._mKeyPoints)
        else:
            detector = cv2.FeatureDetector_create(flavor)
            self._mKeyPoints = detector.detect(self.getGrayNumpy())
    else:
        warnings.warn("SimpleCV    can't    seem    to    find    appropriate    function    with    your    OpenCV    version.")
        return (None, None)
    return (self._mKeyPoints, self._mKPDescriptors)
