【问题标题】:openCV image Stitching wide angle 160 degreesopenCV图像拼接广角160度
【发布时间】:2020-03-25 20:55:17
【问题描述】:

我正在尝试拼接图像广角 160.5 度,但结果不是很好

我正在使用 OpenCV 4 和 ffmpeg 从视频中获取帧

ffmpeg 命令每秒获取 15 帧:

ffmpeg -i first.mp4 -vf fps=15  preview%05d.jpg

OpenCV 拼接代码

import cv2
import numpy as np

images = []
for i in range(70):
    name = ('preview%05d.jpg' % (i+1))
    print(name)
    images.append(cv2.imread(name , cv2.IMREAD_COLOR))


print("start ")
stitcher = cv2.Stitcher_create()
ret, pano = stitcher.stitch(images)

if ret == cv2.STITCHER_OK:
    cv2.imshow('panorama', pano)
    cv2.waitKey()
    cv2.destroyAllWindows()
else:
    print(cv2.STITCHER_ERR_NEED_MORE_IMGS)
    print(cv2.STITCHER_ERR_HOMOGRAPHY_EST_FAIL)
    print(cv2.STITCHER_ERR_CAMERA_PARAMS_ADJUST_FAIL)
    print(ret)
    print('Error during stiching')

实际结果:

预期结果:

【问题讨论】:

标签: opencv ffmpeg image-stitching opencv-stitching wideimage


【解决方案1】:

Stither 期望图像具有相似的部分(最多进行一些透视变换)。它执行成对的图像配准来找到这个透视变换。在您的情况下,它将无法找到它,因为它根本不存在。

在拼接器之前必须执行的附加步骤 - 校正每个图像以校正广角不平衡。要找到校正参数,您需要使用校准目标进行一些相机校准。

【讨论】:

    【解决方案2】:

    在代码行 stitcher = cv2.Stitcher_create() 之前,您必须附加一些算法,通过 homography method 将梯形图像视图转换为矩形图像视图。

    使用:cv2.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask]]])

    • srcPoints – 原始平面中点的坐标,CV_32FC2 或向量类型的矩阵。
    • dstPoints – 目标平面中点的坐标,CV_32FC2 类型的矩阵或向量。

    另请参阅 here 了解 OpenCV 上的 findHomography

    特别是:在您的情况下,底部(图像的底部)显示大部分信息,而顶部有更多不相关的信息。在这里,您应该保持顶部的纵横比相同并缩小底部。这应该对每张图像都进行。完成后,您可以尝试再次缝合它们。

    转换基于梯形图的图像信息的方法示例,例如方形图片:

                     (information ratio x)
    ----+++++++----  (1)
    ---+++++++++---  (1)
    --+++++++++++--  (1)
    -+++++++++++++-  (1)
    +++++++++++++++  (1)
    

    进入平方图像信息:

                    (information ratio x)
    ----+++++++---- (1)
    ----+++++++---- (1.1)
    ----+++++++---- (1.2)
    ----+++++++---- (1.3)
    ----+++++++---- (1.4; most compressed information ratio)
    

    完成后,您可以缝合它。不要忘记发布结果;-)

    另一种方法是将相机视为线路检查器。当您从每张图像中获取信息时使用此方法,比如说第 y1060 到 1080 行(例如图像大小 1920x1080px),然后用这 20 行中的信息按升序填充一个新数组。

    2019 年 1 月更新:

    由于陡峭的 60 度角,单应性似乎无法完成 100% 的工作,您可以尝试通过先执行 PerspectiveTransform 来校正角度。

    # you can add a for-loop + image counter here to perform action on all images taken from
    # the movie-file. Then its easily replacing numbers in the next part for the name
    # of the image.
    
    scr_array = []  # source e.g. pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]])
    dest_array = [] # destination e.g. pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
    
    Matrix1 = cv2.getPerspectiveTransform(scr_array,dest_array)
    dst = cv2.warpPerspective(image, Matrix1 , (cols, rows))
    
    label = 'CarImage1' # use ('CarImage%s' % labelnr) here for automated annotation.
    
    # cv2.imshow(label , dst) # check the image
    # cv2.imwrite(('%s.jpg' % label), dst) 
    

    另请参阅 PerspectiveTransform 上的文档 here

    【讨论】:

    • 谢谢你的回答,能再看一遍视频吗?
    • 视频有两个问题,我的第一感觉是,视频是在六十度左右的角度拍摄的,并且是作为鱼眼相机使用的。我尝试应用您的解决方案,但没有成功
    猜你喜欢
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2019-01-01
    • 2020-03-10
    • 2012-01-02
    相关资源
    最近更新 更多