0

I have an reference image I want to match on screenshot. It is part of screenshot, so it's must definitely match.

Image to find: >needleImage<

Full screenshot:

haystackImage

So, with OpenCV pyscreeze matches images like these:

# get all matches at once, credit: https://stackoverflow.com/questions/7670112/finding-a-subimage-inside-a-numpy-image/9253805#9253805
result = cv2.matchTemplate(haystackImage, needleImage, cv2.TM_CCOEFF_NORMED)
match_indices = numpy.arange(result.size)[(result > confidence).flatten()]
matches = numpy.unravel_index(match_indices[:limit], result.shape)

some tests:

opencv + numpy confidence 1.0: 0 matches
first ten: []
Bench passed in 0.205 seconds

opencv + numpy confidence default (0.999): 1795428 matches
first ten: [(0, 0, 13, 13), (1, 0, 13, 13), (2, 0, 13, 13), (3, 0, 13, 13), (4, 0, 13, 13), (5, 0, 13, 13), (6, 0, 13, 13), (7, 0, 13, 13), (8, 0, 13, 13), (9, 0, 13, 13)]
Bench passed in 0.852 seconds

pure python method: 6690 matches
first ten: [(1855, 208, 13, 13), (1856, 208, 13, 13), (1857, 208, 13, 13), (1858, 208, 13, 13), (1859, 208, 13, 13), (1860, 208, 13, 13), (1861, 208, 13, 13), (1862, 208, 13, 13), (1863, 208, 13, 13), (1864, 208, 13, 13)]

Bench passed in 1.344 seconds

I've played with confidence, matching methods, but with OpenCV results are same. It's matched every single pixel or not matching everything.

Pure python method from pyscreeze give most proper results - it's matching images properly.

Maybe I don't need something like OpenCV to match part of screenshot? But pure python is 5-10 times slower.

Egor Egorov
  • 313
  • 1
  • 4
  • 19

0 Answers0