feature-extractionkeypointcorner-detection

How to extract keypoints from Harris Corner Detector using Opencv


-Having problem with this part (How do i extract the keypoints from above Harris detector)

    std::vector<KeyPoint> keypoints;

Solution

  • Python

    This is a how I wrote it in Python:

    # convert coordinates to Keypoint type
    eye_corner_keypoints = [cv2.KeyPoint(crd[0], crd[1], 13) for crd in eye_corner_coordinates]
    
    # compute SIFT descriptors from corner keypoints
    sift = cv2.xfeatures2d.SIFT_create()
    eye_corner_descriptors = [sift.compute(gray,[kp])[1] for kp in eye_corner_keypoints]
    

    C++

    Looking at the constructor signature in the OpenCV reference documentation for the KeyPoint class:

    KeyPoint (float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1)
    

    It looks like you can iterate through your coordinate points and instantiate your KeyPoint objects at each iteration (roughly) like so:

    for (int i = 0; i < num_points; i++) {
        KeyPoint kp(points_x[i], points_y[i], points_size[i]);
        /* ... */
    

    Warning: code is untested, I'm not a C++ programmer.