Created
August 6, 2013 03:20
-
-
Save halcat0x15a/6161744 to your computer and use it in GitHub Desktop.
2つの画像a,bがあり、画像bが画像aのどの位置に含まれるかを調べるコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def point(a: BufferedImage, b: BufferedImage) = | |
for { | |
points <- (for { | |
ax <- 0.to(a.getWidth - b.getWidth).view | |
ay <- 0.to(a.getHeight - b.getHeight).view | |
} yield { | |
for { | |
bx <- 0.until(b.getWidth).view | |
by <- 0.until(b.getHeight).view | |
} yield (ax, ay) -> (bx, by) | |
}).find(_ forall { | |
case ((ax, ay), (bx, by)) => | |
a.getRGB(ax + bx, ay + by) == b.getRGB(bx, by) | |
}) | |
((x, y), _) <- points.headOption | |
} yield (x + b.getWidth / 2, y + b.getHeight / 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment