这是我最近为uni做的一小段代码。它从摄像机捕获图像,并在输出图像上实时显示检测到的关键点。希望对您有用。
还有一些文档在这里 。
码:
import cv2
#Create object to read images from camera 0
cam = cv2.VideoCapture(0)
#Initialize SURF object
surf = cv2.SURF(85)
#Set desired radius
rad = 2
while True:
#Get image from webcam and convert to greyscale
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#Detect keypoints and descriptors in greyscale image
keypoints, descriptors = surf.detect(gray, None, False)
#Draw a small red circle with the desired radius
#at the (x, y) location for each feature found
for kp in keypoints:
x = int(kp.pt[0])
y = int(kp.pt[1])
cv2.circle(img, (x, y), rad, (0, 0, 255))
#Display colour image with detected features
cv2.imshow("features", img)
#Sleep infinite loop for ~10ms
#Exit if user presses <Esc>
if cv2.waitKey(10) == 27:
break
0
我正在尝试使用OpenCV从图像中提取SURF描述符。我正在使用OpenCV 2.4和Python 2.7,但一直在努力寻找任何提供有关如何使用功能的信息的文档。我已经能够使用以下代码来提取特征,但是我找不到任何明智的方法来提取描述符:
我尝试提取描述符的代码是:
有人有做这种事情的示例代码,还是提供示例的任何文档的指针?