【发布时间】:2018-03-20 03:05:53
【问题描述】:
论文的总体思路是确定二值图像的豪斯多夫距离,并使用它从测试图像中找到模板图像。
对于模板匹配,建议构建image pyramids 以及滑动窗口,您将使用滑动窗口在测试图像上滑动以进行检测。我也能做到这两点。
我被困在如何从这里继续前进。我是否将模板从不同的金字塔层滑过测试图像?还是模板上的测试图像?关于滑动窗口,它们是/是否意味着测试或模板图像的 ROI?
简而言之,我有拼图的碎片,但不知道要从哪个方向解开谜题
int distance(vector<Point>const& image, vector<Point>const& tempImage)
{
int maxDistance = 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;
}
maxDistance += minDistance;
}
return maxDistance;
}
double hausdorffDistance(vector<Point>const& image, vector<Point>const& tempImage)
{
double maxDistImage = distance(image, tempImage);
double maxDistTemp = distance(tempImage, image);
return sqrt(max(maxDistImage, maxDistTemp));
}
vector<Mat> buildPyramids(Mat& frame)
{
vector<Mat> pyramids;
int count = 6;
Mat prevFrame = frame, nextFrame;
while(count > 0)
{
resize(prevFrame, nextFrame, Size(), .85, .85);
prevFrame = nextFrame;
pyramids.push_back(nextFrame);
--count;
}
return pyramids;
}
vector<Rect> slidingWindows(Mat& image, int stepSize, int width, int height)
{
vector<Rect> windows;
for(size_t row = 0; row < image.rows; row += stepSize)
{
if((row + height) > image.rows) break;
for(size_t col = 0; col < image.cols; col += stepSize)
{
if((col + width) > image.cols) break;
windows.push_back(Rect(col, row, width, height));
}
}
return windows;
}
【问题讨论】:
标签: c++ opencv object-detection template-matching