hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
I have seen these two lines of code in may online forums but I don't understand where the SVM vector comes from, i.e. what was the training data that was used to train this SVM and can I find that data and source code anywhere?
And also why does the SVM vector have a length of 3781 for a 64x128 image?
Some insight into this would be really helpful.
Thanks
Here you are using pre-trained people detector as SVM. You can read about it in the doc. I don't know the way that they trained it (The algorithms, parameters). But according to this answer, it was trained with Daimler Pedestrian Detection Dataset.
cv2.HOGDescriptor_getDefaultPeopleDetector() will return a array with size 3781 in size. Those are coefficients that are used by SVM to classify people. It has nothing to do with the input image that you are using.
And most importantly you can train a SVM as you like to detect another object and use as the SVM detector. Check this answer for more.
Related
It is may be a very simple question. I am searching for a classifier which can be trained using C++ and OpenCV libraries for rail line detection.
Can anybody give a brief idea.
Thanks in advance.
Railway lines can be easier to detect with HOG or SIFT features, given the types of features that they contain. However, I would recommend YOLO 9000. If it already knows how to detect railway tracks, you are in luck. Otherwise, it can be trained with a collection of images.
i'm using opencv SVM and i want to know if it is possible to know which image is closer to our input image instead of the class which the image belongs
Do you mean which training image? Using an SVM, the short answer is no. The SVM builds a model used for classification and it doesn't contain all the training images, just support vectors. Maybe NN is better suited to your problem.
i'm working on a project (using opencv) where i need to accomplish the following:
Train a classifier so that it can detect people in an thermal image.
I decided to use opencv and classify with HOG and SVM.
So far, i have gotten to the point where i can
Load several images, positive and negative samples (about 1000)
extract the HOG Features for each image
Store the features with their label
Train the SVM
Get the SVM Settings (alpha and bias), set it as HOG Descriptor's SVM
Run testing
The Testing is horrible, even worse then the original one with
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
I think i'm doing the HOG Features wrong, bc i compute them for the whole image, but i need them computed on the image part where the person is. So i guess, that i have to crop the images where the Person is, resize it to some window size, train the SVM on classifing those windows and THEN pass it to the HOG Descriptor.
When i test the images directly on the trained SVM, i have observed, that i get almost 100% false positives. I guess this caused by the problem i described earlier.
I'm open for any ideas.
Regards,
hh
After obtaining the image dataset, the feature database is constructed for all images which is a vector based on mean and sd of RGB color model and HSV color model for a portion of the image. How can I use a svm to retieve related images from the database once the query image is given.
Also how to use unsupervised learning for the above problem
Assuming the query images are unlabeled, applying SVM would require a way of knowing the labels for dataset images since SVM is a form of supervised learning, which seeks to correctly determine class labels for unlabeled data. You would need another method for generating class labels, such as unsupervised learning, so this approach does not seem relevant if you only have feature vectors but no class labels.
A neural network allows for unsupervised learning with unlabeled data, but is a rather complex approach and is the subject of academic research. You may want to consider a simpler machine learning approach such as k-Nearest Neighbors, which allows you to obtain the k closest training samples that are similar in your feature space. This algorithm is simple to implement and is found in many machine learning libraries. For example in Python you can use scikit learn.
I am unsure what type of images you are working with, but you might also want to explore using feature detector algorithms such as SIFT rather than just pixel intensities.
I have been looking into training/using OpenCV to attempt to detect human figures. I want to try training a HOG for my specific purposes and not use the provided getDefaultPeopleDetector function. I have been unable to find any usable documentation on the HOGDescriptor class.
How do I train my own classifier for my own purposes?
HOG descriptor is very easy to implement. You can write your own code to do it. Look at http://smsoftdev-solutions.blogspot.com/2009/08/integral-histogram-for-fast-calculation.html.
It is fast implementation of HOG. Once you get HOG features of all the training images.You can train an SVM in OpenCV. Training with Gaussian Kernel has produced good results.