import cv2, os
import numpy as np
import matplotlib.pyplot as plt
# INITIALISATION
filename = os.path.join('foo', 'bar.jpg')
img0 = cv2.imread(filename) # original image
gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
f, (ax1, ax2) = plt.subplots(1, 2) # create subplots
# DETECT AND DRAW KEYPOINTS
# sift.detect() returns a list of keypoints
# keypoint is a standard class of opencv (not just SIFT-related)
kp = sift.detect(gray,None) # calculates SIFT points
img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
ax1.imshow(img1) # plot
# RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
# Reade these and make numpy array
pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
cols = pts[:,0]
rows = pts[:,1]
ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
ax2.scatter(cols, rows)
plt.show()
7条答案
按热度按时间b09cbbtk1#
point.pt is a tuple
(x,y)'的关系。所以,
或者,
sq1bmfud2#
OpenCV为此提供了一个函数,您可以运行:
c9x0cxw03#
您可以使用:
pts
将是关键点的array
。lh80um4z4#
Read the docs.
类关键点
显著点检测器的数据结构。
所以
point.pt
是一个点2f。尝试
x,y= point.pt
hyrbngr75#
下面是我的建议(可运行代码):
hsgswve46#
我就这样解决了你的问题。
现在,您将获得图像中所有关键点的x,y坐标列表。
3z6pesqy7#
为了得到光流输入的正确形状,我使用了上述方法的组合