Python Forum
Detecting if image matches another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detecting if image matches another
#1
Hi,

I have a program that continually takes screenshots of a Nintendo 64 Game from a capture card, it needs to compare the screenshot and determine if it matches another given screenshot.

My original plan was to use the compare_ssim method from the skimage.measurepackage to determine the structural similarity, and then if the ssim percentage was high enough (i.e 95%) say it's match. This works well in theory, however the quality of capture cards vary and ssim gives poor results in practice.

My SSIM test code:
from skimage.measure import compare_ssim
import cv2

screenshot_img = cv2.cvtColor(cv2.imread("screenshot.png"), cv2.COLOR_BGR2GRAY)
comparison_img = cv2.cvtColor(cv2.imread("comparison.png"), cv2.COLOR_BGR2GRAY)

ssim = calc_ssim(screenshot_img, comparison_img)
print(ssim)
Here are two examples of what I'm trying to determine match.

[Image: zilz5w.png]

[Image: zwf1ph.jpg]

See how the top one is lower quality, the ssim only rates these as a 30% match, however I need my program to recognise these are images of the same thing with certainty.

What else can I do to reliably determine whether two images such as the ones posted above are the same/very similar? I'm open to a new method entirely. It just has to be somewhat quick as my application has to process at 29.97fps, and around half the frame is already spent taking the screenshot.

Thanks!
Reply
#2
Just compare md5 or sha1 sum of the two files.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
hey, should have mentioned, as the program is taking screenshots quickly and doing processing on them, I never actually save them to disk. Only the comparison image is saved to disc. The code posted was just test code as stated to test the idea.

EDIT:

I may have found a solution, I'm using openCVs matchTemplate function, and passing in a cropped version of the logo posted in my original thread as the template. Something like this:

res = cv2.matchTemplate(image, template_image, cv2.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

if min_val < 0.1:
    print("Match found")
If anyone has another suggestion or an improvement please let me know, this is still just early testing.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  iterating and detecting the last Skaperen 3 1,063 Oct-01-2022, 05:23 AM
Last Post: Gribouillis
  Detecting float or int in a string Clunk_Head 15 4,425 May-26-2022, 11:39 PM
Last Post: Pedroski55
  module detecting if imported vs not Skaperen 1 1,658 Nov-19-2021, 07:43 AM
Last Post: Yoriz
  detecting a generstor passed to a funtion Skaperen 9 3,563 Sep-23-2021, 01:29 AM
Last Post: Skaperen
  Python BLE Scanner not detecting device alexanderDennisEnviro500 0 1,995 Aug-01-2021, 02:29 AM
Last Post: alexanderDennisEnviro500
  Detecting power plug Narayan 2 2,697 Aug-01-2020, 04:29 AM
Last Post: bowlofred
  delete a Python object that matches an atribute portafreak 2 2,175 Feb-19-2020, 12:48 PM
Last Post: portafreak
  Detecting USB Device Insertion on Windows 10 Atalanttore 0 2,369 Jan-17-2020, 02:46 PM
Last Post: Atalanttore
  Detecting windows shutdown event riccardoob 4 5,690 Nov-12-2019, 04:51 PM
Last Post: Aurthor_King_of_the_Brittons
  Detecting String Elements in a List within Given Message Redicebergz 6 3,800 Mar-19-2019, 03:12 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020