0

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 original imageto extract its keypointskeypointsand 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

Tes3awy
  • 2,166
  • 5
  • 29
  • 51
  • @Dan Mašek Do you have any idea how to do this my super hero ? – Tes3awy Apr 01 '16 at 18:33
  • :D Sorry, not at the moment, I'm occupied with something else. Maybe in a couple of days if noone answers it by then. – Dan Mašek Apr 02 '16 at 00:29
  • @Dan Mašek No problem at all my super hero, but don't forget me :D – Tes3awy Apr 02 '16 at 00:41
  • 1
    [This](https://github.com/dan-masek/OCV_Vehicles_Features) is my current code. I scaled down the input car to make it easier to display the matches. I used the function shown in [this question](http://stackoverflow.com/questions/20259025/module-object-has-no-attribute-drawmatches-opencv-python) to display the matches. I think we should apply a mask to the video image to limit feature matching to the area where cars can occur. Then we need some clustering algorithm. Problem with this algorithm is that it's not idea for detecting multiple similar objects in one frame. – Dan Mašek Apr 04 '16 at 02:00
  • @Dan Mašek I have read something that is called Bag of Words BOW, I am still reading about it, and I think it's easier in classifying the object to be detected – Tes3awy Apr 04 '16 at 20:14
  • @Dan Mašek btw I am using OpenCV 3.1.0-dev now, not OpenCV 2.4.11, because it has more commands than the latter – Tes3awy Apr 05 '16 at 22:49
  • @Dan Mašek I updated the question can you help me, I know this may be annoying to you that I am asking you too much, but you are really so helpful and I trust your solutions, and as you can see, nobody answered me except you – Tes3awy Apr 06 '16 at 23:34

0 Answers0