OpenCV立体声Rectify扭曲图像 [英] OpenCV stereoRectify distorts image

查看:453
本文介绍了OpenCV立体声Rectify扭曲图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个ELP 1.0百万像素双镜头USB立体声相机,我们正在尝试使用C ++中的OpenCV 3.1对其进行校准.但是,校准的结果完全不可用,因为调用stereoRectify会完全扭曲图像.这就是我们要做的:

we have a ELP 1.0 Megapixel Dual Lens Usb Stereo camera and we are trying to calibrate it using OpenCV 3.1 in C++. However, the result of the calibration is totally unusable, because calling stereoRectify totally twistes the image. This is what we do:

在两个摄像机中都找到校准(棋盘)图案,棋盘大小为5x7,无论拍摄的图像数量如何,结果几乎相同

Finding calibration (chessboard) pattern in both cameras, chessboard size is 5x7 and the result is almost same regardless the number of images taken

findChessboardCorners(img[k], boardSize, corners, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE)
cornerSubPix(img[k], corners, Size(11, 11), Size(-1, -1), TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01));

所有棋盘均已正确检测并通过验证

All chessboards are correctly detected that is verified using

drawChessboardCorners(img[k], boardSize, corners, bFound);

然后我们分别校准每个摄像机(但是此步骤对于立体声校准似乎并不重要),但是我们可以使用它分别验证每个摄像机

Then we calibrate each camera separately (but this step seems not to be important for stereo calibration), but we can use it to verify each camera separately

calibrateCamera(objectPoints, imagePoints[k], Size(320, 240), cameraMatrix[k], distCoeffs[k], rvecs, tvecs, 0)

然后我们进行立体声校准

Then we do stereo calibration

stereoCalibrate(objectPoints, imagePoints[0], imagePoints[1], cameraMatrix[0], distCoeffs[0], cameraMatrix[1], distCoeffs[1],
    Size(320, 240), R, T, E, F, CALIB_USE_INTRINSIC_GUESS);

计算整流变换

stereoRectify(cameraMatrix[0], distCoeffs[0], cameraMatrix[1], distCoeffs[1], Size(320, 240), R, T, R1, R2, P1, P2, Q,
    CALIB_ZERO_DISPARITY, 1, Size(320, 240), &validRoI[0], &validRoI[1]);

初始化地图以进行重新映射

Initialize maps for remap

Mat rmap[2][2];
initUndistortRectifyMap(cameraMatrix[0], distCoeffs[0], R1, P1, Size(FRAME_WIDTH, FRAME_HEIGHT), CV_16SC2, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cameraMatrix[1], distCoeffs[1], R2, P2, Size(FRAME_WIDTH, FRAME_HEIGHT), CV_16SC2, rmap[1][0], rmap[1][1]);
...
remap(img, rimg, rmap[k][0], rmap[k][1], INTER_LINEAR);
imshow("Canvas", rimg);

结果是图像完全失真.正如我在开始时所说的,所有校准/棋盘图案都可以正确检测到,如果我们不调用stereoRectify函数,则未失真的图像(重新映射后)看起来很完美.如果我们调用stereoRectify函数,就会出现问题.

The result is totally distorted image. As I said at the beginning, all calibration/chessboard patterns are correctly detected and if we don't call stereoRectify function, the undistorted images (after remap) look perfect. The problem comes if we call stereoRectify function.

我们错过了什么吗? 校准图像的数量似乎没有任何影响(有时拍摄2张图像比10张图像效果更好(但仍不可用))

Is there something we missed out? The number of calibration images does not seem to have any effect (sometimes taking 2 images provides better result (but still not usable) than 10 images)

这是校准图案的示例.我们采取了几种不同的方向:

This is the example of calibration pattern. We take several different orientations:

如果我们不调用stereoRectify,这是校准的结果:

This is the result of the calibration if we do not call stereoRectify:

如果我们调用stereoRectify,这是错误的结果(但大多数情况下会变得更糟):

This is the wrong result if we call stereoRectify (but mostly it gets much worse):

在此先感谢您提供任何帮助.

Thanks in advance for any help what could be wrong.

推荐答案

您好吗?您尝试过在函数stereoRectify中更改参数alpha的值.我记得,一旦我也获得了这样的结果,并将alpha的值更改为0便为我工作了. 请让我知道您使用alpha = -1,alpha = 0.5和alpha = 0所获得的结果

Hey have you tried changing the value of parameter alpha in function stereoRectify. I remember that once I also obtained such results and changing the value of alpha to 0 did the work for me. Please let me know the results you obtain with alpha = -1, alpha=0.5 and alpha =0

这篇关于OpenCV立体声Rectify扭曲图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆