Does anyone have any examples of using OpenCV with python for descriptor extraction?

后端 未结 4 1268
夕颜
夕颜 2021-02-04 05:22

I\'m trying to use OpenCV to extract SURF descriptors from an image. I\'m using OpenCV 2.4 and Python 2.7, but am struggling to find any documentation that provides any informat

4条回答
  •  走了就别回头了
    2021-02-04 06:10

    Here is a simple bit of code I did for uni fairly recently. It captures the image from a camera and displays the detected keypoints on the output image in real-time. I hope it is of use to you.

    There is some documentation here.

    Code:

    import cv2
    
    #Create object to read images from camera 0
    cam = cv2.VideoCapture(0)
    
    #Initialize SURF object
    surf = cv2.SURF(85)
    
    #Set desired radius
    rad = 2
    
    while True:
        #Get image from webcam and convert to greyscale
        ret, img = cam.read()
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
        #Detect keypoints and descriptors in greyscale image
        keypoints, descriptors = surf.detect(gray, None, False)
    
        #Draw a small red circle with the desired radius
        #at the (x, y) location for each feature found
        for kp in keypoints:
            x = int(kp.pt[0])
            y = int(kp.pt[1])
            cv2.circle(img, (x, y), rad, (0, 0, 255))
    
        #Display colour image with detected features
        cv2.imshow("features", img)
    
        #Sleep infinite loop for ~10ms
        #Exit if user presses 
        if cv2.waitKey(10) == 27:
            break
    

提交回复
热议问题