天天看點

python opencv圖像拼接 多張圖互相有重複部分

python opencv圖像拼接 多張圖互相有重複部分
import cv2
import math
import os

# 檔案夾所有圖檔
path = "Images/ROIRun"
images = []
for filename in os.listdir(path):  # listdir的參數是檔案夾的路徑
    filenames = path + '\\' + filename
    # print(filenames)
    img_orig = cv2.imread(filenames, 1)
    print(filenames)

    if img_orig is None:
        print("Warning: No Pictures")
    else:
        images.append(img_orig)

# 初始化OpenCV的圖像sticher對象,然後執行圖像拼接
print("[INFO] stitching images.........................")
# stitcher = cv2.createStitcher() if imutils.is_cv3() else cv2.Stitcher_create()
stitcher = cv2.Stitcher_create()

(status, stitched) = stitcher.stitch(images)

# print(status, stitched)
# 如果狀态為“0”,則OpenCV成功執行圖像拼接
# if the status is '0', then OpenCV successfully performed image stitching
if status == 0:
    # write the output stitched image to disk
    cv2.imwrite("Images/stitch.jpg", stitched)

    # display the output stitched image to our screen
    cv2.imshow("Stitched", stitched)
    cv2.waitKey(0)

# otherwise the stitching failed, likely due to not enough keypoints) being detected
else:
    print("[INFO] image stitching failed ({})".format(status))      

OpenCV探索之路(二十四)圖像拼接和圖像融合技術