

У меня есть копия газеты (изображение), в которой есть реклама. Я хочу найти это объявление в другом экземпляре газеты (изображение). У меня возникли проблемы с этим в Python.
Что я пробовал до сих пор
Использование opencv Я попробовал сопоставление текста с помощью OCR, но не получил желаемого результата. Есть ли лучший способ сделать это?
Я тоже пробовал сопоставление шаблонов.
вот код:
Код: Выделить всё
import cv2
import numpy as np
def is_image_present(template_path, image_path):
# Read the template image and the main image
template = cv2.imread(template_path, cv2.IMREAD_GRAYSCALE)
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Resize the template image to match the dimensions of the main image
resized_template = cv2.resize(template, (image.shape[1], image.shape[0]))
# Perform template matching
result = cv2.matchTemplate(image, resized_template, cv2.TM_CCOEFF_NORMED)
# Define a threshold value to consider a match
threshold = 0.8
# Find locations where the template matches the main image above the threshold
locations = np.where(result >= threshold)
# Check if any match is found
if len(locations[0]) > 0:
return True
else:
return False
# Provide the paths to your images
template_image_path = 'image_small.jpg'
main_image_path = 'image_large.jpg'
# Check if the template image is present in the main image
result = is_image_present(template_image_path, main_image_path)
# Print the result
if result:
print("Template image is present in the main image.")
else:
print("Template image is not present in the main image.")
Подробнее здесь: https://stackoverflow.com/questions/765 ... ing-python