OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 20 Dec 2015 16:39:12 -0600EMD function returning many zeros valueshttp://answers.opencv.org/question/79896/emd-function-returning-many-zeros-values/ I'm using the function in my application with the CV_DIST_L2, and I need to compare many vectors of characteristics. I know that they are much different because I used others functions to compare, but using the EMD is returning many zero values, I'm comparing about 1 million of images. If I need to rank 10 images by the distance it is very bad because of the zero values, it is normal? For example if I have one image and I need to compare with the others 1 million, for to find the 10 more similar, may be I can't find nor the query image because of the zeros values.
char metricname[10] = "EMD";
class EarthMoversMetricEvaluator : public stBasicMetricEvaluator < tBasicArrayObject > {
public:
virtual stDistance GetDistance(tBasicArrayObject * o1, tBasicArrayObject * o2) {
this->UpdateDistanceCount();
int dim = o1->GetSize();
Mat sig1(dim, 2, CV_32FC1);
Mat sig2(dim, 2, CV_32FC1);
for (unsigned int a = 0; a < dim; a++) {
sig1.at<float>(a, 0) = o1->Get(a);
sig1.at<float>(a, 1) = a;
sig2.at<float>(a, 0) = o2->Get(a);
sig2.at<float>(a, 1) = a;
}
double d = EMD(sig1, sig2, CV_DIST_L2);
return d;
}
virtual stDistance GetDistance2(tBasicArrayObject * o1, tBasicArrayObject * o2) {
stDistance d = GetDistance(o1, o2);
return d*d;
}
};
typedef EarthMoversMetricEvaluator myEvaluator;
o1 and o2 are two characteristic vector with one dimension, I have one million of vectors when I do one knn query with k = 10 all answers are 0, and for one knn query it is bad, is there any solution? Fri, 18 Dec 2015 14:54:46 -0600http://answers.opencv.org/question/79896/emd-function-returning-many-zeros-values/Answer by rblima for <p>I'm using the function in my application with the CV_DIST_L2, and I need to compare many vectors of characteristics. I know that they are much different because I used others functions to compare, but using the EMD is returning many zero values, I'm comparing about 1 million of images. If I need to rank 10 images by the distance it is very bad because of the zero values, it is normal? For example if I have one image and I need to compare with the others 1 million, for to find the 10 more similar, may be I can't find nor the query image because of the zeros values.</p>
<pre><code>char metricname[10] = "EMD";
class EarthMoversMetricEvaluator : public stBasicMetricEvaluator < tBasicArrayObject > {
public:
virtual stDistance GetDistance(tBasicArrayObject * o1, tBasicArrayObject * o2) {
this->UpdateDistanceCount();
int dim = o1->GetSize();
Mat sig1(dim, 2, CV_32FC1);
Mat sig2(dim, 2, CV_32FC1);
for (unsigned int a = 0; a < dim; a++) {
sig1.at<float>(a, 0) = o1->Get(a);
sig1.at<float>(a, 1) = a;
sig2.at<float>(a, 0) = o2->Get(a);
sig2.at<float>(a, 1) = a;
}
double d = EMD(sig1, sig2, CV_DIST_L2);
return d;
}
virtual stDistance GetDistance2(tBasicArrayObject * o1, tBasicArrayObject * o2) {
stDistance d = GetDistance(o1, o2);
return d*d;
}
};
typedef EarthMoversMetricEvaluator myEvaluator;
</code></pre>
<p>o1 and o2 are two characteristic vector with one dimension, I have one million of vectors when I do one knn query with k = 10 all answers are 0, and for one knn query it is bad, is there any solution? </p>
http://answers.opencv.org/question/79896/emd-function-returning-many-zeros-values/?answer=80092#post-id-80092 char metricname[10] = "EMD";
class EarthMoversMetricEvaluator : public stBasicMetricEvaluator < tBasicArrayObject > {
public:
virtual stDistance GetDistance(tBasicArrayObject * o1, tBasicArrayObject * o2) {
this->UpdateDistanceCount();
int dim = o1->GetSize();
Mat sig1(dim, 2, CV_32FC1);
Mat sig2(dim, 2, CV_32FC1);
for (unsigned int a = 0; a < dim; a++) {
sig1.at<float>(a, 0) = o1->Get(a);
sig1.at<float>(a, 1) = a;
sig2.at<float>(a, 0) = o2->Get(a);
sig2.at<float>(a, 1) = a;
}
double d = EMD(sig1, sig2, CV_DIST_L2);
return d;
}
virtual stDistance GetDistance2(tBasicArrayObject * o1, tBasicArrayObject * o2) {
stDistance d = GetDistance(o1, o2);
return d*d;
}
};
typedef EarthMoversMetricEvaluator myEvaluator;
o1 and o2 are two characteristic vector with one dimension, I have one million of vectors when I do one knn query with k = 10 all answers are 0, and for one knn query it is bad, is there any solution? Sun, 20 Dec 2015 16:39:12 -0600http://answers.opencv.org/question/79896/emd-function-returning-many-zeros-values/?answer=80092#post-id-80092