栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何找到图像中包含的图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何找到图像中包含的图像?

对于将来偶然发现此问题的任何人。

这可以通过模板匹配来完成。总而言之(我的理解),模板匹配在一个图像中寻找另一个图像的精确匹配。

这是如何在Python中执行此操作的示例:

import cv2method = cv2.TM_SQDIFF_NORMED# Read the images from the filesmall_image = cv2.imread('small_image.png')large_image = cv2.imread('large_image.jpeg')result = cv2.matchTemplate(small_image, large_image, method)# We want the minimum squared differencemn,_,mnLoc,_ = cv2.minMaxLoc(result)# Draw the rectangle:# Extract the coordinates of our best matchMPx,MPy = mnLoc# Step 2: Get the size of the template. This is the same size as the match.trows,tcols = small_image.shape[:2]# Step 3: Draw the rectangle on large_imagecv2.rectangle(large_image, (MPx,MPy),(MPx+tcols,MPy+trows),(0,0,255),2)# Display the original image with the rectangle around the match.cv2.imshow('output',large_image)# The image is only displayed if we call thiscv2.waitKey(0)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/617749.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号