Logo elodees  elodees

A caring AI for a better world













Only alphabetic characters accented or not as well as the space are accepted

Logo IA




SURF Feature Detection





No account yet ?

Sign up to access all content




Feature Detection and Matching

License: MITLicenseMIT  Copyright (c) 2020 Alexandra Raibolt


GitHub



Free image provided by pexel.com
Free image provided by pexel.com




Free image provided by pexel.com




Tested in Anaconda and Python 3.7

# Imports
from matplotlib import pyplot as plt
import cv2 as cv
import numpy as np
import os
import pickle
 
# Open and convert a input
# image from BGR to GRAYSCALE
image = cv.imread(filename = 'Figures/pexels-bestbe-models-2412691.jpg',
                   flags = cv.IMREAD_GRAYSCALE)
 
# SURF is a feature detector and descriptor

# Initiate SURF detector
SURF = cv.xfeatures2d.SURF_create()
 
 # Find the keypoints with SURF
keypoints = SURF.detect(image, None)
 
# Print number of keypoints detected
print("Number of keypoints Detected:", len(keypoints), "\n")
 
# Save Keypoints to a file

index = []
 
for point in keypoints:
    temp = (point.pt,
            point.size,
            point.angle,
            point.response,
            point.octave, 
            point.class_id)
 
    index.append(temp)
 
# File name
filename = "Outputs/SURF-keypoints.txt"
 
# Delete a file if it exists
if os.path.exists(filename):
    os.remove(filename)
 
# Open a file
file = open(filename, "wb")
 
# Write 
file.write(pickle.dumps(index))
 
# Close a file
file.close()
 
# Compute the descriptors with SURF
keypoints, descriptors = SURF.compute(image, keypoints)
 
# Print the descriptor size in bytes
print("Size of Descriptor:", SURF.descriptorSize(), "\n")
 
# Print the descriptor type
print("Type of Descriptor:", SURF.descriptorType(), "\n")
 
# Print the default norm type
print("Default Norm Type:", SURF.defaultNorm(), "\n")
 
# Print shape of descriptor
print("Shape of Descriptor:", descriptors.shape, "\n")
 
# Draw only 50 keypoints on input image
image = cv.drawKeypoints(image = image,
                         keypoints = keypoints[:50],
                         outImage = None,
                         flags = cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
 
# Plot input image

# Turn interactive plotting off
plt.ioff()
 
# Create a new figure
plt.figure()
plt.axis('off')
plt.imshow(image)
plt.show()
 
plt.imsave(fname = 'Figures/feature-detection-SURF.jpg',
           arr = image,
           dpi = 300)
 
# Close it
plt.close()
 


Feature Detection and Description

License: MITLicenseMIT  Copyright (c) 2020 Alexandra Raibolt


GitHub



Free image provided by pexel.com
Free image provided by pexel.com








Image features


Computer vision


Deep learning

Machine learning












Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !

Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License