程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Sift key point detection and feature matching (implemented in Python)

編輯:Python

List of articles

    • 1.Harris and Shi-Tomasi feature detection
    • 2.SIFT(Scale-Invariant Feature Transform) Key point detection
    • 3.SIFT Using process
      • (1) establish SIFT object
      • (2) To test ,( Key points )KP=sift.detect(img,……)
      • (3) Draw key points ,drawKeypoints(gray,KP,img)
    • 4. Code combat
    • 5. Feature matching
      • (1) Mode one : Key match
      • (2) Mode two : Key match

1.Harris and Shi-Tomasi feature detection

Harris: https://blog.csdn.net/Keep_Trying_Go/article/details/125384144
Shi-Tomasi:https://blog.csdn.net/Keep_Trying_Go/article/details/125384218


2.SIFT(Scale-Invariant Feature Transform) Key point detection

reflection : Given the Harris Corner detection , Why SIFT Key point detection ?
(1)Harris The corner has the property of rotation invariance ; But after zooming , The original corner may not necessarily be a corner ;

You can see that when the corners of the first picture are enlarged , It becomes the second picture , But when we go to the test again, we can't detect any corners , It's the edge . So I put forward SIFT.


3.SIFT Using process

(1) establish SIFT object

(2) To test ,( Key points )KP=sift.detect(img,……)

(3) Draw key points ,drawKeypoints(gray,KP,img)

among gray—— original image , Three channel or single channel images can be made ;KP—— Key points ;img—— Draw points onto the original image ;color—— Color information of the drawn feature points , The default drawing is random color ;
Flags——
(1)cv2.DRAW_MATCHES_FLAGS_DEFAULT: Create output image matrix , Draw matching pairs and feature points using existing output images , Draw only the middle point for each key
(2)cv2.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG: Do not create output image matrix , Instead, draw matching pairs on the output image
(3)cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS: Draw a key point graph with size and direction for each feature point
(4)cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS: The feature points of a single point are not drawn


4. Code combat

import os
import cv2
import cv2
img=cv2.imread('images/HaLiSi.jpg')
img=cv2.resize(src=img,dsize=(450,450))
gray=cv2.cvtColor(src=img,code=cv2.COLOR_BGR2GRAY)
#SIFT objects creating 
sift=cv2.SIFT_create()
# To test , The second parameter is None, Indicates to test the whole picture 
kp=sift.detect(gray,None)
# Draw corners 
cv2.drawKeypoints(image=gray,keypoints=kp,outImage=img,color=(0,255,0))
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
print('pycharm')


5. Feature matching

(1) Key points : Location , Size and direction ;
Calculation SIFT Narrator :
(2) A set of vector values of the pixels around the key that contribute to it are recorded , It is not subject to affine transformation , The influence of light transformation, etc .

(1) Mode one : Key match

 Key match :
# Mode one : Feature matching 
kp,des=sift.compute(img,kp)
import os
import cv2
import numpy as np
img=cv2.imread('images/HaLiSi.jpg')
img=cv2.resize(src=img,dsize=(450,450))
gray=cv2.cvtColor(src=img,code=cv2.COLOR_BGR2GRAY)
#SIFT objects creating 
sift=cv2.SIFT_create()
# To test , The second parameter is None, Indicates to test the whole picture 
kp=sift.detect(gray,None)
# Feature matching 
kp,des=sift.compute(gray,kp)
print(des)
# kp,des=sift.detectAndCompute(gray)
# Draw corners 
cv2.drawKeypoints(image=gray,keypoints=kp,outImage=img,color=(0,255,0))
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
print('Pycharm')

(2) Mode two : Key match

At the same time, key point detection and feature matching
Kp,des=sift.detectAndCompute(img,None)
Img: Input image ( grayscale );
Mask: Appoint img Which area in the .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved