首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >“缝合”两幅图片寻找最佳的平移和旋转巨蟒

“缝合”两幅图片寻找最佳的平移和旋转巨蟒
EN

Stack Overflow用户
提问于 2022-05-24 07:08:05
回答 1查看 210关注 0票数 2

我有两个视频图片,frameA和frameB。假设视频正在平移,慢慢地,人们可以想象frameA和frameB有很大的重叠。然后,我们可以从视频片段中创建全景图。

我试过使用:Openencv2.缝纫机,带BF匹配的SURF/ORB探测器,以及一些普通的方法。由于某种原因,他们都没有产生我所需要的结果。我发现的主要问题是,SURF/ORB识别的区域太“小”,而且匹配不正确。

我在一个沙漠里,看到的是一棵仙人掌。我正在翻过它。冲浪/球体正在探测感兴趣的区域,如我的仙人掌的边缘与天空/陆地,无法匹配(不知道为什么)在下一个帧。它检测到的东西,它不匹配,当你使用同形,它匹配的仙人掌中间和仙人掌的顶部在下一个框架.它会被扭曲。

有办法做下面的事吗?

  1. 只执行旋转和平移?在两个帧之间--注意后续帧中有“新”信息,所以它永远不可能100%重叠。
  2. 找到最佳的旋转和平移,基本假设有最佳匹配?(我的速度非常慢,并保证overlap).
  3. Ignore的小幅度波动。如果我的特征探测器足够“大”,它会说,“仙人掌在框架1”匹配“猫在框架2",翻译为X,Y,并可能旋转Z.

我尝试的解决方案是拍摄整个图片,进行“重叠”扫描,并找出不同之处。在我有最小值的地方,我有适当的X,Y移位。然而,这有两个问题:

  1. ,它很慢。太慢了。
  2. 不能旋转,如果搜索空间增加,速度会更慢。

代码语言:javascript
运行
复制
    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。

EN

回答 1

Stack Overflow用户

发布于 2022-05-27 03:52:53

到目前为止,我已经创建了与密集特性Dector类似的我自己的关键点。与SIFT/Corner/ or或任何发现小功能的特性不同,密集的特性可以被认为是在整个图像中获取网格中的关键点。

(请参阅更多信息) https://subscription.packtpub.com/book/application-development/9781785283932/10/ch10lvl1sec81/what-is-a-dense-feature-detector

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72358573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档