I am trying to dump keypoints of cars with SIFT or SURF and match these keypoints to a video in order to detect cars. Keypoints are more convenient to use instead of Haar Cascades because I would have to use a lot of images for example 5000 to train, which will take a lot of computation process. Keypoints from SURF or SIFT are scale invariant which will be almost the same in every car.
The code for dumping keypoints into a txt file is:
import cv2
import numpy as np
import os
import cPickle
surf = cv2.xfeatures2d.SURF_create()
descriptors = []
image = cv2.imread('1.jpg')
kp, dsc = surf.detectAndCompute(image, None)
img = cv2.drawKeypoints(image, kp, image)
descriptors.append(dsc)
des = np.array(descriptors)
k = 5
bow = cv2.BOWKMeansTrainer(k)
cluster = bow.cluster(des)
add = bow.add(dsc)
f = open("descriptors.pkl", "w")
f.write(cPickle.dumps(des))
f.close()
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
after that I don't know how to match these keypoints in the txt file I generated with a video I have, there are many feature matching algorithms as brute force and KNN matcher, and also classifiers as SVM Classifier which will be used as I read in many papers
I tried on this image to extract its keypointsand the keypoints extracted in txt file are in this [GitHub][3] link, with the code and the video I need to detect cars in.
Any idea how to match the keypoints of this car with cars in the video ('traffic.avi').
I want to detect cars using Bag of Visual Words Method, Tried to do so but don't know how to do the coding
Note: I am using OpenCV 3.1 and Python 2.7.x
来源:https://stackoverflow.com/questions/36363397/issue-bag-of-features-training-sift-or-surf-for-car-detection-within-video-with