1 | initial version |
I finally managed to solve this problem and this is how I went about doing it.
My new Hausdorff distance implementation looked like this:
int distance(vector<Point>const& image, vector<Point>const& tempImage)
{
int totalDistance = 0;
for(Point imagePoint: image)
{
int minDistance = numeric_limits<int>::max();
for(Point tempPoint: tempImage)
{
Point diff = imagePoint - tempPoint;
int length = (diff.x * diff.x) + (diff.y * diff.y);
if(length < minDistance) minDistance = length;
if(length == 0) break;
}
if(minDistance > totalDistance) totalDistance = minDistance;
}
return totalDistance;
}
With regards to scale, that's where the image pyramids came into play. Turned out the slidingWindows
were entirely useless.
Aside from the first two steps, the previous Hausdorff Distance implementation was not working for me at all. Why you might ask?
maxDistance += minDistance
part was just killing me. I was getting huge values as my distance even though my frame size was nowhere close to being that huge. Distances north of 3k were the norm.With that said, I am still learning so before down voting, please point out my mistake so I can learn from it.
2 | No.2 Revision |
I finally managed to solve this problem and this is how I went about doing it.
My new Hausdorff distance implementation looked like this:
int distance(vector<Point>const& image, vector<Point>const& tempImage)
{
int totalDistance = 0;
for(Point imagePoint: image)
{
int minDistance = numeric_limits<int>::max();
for(Point tempPoint: tempImage)
{
Point diff = imagePoint - tempPoint;
int length = (diff.x * diff.x) + (diff.y * diff.y);
if(length < minDistance) minDistance = length;
if(length == 0) break;
}
if(minDistance > totalDistance) totalDistance = minDistance;
}
return totalDistance;
}
With regards to scale, that's where the image pyramids came into play. Turned out the slidingWindows
were entirely useless.
Aside from the first two steps, the previous Hausdorff Distance implementation was not working for me at all. Why you might ask?
maxDistance += minDistance
part was just killing me. I was getting huge values as my distance even though my frame size was nowhere close to being that huge. Distances north of 3k were the norm.With that said, I am still learning so before down voting, please point out my mistake so I can learn from it.
EDIT I
After performing multiple tests, I observed two things
+=
, the detection work just fine when the camera is pointed directly at the object.+=
worked best even with weird camera angles but the thresholding is still tricky.Thanks to @berak, I finally caved in to +=