gpt4 book ai didi

graphics - 使用计算机视觉处理图像验证码

转载 作者:行者123 更新时间:2023-12-03 07:52:36 25 4
gpt4 key购买 nike

我想在“大图像”内找到“小图像”中对象的坐标。如果您有任何想法,请告诉我。

我尝试过特征匹配,但成功率很低。


enter image description here

enter image description here


enter image description here

enter image description here


enter image description here

enter image description here

最佳答案

对于您的情况,您似乎可以简单地将小图片旋转 N 次,并对每张旋转的小图片应用模板匹配。

还对图像应用中值滤波器以减少噪声

示例:

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

img_small = cv.imread('small.png', cv.IMREAD_COLOR)
img_big = cv.imread('big.png', cv.IMREAD_COLOR)

img_small = cv.cvtColor(img_small, cv.COLOR_BGR2RGB)
img_big = cv.cvtColor(img_big, cv.COLOR_BGR2RGB)

img_big = cv.medianBlur(img_big, 3)

rows,cols = img_small.shape[:2]

img_small_rotated = list()

n = 20

for i in range(0,n):
M = cv.getRotationMatrix2D(((cols-1)/2.0,(rows-1)/2.0),360*(i/n),1)
img_small_rot = cv.warpAffine(img_small,M,img_small.shape[:2],borderValue = (255,255,255))
img_small_rot = cv.medianBlur(img_small_rot, 3)
img_small_rotated.append(img_small_rot)

im_show_all_templates = np.concatenate(img_small_rotated, axis=1)

plt.imshow(im_show_all_templates)
plt.show()

max_loc_global = None
max_val_global = 0

for i in img_small_rotated:
res = cv.matchTemplate(img_big,i,cv.TM_CCOEFF_NORMED)

min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
if max_val > max_val_global:
max_val_global = max_val
max_loc_global = max_loc

print(max_val_global, max_loc_global)

top_left = max_loc_global
bottom_right = (top_left[0] + cols, top_left[1] + rows)

cv.rectangle(img_big,top_left, bottom_right, 0, 2)

plt.imshow(img_big)
plt.show()

结果:

enter image description here

您可以使用类似的技术以其他方式扩展模板匹配空间(缩放、过滤、旋转),但对于您的应用程序来说,旋转似乎就足够了。

关于graphics - 使用计算机视觉处理图像验证码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76809885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com