- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想扭曲和矫正我的立体图像。为此,我在 Python 2.7 中使用了 Opencv 3.3。我使用的代码是:
import cv2
import numpy as np
cameraMatrixL = np.load('mtx_left.npy')
distCoeffsL = np.load('dist_left.npy')
cameraMatrixR = np.load('mtx_right.npy')
distCoeffsR = np.load('dist_right.npy')
R = np.load('R.npy')
T = np.load('T.npy')
imgleft = cv2.imread('D:\python\camera calibration and 3d const\left\left60.png',0)
imgright = cv2.imread('D:\python\camera calibration and 3d const\Right/right60.png',0)
R1,R2,P1,P2,Q,validPixROI1, validPixROI2 = cv2.stereoRectify(cameraMatrixL,distCoeffsL,cameraMatrixR,distCoeffsR,(640,480),R,T,alpha=1)
print Q
# distort images
undistort_map1, rectify_map1 = cv2.initUndistortRectifyMap(cameraMatrixL, distCoeffsR, R1, P1, (640,480), cv2.CV_16SC2)
undistort_map2, rectify_map2 = cv2.initUndistortRectifyMap(cameraMatrixR, distCoeffsR, R2, P2, (640,480), cv2.CV_16SC2)
undistor_output1 = cv2.remap(imgleft, undistort_map1, rectify_map1, cv2.INTER_LINEAR)
undistor_output2 = cv2.remap(imgright, undistort_map2, rectify_map2, cv2.INTER_LINEAR)
cv2.imshow('undistor_output1',undistor_output1)
cv2.imshow('undistor_output2',undistor_output2)
while (True):
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我分别校准了我的相机,然后将那些获得的矩阵用于 cv2.stereoRectify
以获得我在 中使用的
。但是我没有正确地得到不失真的图像。它看起来像这样: 我的矩阵是:R1,R2,P1,P2,Q
矩阵>cv2.initUndistortRectifyMap
Q
[[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 -3.23097469e+02]
[ 0.00000000e+00 1.00000000e+00 0.00000000e+00 -2.40008609e+02]
[ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -7.47885268e+00]
[ 0.00000000e+00 0.00000000e+00 -1.53249612e-02 0.00000000e+00]]
cameraMartix Left
[[ 807.24668269 0. 326.78961645]
[ 0. 620.70299534 259.9187458 ]
[ 0. 0. 1. ]]
camearMatrix Right
[[ 567.37537971 0. 278.76995505]
[ 0. 558.21417195 216.22972643]
[ 0. 0. 1. ]]
Rotation
[[ 0.99973813 -0.02260904 0.00353613]
[ 0.02269951 0.99934817 -0.02807079]
[-0.00289917 0.0281437 0.99959968]]
Tranlation
[[-93.46968934]
[ -1.48741179]
[ 24.98692133]]
我已经阅读了很多答案,但都没有解决我的问题。
Straightforward solution on how to stereo calibration and rectifications OpenCV?
* undistortPoints in OpenCV (cv2) with Python wrong results
using initUndistortRectifyMap to undistort image points
opencv cv2.remap creates strange images *
这个问题的解决方案是什么?
谢谢。
最佳答案
在尝试了很多事情之后,我找到了解决这个特定问题的方法。在比较了使用Python OpenCV 和Matlab 获得的相机旋转矩阵和畸变矩阵后,我发现使用Python 和Matlab 获得的矩阵之间存在很大差异。因此,我再次校准我的相机并使用 Python 和 OpenCV 进行立体校准。下图显示了旧矩阵(从 Python 获得)和新矩阵(使用 Python 再次校准后获得)之间的差异。
在这张图中,我们可以看到,与失真系数矩阵相比,旧情况下左右摄像机的失真系数矩阵(dist coeff.right old and left old)
有很大差异新案例的左右摄像头 (dist coeff.right new and left new)
。对于右摄像头,旧系数分别为 83.85 和 -19.18,分别为 0.78 和 -0.61。同样,对于左摄像头,旧系数分别为 123.7 和 -1641.4,分别为 -0.38 和 0.73。此外,旧左相机矩阵的第一个元素 (1,1) 是 807.24,与右相机旧矩阵相比差异很大。新的左摄像头矩阵的元素值为 552.41,我认为这是正确的。当我使用所有这些新矩阵并将我的 alpha 值更改为 0 (alpha = 0)
时,我得到了以下结果。
对于stereoCalbirate
,我使用了以下输入
retVal, cm1, dc1, cm2, dc2, r, t, e, f = cv2.stereoCalibrate(objpoints, imgpointsL, imgpointsR, cm1, dc1, cm2, dc2, (640, 480), None, None, cv2.CALIB_FIX_INTRINSIC, criteria)
其中 条件 = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)
关于Python 2.7/OpenCV 3.3 : Error in cv2. initUndistortRectifyMap 。不显示未失真的校正图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100927/
我正在使用 opencv 进行图像校正,但我想使用 c 函数 cvInitUndistortRectifyMap 返回的 map (mapx 和 mapy)自己进行映射(通常由 cvremap 完成)
我目前正在为一对立体相机编写 openCV 程序。完成相机校准和立体校准。 下一步是从我获得的 2 张图像中找到特征在空间中的位置。这就是为什么我必须对图像进行立体校正并在之后进行计算的原因。 我在
我想校准我的相机。目标是消除失真并且不裁剪图像(如上一张照片)。我是这样做的: 1)加载图片,找到棋盘的角 import cv2 import numpy as np import os import
我想消除相机图像的失真。 OpenCV 的 undistort 函数太慢了,所以我想像文档中提到的那样将它拆分为 initUndistortRectifyMap(作为初始步骤)和 remap(在渲染循
我想扭曲和矫正我的立体图像。为此,我在 Python 2.7 中使用了 Opencv 3.3。我使用的代码是: import cv2 import numpy as np cameraMatrixL
我是一名优秀的程序员,十分优秀!