【问题标题】:How to stitch multiple images using opencv?如何使用opencv拼接多个图像?
【发布时间】:2023-03-17 22:03:01
【问题描述】:

我想使用多张图像创建全景图。所以基本上,相机会在一个平面上线性平移,连续拍摄大约 20-30 张图像。我必须创建这些图像的全景图。我尝试过使用缝合功能以及查找特征并匹配它们然后变形的传统方法。但我不确定我是否做得正确。我该如何进行?

import imutils
import cv2
import glob

input_path = "/Users/akshayacharya/Desktop/Panorama/Raw 
Data/riverside/*.jpg"

# input and sort the images
list_images = glob.glob(input_path)
list_sorted = sorted(list_images)
print(list_sorted)

# output path definition
output_path = "/Users/akshayacharya/Desktop/Panorama/Final 
Panorama/finalpanoex1.jpg"

# initialize empty list and fill all images
images = []
for image in list_sorted:
    image1 = cv2.imread(image)
    image1 = cv2.resize(image1, (720, 480))
    images.append(image1)

print("Read the images")
# this is the final list to stitch
final = [images[0]]
flag = True
print(len(images))
temp = [images[0]]
print(type(temp))

stitcher = cv2.createStitcher() if imutils.is_cv3() else 
cv2.Stitcher_create()

i = 0
while(i < len(images)-1):
    (status, stitched) = stitcher.stitch([temp[0], images[i+1]])
    if status == 0:
        final.append(images[i+1])
        print(f"Succesfully stitch {i} to {i+1}")
        i = i+1

        temp[0] = stitched

        continue
    if status != 0:
        print(f"Succesfully could not stitch {i} to {i + 1}")
        for j in range(i+2, len(images)):
            print(f"now trying {i} to {j}")
            (status, stitchedd) = stitcher.stitch([temp[0], images[j]])
            if status == 0:
                print(f"Succesfully managed to stitch {i} to {j}")
                final.append(images[j])
                i=j
                temp[0] = stitchedd
                break
            if status != 0:
                print(f"Oops could not stitch {i} to {j}")
                print(f"Will now see compatibility between {i} and {j+1}")

            continue

        i += 1
    continue

cv2.imwrite(output_path, temp[0])

I have attached the output image```

【问题讨论】:

  • '但我不确定我是否做得正确'。我们也不是。你的代码是什么,你的结果是什么,它们有什么问题?
  • @couka 我附上了代码和输出。请通过它

标签: python opencv sift panoramas


【解决方案1】:

您可以查看我的 SIFT 笔记本,了解有关使用 opencv here 进行功能和全景拼接的代码。

【讨论】:

    【解决方案2】:

    全景图像构建流水线可以是关键点检测和局部不变描述符;关键点匹配; RANSAC;和透视变形。

    使用 RANSAC 算法使用匹配的特征向量估计单应矩阵。使用从 RANSAC 获得的单应矩阵应用翘曲变换。 RANSAC 改进了匹配过程检测。 OpenCV documentationhere 上提供了最近的教程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-26
      • 2020-03-10
      • 1970-01-01
      • 2019-01-01
      • 2012-12-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      相关资源
      最近更新 更多