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

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

问题描述

我目前正在构建一个基本上相当于搜索引擎和网络漫画库的交叉点,这些漫画主要关注引用来源和给予作者信用。

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我试图找出一种搜索图像的方法来查找其中的字符。

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做这件事。 / p>

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
from cv2 import cv

method = cv.CV_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天全站免登陆