我想检测两个连续视频帧(当前帧和前一帧)的特征点。为此,我使用SIFT和强力算法提取匹配的关键点。现在我只想将匹配的关键点转换为当前帧和他们的位置和大小。我怎样才能做到这一点 ?有没有具体的功能呢?非常感谢您的帮助
下面是我目前的代码:
import cv2
import numpy as np
cap = cv2.VideoCapture('video3.mov')
ret, frame = cap.read()
while(cap.isOpened()):
prev_frame=frame[:]
ret, frame = cap.read()
if ret:
graycurrent = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
grayprev = cv2.cvtColor(prev_frame, cv2.COLOR_BGR2GRAY)
#detect key feature points
sift = cv2.xfeatures2d.SIFT_create()
#kp = sift.detect(graycurrent, None)
kp1, des1 = sift.detectAndCompute(graycurrent, None)
#draw key points detected
img1 = cv2.drawKeypoints(graycurrent, kp1,graycurrent, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
kp2, des2 = sift.detectAndCompute(grayprev, None)
#draw key points detected
img2 = cv2.drawKeypoints(grayprev, kp2,grayprev, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# BFMatcher with default params
bf = cv2.BFMatcher(normType=cv2.NORM_L2, crossCheck= True)
matches = bf.match(des1,des2)
cv2.imshow("grayframe",img1)
cv2.imshow("prevFrame",img2)
else:
print("could not read the frame")
if cv2.waitKey(100) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()