Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Created August 6, 2013 03:20
Show Gist options
  • Save halcat0x15a/6161744 to your computer and use it in GitHub Desktop.
Save halcat0x15a/6161744 to your computer and use it in GitHub Desktop.
2つの画像a,bがあり、画像bが画像aのどの位置に含まれるかを調べるコード
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