我目前正在构建基本上相当于搜索引擎和网络漫画画廊之间的交叉点,其重点是引用来源和给予作者信用。
我正在尝试找出一种方法来搜索图像以查找其中的字符。
例如:
假设我将红色字符和绿色字符保存为红人和绿人,如何确定图像是否包含其中之一。
这不需要 100% 的识别或者任何东西,这更多的是我想创建的附加功能,我只是不知道从哪里开始。我已经在谷歌上搜索了很多关于图像识别的信息,但没有发现太多帮助。
就其价值而言,我更喜欢使用 Python 来完成此操作。
As 摩西的回答仅涵盖匹配给定图片中仅包含一次的模板。以下是一次匹配多个的方法:
import cv2
import numpy as np
img_rgb = cv2.imread('mario.png')
template = cv2.imread('mario_coin.png')
w, h = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = .8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]): # Switch columns and rows
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
cv2.imwrite('result.png', img_rgb)
(注:我更改并修复了一些“错误”原始代码中的内容)
Result:
Source: https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html#template-matching-with-multiple-objects
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)