用Python vc2 在大图中查找小图

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:\>
'''
posted @   dotfirer  阅读(333)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示