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 belongs our image.
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 belongs our image.
so, here is a simple nearest neighbour classification.
(you'll find though, that it is less accurate, than an SVM or ANN_MLP):
void nearest(const cv::Mat &testData, const vector<cv::Mat> &trainData, int &best, double &mind)
{
mind=DBL_MAX;
best = -1;
for (size_t r=0; r<trainData.size(); r++)
{
double d = norm(testData, trainData[r]);
if (d < mind)
{
mind = d;
best = r;
}
}
}
vector<Mat> trainData = ...
vector<int> trainLabels = ...
Mat testData = ...
int best;
double dist;
nearest(testData, trainData, best, dist);
int predicted = trainLabels[best];
Mat closest = trainData[best];
I am currently working on a project where I have to extract the facial expression from a video. I've extracted the landmarks, now i want to classify the emotions + get the closest image's landmarks. So is there a possibility to do the classification based on the facial landmarks?
Asked: 2016-05-17 09:03:48 -0600
Seen: 776 times
Last updated: May 18 '16
OpenCV DescriptorMatcher matches
Conversion between IplImage and MxArray
Video On Label OpenCV Qt :: hide cvNamedWindows
Problems using the math.h class with OpenCV (c++, VS2012)
How to reduce false positives for face detection
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
this might not be possible.
an SVM does not keep the train data around, all it keeps are the support vectors.
thank you for your answer. can you please tell me what method can i use to solve this problem?
it's not an answer (so far)
an SVM does classification , but your question hints, that you want something slightly different, like finding the 'closest neighbour' ? a simple 'nearest neighbour search' (e.g. comparing all of your train samples to the test one using norm(a,b), and keeping the one with lowest score) would do that, also there's flann::Index
is there a possible way to get the closest neighbour + the class which belongs the image (using the nearest neighbour ) ?
sidenote: do you really need the closest image ? or would any image from the predicted class do?
i need the closest image + which class it belongs