如何找到图像中包含的图像? [英] How do I find an image contained within an image?

查看:18
本文介绍了如何找到图像中包含的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个基本上相当于搜索引擎和网络漫画画廊之间的交叉,专注于引用来源和给予作者信用.

I'm currently building what basically amounts to a cross between a search engine and a gallery for web comics that's focused on citing sources and giving authors credit.

我正在尝试找出一种方法来搜索图像以查找其中的字符.

I'm trying to figure out a way to search an image to find characters within it.

例如:

假设我将红色字符和绿色字符保存为 Red Man 和 Green Man,我如何确定图像是否包含其中一个.

Assuming I have the red character and the green character saved as Red Man and Green Man how do I determine if an image contains one or the other.

这不需要 100% 的认可,或者这更像是我想创建的附加功能,我只是不确定从哪里开始.我在谷歌上搜索了很多图像识别,但没有找到太多帮助.

This doesn't need to have 100% recognition or anything is this is more of an added feature I'd like to create, I'm just not sure where to start. I've done a lot of googling for image recognition but haven't found much helpful.

就其价值而言,我更愿意使用 Python 来做到这一点.

For what it's worth, I'd prefer to do this using Python.

推荐答案

适用于将来遇到此问题的任何人.

For anyone who stumbles across this in the future.

这可以通过模板匹配来完成.总结一下(我的理解),模板匹配会寻找一个图像与另一个图像的完全匹配.

This can be done with template matching. To summarize (my understanding), template matching looks for an exact match of one image within another image.

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

Here's an example of how to do it within Python:

import cv2

method = cv2.TM_SQDIFF_NORMED

# Read the images from the file
small_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 difference
mn,_,mnLoc,_ = cv2.minMaxLoc(result)

# Draw the rectangle:
# Extract the coordinates of our best match
MPx,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_image
cv2.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 this
cv2.waitKey(0)

这篇关于如何找到图像中包含的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆