python 图像拼接

复制代码
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))
复制代码

 

posted @   myrj  阅读(91)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示