opencv 图像拼接stitcher

如果相互重复的至少有1/3效果还有不错的

import cv2
import math
import os

# 文件夹所有图片
path = "Images/Scan"
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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值