全景图拼接和视频行人检测(Python + opencv)

3. 根据关键点特征和描述符, 对两张图像进行匹配, 得到若干匹配点对, 并移除错误匹配
    
    4. 使用Ransac算法和匹配的特征来估计单应矩阵(homography matrix)
    
    5. 通过单应矩阵来对图像进行仿射变换
    
    6. 两图像拼接,重叠部分融合
    
    7. 裁剪以获得美观的最终图像
    
    本次实验通过拍摄多组不同的图片来实现图像的拼接.

# 参考自https://cloud.tencent.com/developer/article/2214756 并作修改
import numpy as np
import cv2
import imutils
from imutils import paths

images = 'image'    # 输入图像路径
output = 'res/mix.png'  # 输出图像
crop = True
# 使用imutils.path.list_images获取输入图像路径中所有图像的路径并排序
imagePaths = sorted(list(paths.list_images(images)))
images = []

# 读取图像
for imagePath in imagePaths:
    image = cv2.imread(imagePath)
    images.append(image)

# 创建图像缝合器
stitcher = cv2.Stitcher_create()
(status, stitched) = stitcher.stitch(images)

# status 代表拼接状态,成功时status为0
if status == 0:
    # 进入裁剪图像
    if crop:
        # 在拼图周围添加2像素
        stitched = cv2.copyMakeBorder(stitched, 2, 2, 2, 2,
                                      cv2.BORDER_CONSTANT, (0, 0, 0))
        # 图像灰度化处理
        gray = cv2.cvtColor(stitched, cv2.COLOR_BGR2GRAY)
        thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)[1]

        # 查找阈值图像的轮廓
        cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                cv2.CHAIN_APPROX_SIMPLE)
        cnts = imutils.grab_contours(cnts)
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值