Movatterモバイル変換


[0]ホーム

URL:



Code forSIFT Feature Extraction using OpenCV in Python Tutorial


View on Github

sift.py

import cv2# reading the imageimg = cv2.imread('table.jpg')# convert to greyscalegray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# create SIFT feature extractorsift = cv2.xfeatures2d.SIFT_create()# detect features from the imagekeypoints, descriptors = sift.detectAndCompute(img, None)# draw the detected key pointssift_image = cv2.drawKeypoints(gray, keypoints, img)# show the imagecv2.imshow('image', sift_image)# save the imagecv2.imwrite("table-sift.jpg", sift_image)cv2.waitKey(0)cv2.destroyAllWindows()

feature_match.py

import cv2# read the imagesimg1 = cv2.imread('book.jpg')  img2 = cv2.imread('table.jpg')# convert images to grayscaleimg1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)# create SIFT objectsift = cv2.xfeatures2d.SIFT_create()# detect SIFT features in both imageskeypoints_1, descriptors_1 = sift.detectAndCompute(img1,None)keypoints_2, descriptors_2 = sift.detectAndCompute(img2,None)# create feature matcherbf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)# match descriptors of both imagesmatches = bf.match(descriptors_1,descriptors_2)# sort matches by distancematches = sorted(matches, key = lambda x:x.distance)# draw first 50 matchesmatched_img = cv2.drawMatches(img1, keypoints_1, img2, keypoints_2, matches[:50], img2, flags=2)# show the imagecv2.imshow('image', matched_img)# save the imagecv2.imwrite("matched_images.jpg", matched_img)cv2.waitKey(0)cv2.destroyAllWindows()

Mastering YOLO - Yacine Author - Top


Join 50,000+ Python Programmers & Enthusiasts like you!



Tags

Ethical Hacking with Python EBook - Topic - Middle


New Tutorials

Popular Tutorials


Practical Python PDF Processing EBook - Topic - Bottom







[8]ページ先頭

©2009-2025 Movatter.jp