No account yet ?
Tested in Anaconda and Python 3.7
import cv2 as cv import matplotlib.pyplot as plt # Open and convert the input and training-set image from BGR to GRAYSCALE image1 = cv.imread(filename = 'omSjL.jpg', flags = cv.IMREAD_GRAYSCALE) image2 = cv.imread(filename = 'K8vC7.jpg', flags = cv.IMREAD_GRAYSCALE) # Initiate BRISK descriptor BRISK = cv.BRISK_create() # Find the keypoints and compute the descriptors for input and training-set image keypoints1, descriptors1 = BRISK.detectAndCompute(image1, None) keypoints2, descriptors2 = BRISK.detectAndCompute(image2, None) # create BFMatcher object BFMatcher = cv.BFMatcher(normType = cv.NORM_HAMMING, crossCheck = True) # Matching descriptor vectors using Brute Force Matcher matches = BFMatcher.match(queryDescriptors = descriptors1, trainDescriptors = descriptors2) # Sort them in the order of their distance matches = sorted(matches, key = lambda x: x.distance) # Draw first 15 matches output = cv.drawMatches(img1 = image1, keypoints1 = keypoints1, img2 = image2, keypoints2 = keypoints2, matches1to2 = matches[:15], outImg = None, flags = cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS) plt.imshow(output) plt.show()
Source : https://stackoverflow.com/questions/62571115/how-to-implement-brisk-using-python-and-opencv-to-detect-features
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) # BRISK is a feature detector and descriptor # Initiate BRISK detector BRISK = cv.BRISK_create() # Find the keypoints with BRISK keypoints = BRISK.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/BRISK-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 BRISK keypoints, descriptors = BRISK.compute(image, keypoints) # Print the descriptor size in bytes print("Size of Descriptor:", BRISK.descriptorSize(), "\n") # Print the descriptor type print("Type of Descriptor:", BRISK.descriptorType(), "\n") # Print the default norm type print("Default Norm Type:", BRISK.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-BRISK.jpg', arr = image, dpi = 300) # Close it plt.close()
Feature Detection and Description
Copyright (c) 2020 Alexandra Raibolt
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