用Python vc2 在大图中查找小图

发布时间 2023-05-06 23:27:05作者: dotfirer
import cv2
import time

def find_image_location(small_image_path, large_image_path):
    # Load images
    small_image = cv2.imread(small_image_path)
    large_image = cv2.imread(large_image_path)

    # Find match using template matching
    result = cv2.matchTemplate(large_image, small_image, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)

    # Return location of top-left corner of small image within large image
    return max_loc
#your large picture path
large ='temp\\hua.png' 
#your small picture path
small='temp\\hua4.png'
start_time=time.time()
loc=find_image_location(small,large )
end_time = time.time()
print(loc)
print("耗时: {:.2f}秒".format(end_time - start_time))
'''
(484, 824)
耗时: 0.04秒
PS E:\>
'''