Skip to content

FindImg returns different maxLoc depending on DecodeImg or CaptureImg being used #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
J7mbo opened this issue Nov 27, 2023 · 1 comment

Comments

@J7mbo
Copy link

J7mbo commented Nov 27, 2023

Problem

  • A screenshot is taken with robotgo.CaptureImg().
  • When that screenshot is saved first, and then loaded using DecodeImg, then the X Y coordinates from FindImg() are correct. See code 1.
  • When that screenshot is instead used directly in FindImg(), the results are different! See code 2.

This is a problem for those who want to use the images from memory, not having to save them to the filesystem first.

Code 1:

Note: please substitute for your own images.

robotgo.Save(robotgo.CaptureImg(), "template.png")

template, _, _ := robotgo.DecodeImg("template.png")
find, _, err := robotgo.DecodeImg("find.png")

a, b, c, maxLoc := gcv.FindImg(find, template)
fmt.Println(a, b, c, maxLoc)

This gives:

-0.26353332 0.99999934 (2802,1283) (1026,168)

Code 2:

template := robotgo.CaptureImg()
find, _, err := robotgo.DecodeImg("find.png")

a, b, c, maxLoc := gcv.FindImg(find, template)
fmt.Println(a, b, c, maxLoc)

-0.42405054 0.41302797 (664,132) (2869,116)

Note how the only difference between the two code snippets are that we're saving the image first and then loading it with DecodeImg.

Extra Info


  • Note that this is a 14" MacOS with retina display. I have been noticing issues with scaling etc and having to do my own calculations to compensate. I'm not sure this is an issue here directly, though?
  • gcv version (or commit ref): github.com/vcaesar/gcv v0.40.5
  • Go version: go version go1.21.4 darwin/arm64
  • Operating system and bit: MacOS M3 chip
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
@J7mbo
Copy link
Author

J7mbo commented Nov 28, 2023

PS - I know that this is just using MatchTemplate under the hood so if I need to open something in the gocv lib please let me know and I'll do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant