Using SVM and BOW for image classification OpenCV - c++

Im trying to implement an image classification program using the BoW to create the visual library and classify using SVM. Now I have done the Bow part and I'm kinda stuck with the SVM training part.
This is what I have coded so far.
1) Extract (detect and describe) features from training images. (I have 4 classes of images)
2) Build a unclustered matrix of all features of the training images
3) Use k-mean clustering to cluster the data into bags (BoW)
5) Save the visual library in YML format for accessing by the SVM predictor
4) Build a BoW descriptor incorporated with SIFT and FLANN to extract features from the test image
5) Build SVM classifier
No my question is how to train the SVM classifier before I proceed with actual prediction.
According OpenCV 3.1 (not 2.4) class reference for SVM,
We can train the classifier using the trainAuto() member function. In order to create the data for training we have to use the one of following member functions.
Now having said that, I prefer to use the Train::create function to create the training data. What are the arguments of TrainData::create() member function. How do I build these arguments for my case where training images are all in the same directory separated by folders. What do arguments layout, responses, varldx, sampleldx, sampleWeights and varType mean? Sorry if I'm asking a basic question. Im new to openCv and I don't find sufficient help for the OpenCV 3.1 on the internet. All the materials I find are related to OpenCV 2.4. OpenCV 3.1 is big overhaul compared to the former version. Furthermore the documentation for 3.1 is in beta stage and does not help much either. Thank you. Any help is appreciated.

Related

Image classification using SVM

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.

Real-time object tracking in OpenCV

I have written an object classification program using BoW clustering and SVM classification algorithms. The program runs successfully. Now that I can classify the objects, I want to track them in real time by drawing a bounding rectangle/circle around them. I have researched and came with the following ideas.
1) Use homography by using the train set images from the train data directory. But the problem with this approach is, the train image should be exactly same as the test image. Since I'm not detecting specific objects, the test images are closely related to the train images but not essentially an exact match. In homography we find a known object in a test scene. Please correct me if I am wrong about homography.
2) Use feature tracking. Im planning to extract the features computed by SIFT in the test images which are similar to the train images and then track them by drawing a bounding rectangle/circle. But the issue here is how do I know which features are from the object and which features are from the environment? Is there any member function in SVM class which can return the key points or region of interest used to classify the object?
Thank you

How to extract LBP features from a hand contour using opencv c++

I am currently working on a hand recognition system. I have been able to detect the hand and draw a contour for it. Now, I have to extract features from the hand region. What is the best feature extraction method that i can use?
I was thinking to use Local Binary Pattern, but since i am new to computer vision i don't know how to use it.
Perhaps you must look at histogram of gradients (HOG), which can be considered as a more general version of LBP. You can have multiple images of hands; by extracting HOG features from each image and using an SVM or neural network classifier, you can learn a statistical model of hand poses. This will help in recognizing an unseen hand. Look also at the current literature on deep learning.
A C++ implementation of HOG is available from vlfeat library [1], which can be called from OpenCV. HOG can be computer from OpenCV also [2].
[1] http://www.vlfeat.org/overview/hog.html
[2] http://goo.gl/8jTetR

Object Annotation in images with OpenCV

I am trying to develop an automatic(or semi-automatic) image annotator for my final year project with OpenCV. I have been studying many OpenCV resources and have come across cascade classification for training and detection purposes. I understood that part, and also tried the Face Detection tutorial provided with OpenCV. So, now I know how to train and detect objects.
However, I still cannot understand how can I annotate objects present in the image?
For example, the system will show that this is an object, but I want the system to show that it is a ball. How can i accomplish that?
Thanks in advance.
One binary classificator (detector) can separate objects by two classes:
positive - the object type classifier was trained for,
and negative - all others.
If you need detect several distinguished classes you should use one detector for each class, or you can train multiclass classifier ("one vs all" type of classifiers for example), but it usually works slower and with less accuracy (because detector better search for similar objects). You can also take a look at convolutional networks (by Yann LeCun).
This is a very hard task. I suggest simplifying it by using latent SVM detector and limiting yourself to the models it supplies:
http://docs.opencv.org/modules/objdetect/doc/latent_svm.html

SVM (Support Vector Machine) opencv

I'm new to machine learning. I'm doing a project by using opencv open source library. My issue is that I don't have experience in Machine Learning. I have extracted features from different images and I have evaluated them, now I want to classify objects in those images by using SVM but I don't know what to do. BTW, I used 3 different feature extractors, SIFT, SURF and FAST feature detector (with their descriptors)
Can you give me the guide and some examples to classify more than 5 objects in the background, such as coffee cups, coca cola, basket balls etc...
I'm doing my project in C++, environment (UBUNTU).
With the information provided, all I can give you is the following list:
category-level classification tutorial from the CVML2011 summer school. It includes code (for you unfortunately in Matlab) which can help you to understand the concept behind it.
paper called "A Practical Guide to Support Vector Classification" which clearly explains how to prepare the data, train and test SVM
and of course the OpenCV documentation on svm training
As already pointed out by #jillesdewit you should try to be more specific.