这是您要使用的代码框架:
// look for all (x,y) positions where target appears in desktop
List<Loc> findMatches(Image desktop, Image target, float threshold) {
List<Loc> locs;
for (int y=0; y<desktop.height()-target.height(); y++) {
for (int x=0; x<desktop.width()-target.width(); x++) {
if (imageDistance(desktop, x, y, target) < threshold) {
locs.append(Loc(x,y));
}
}
}
return locs;
}
// computes the root mean squared error between a rectangular window in
// bigImg and target.
float imageDistance(Image bigImg, int bx, int by, Image target) {
float dist = 0.0;
for (int y=0; y<target.height(); y++) {
for (int x=0; x<target.width(); x++) {
// assume RGB images...
for (int colorChannel=0; colorChannel<3; colorChannel++) {
dist += Math.pow(target.getPixel(x,y) - bigImg.getPixel(bx+x,by+y), 2);
}
}
}
return Math.sqrt(dist) / target.width() / target.height();
}
您可以考虑其他图像距离(请参阅类似的问题 )。对于您的应用程序,RMS误差可能是一个不错的选择。
可能有各种Java库可以为您有效地计算此距离。
0
有谁知道在较大图像中定位已知图像的算法(或搜索字词/说明)?
例如
我有一个包含多个按钮和区域(目标)的单个桌面窗口的图像。我也有捕获当前桌面屏幕截图的代码。我想要一种算法,可以帮助我在较大的桌面图像(窗口位于的确切x和y坐标)内找到目标图像。目标图像可能位于较大图像中的任何位置,并且可能不是100%完全相同(非常相似,但可能与操作系统显示差异b / c并不完全相同)
有人知道这样的算法吗?
我发现了各种图像分割和计算机视觉算法,但它们似乎适用于“模糊”区域分类,而不是在另一个图像中定位特定图像。
** 我的目标是创建一个框架,给定一些种子目标图像,该框架可以在桌面上找到“外观”,找到目标区域并“监视”它的更改。 **