Python
2
Вклад в тег
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}")
for element in driver.find_elements(By.CLASS_NAME, "your_class"):
if element.value_of_css_property("color") == "red":
element.click()
import pyautogui
import time
def press_key(key: str, time: int):
"""
key: Клавиша
time: Время зажатия
"""
amount_of_clicks = time // 0.03
pyautogui.press(keys=key, presses=int(amount_of_clicks), interval=0.03)
time.sleep(5)
with pyautogui.hold('ctrl'):
press_key("d", 5)
time.sleep(0.5)
press_key("a", 5)
selenium.common.exceptions.NoSuchElementException
from selenium.common.exceptions import NoSuchElementException
try:
element = driver.find_element(By.CLASS_NAME, class_name)
print(element.text)
except NoSuchElementException:
print('Элемент не найден')