D
D
Dimka54582022-04-07 21:48:46
Text recognising
Dimka5458, 2022-04-07 21:48:46

Image definition?

Would like to know if this is even possible?
I want to write a script that compares the picture on the screen with the screenshot, if they are the same, then the script continues, otherwise break.
If this is difficult to do, is it possible to make the python recognize the text on the screen (for example, “enter the password”) and if the text contains the word “password”, then the script goes on, otherwise break

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2022-04-07
@FCKJesus

About comparing pictures

from skimage.metrics import structural_similarity
import cv2

def orb_sim(img1, img2):
  orb = cv2.ORB_create()
  kp_a, desc_a = orb.detectAndCompute(img1, None)
  kp_b, desc_b = orb.detectAndCompute(img2, None)
  bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

  matches = bf.match(desc_a, desc_b)
  similar_regions = [i for i in matches if i.distance < 50]  
  if len(matches) == 0:
    return 0
  return len(similar_regions) / len(matches)


img1 = cv2.imread('test_img1.jpg', 0)
img2 = cv2.imread('test_img2.jpg', 0)
orb_similarity = orb_sim(img1, img2)
print(f"Фото схожи на:  {orb_similarity}")

The code works quite well with raw images.
And about text recognition, of course you can, there are a lot of ready-made solutions, OpenCV and Google to help

K
Kash_Tan, 2022-04-07
@Kash_Tan

You can check if the pictures are the same using Pillow

The code
from PIL import Image

#Открываем картинки

img1 = Image.open("img1.png")
img2 = Image.open("img2.png")

def same_imgs(img1, img2):
    size1 = img1.size #Получаем размер картинки (ширина, высота)
    pixels1 = []
    for x in range(size1[0]):
        for y in range(size1[1]):
            pixels1.append(img1.getpixel((x, y))) #Добавляем цвета по каждой координате

    size2 = img2.size #Получаем размер картинки (ширина, высота)
    pixels2 = []
    for x in range(size2[0]):
        for y in range(size2[1]):
            pixels2.append(img2.getpixel((x, y))) #Добавляем цвета по каждой координате

    if pixels1 == pixels2: #Проверяем равны ли все цвета
        return True
    else:
        return False

print(same_imgs(img1, img2))

img1.close()
img2.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question