我有两个视频图片,frameA和frameB。假设视频正在平移,慢慢地,人们可以想象frameA和frameB有很大的重叠。然后,我们可以从视频片段中创建全景图。
我试过使用:Openencv2.缝纫机,带BF匹配的SURF/ORB探测器,以及一些普通的方法。由于某种原因,他们都没有产生我所需要的结果。我发现的主要问题是,SURF/ORB识别的区域太“小”,而且匹配不正确。
我在一个沙漠里,看到的是一棵仙人掌。我正在翻过它。冲浪/球体正在探测感兴趣的区域,如我的仙人掌的边缘与天空/陆地,无法匹配(不知道为什么)在下一个帧。它检测到的东西,它不匹配,当你使用同形,它匹配的仙人掌中间和仙人掌的顶部在下一个框架.它会被扭曲。
有办法做下面的事吗?
我尝试的解决方案是拍摄整个图片,进行“重叠”扫描,并找出不同之处。在我有最小值的地方,我有适当的X,Y移位。然而,这有两个问题:
,
image1 = cv2.imread('img1.png')
print(image1.shape)
img1 = cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)
nw1, nh1 = img1.shape
nw15, nh15 = int(nw1/2), int(nh1/2)
# load image 2
image2 = cv2.imread('img2.png')
img2 = cv2.cvtColor(image2,cv2.COLOR_BGR2GRAY)
nw2, nh2 = img2.shape
nw25, nh25 = int(nw2/2), int(nh2/2)
# generate base canvas, note that img1 could be top left of img2, or img2 could be top left of img1
# the search space of this is very large
nw, nh = nw1+nw2*2, nh1+nh2*2
cnw, cnh = int(nw/2), int(nh/2) # get the center point for later calculations
base_image1 = np.ones((nw,nh), np.uint8)*255 # make the background white
base_image1[cnw-nw15: cnw+nw15, cnh-nh15: cnh+nh15] = img1 # set the first image in the center
# create the image we want to "sweep over" we "pre-allocate" since creating new ones is expensive.
sweep_image = np.zeros((nw,nh), np.uint8) # keep at 0 for BLACK
import time
stime = time.time()
total_blend = []
# sweep over my search space!
for x_s in np.arange(20, 80): # limit search space so it finish this year
for y_s in np.arange(300, 500): # limit search space so it finish this year
w1, w2 = cnw-nw25+x_s, cnw+nw25+x_s # get the width slice to set our sweep image
h1, h2 = cnh-nh25+y_s, cnh+nh25+y_s # get the height slice to set our sweep image
sweep_image[w1: w2, h1: h2] = img2 # set the image
diff = cv2.absdiff(base_image1, sweep_image) # calculate the difference
total_blend.append([x_s, y_s, np.sum([diff])]) # store the transformation and coordinates
sweep_image[w1: w2, h1: h2] = 0 # reset back to zero
cv2.imshow('diff',diff)
cv2.waitKey(0)
print(time.time() - stime)
# convert to array
total_blend = np.array(total_blend)
mymin = np.min(total_blend[:,2])
print(total_blend[total_blend[:,2]==mymin]) # get the best coordinates for translation
示例1:注意巨大的白色边框,因为要确保整个搜索空间的图像大小相同。示例1,这是一个ok ish匹配,但请注意暗区域是如何不是很暗的。
示例2:(大的白色边框),但请注意黑暗区域实际上是黑色的。这几乎是最低限度。
所有的帮助和想法都很感激。是否有办法规定特征探测器的“大小”?有更快的方法吗?也许是一些RMSE和numpy特征值-这毕竟是线性代数.?
我用的是python3,opencv2。
发布于 2022-05-27 03:52:53
到目前为止,我已经创建了与密集特性Dector类似的我自己的关键点。与SIFT/Corner/ or或任何发现小功能的特性不同,密集的特性可以被认为是在整个图像中获取网格中的关键点。
https://stackoverflow.com/questions/72358573
复制相似问题