Issue: Bag of Features Training SIFT or SURF for car detection within Video with OpenCV + Python

主宰稳场 提交于 2020-01-01 19:59:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!