[英]openCV image Stitching wide angle 160 degrees
我正在尝试拼接图像广角 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')
实际结果 :
预期结果 :
在代码行之前, stitcher = cv2.Stitcher_create()
您必须附加一些更多的算法,通过homography 方法将梯形图像视图转换为矩形图像视图。
使用: cv2.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask]]])
另请参阅此处了解 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 的文档。
Stither 期待具有相似部分的图像(直到某些透视变换)。 它执行成对图像配准以找到此透视变换。 在您的情况下,它将无法找到它,因为它根本不存在。
您必须在拼接器之前执行的附加步骤 - 校正每个图像以校正广角分布。 要找到校正参数,您需要使用校准目标进行一些相机校准。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.