简体   繁体   English

Emgu(OpenCV for C#) - 使用cvStereoRectify构建视差图

[英]Emgu (OpenCV for C#) - building a disparity map using cvStereoRectify

I've been using the great Emgu C# wrapper for OpenCV to collect images from a home built stereo rig. 我一直在使用用于OpenCV的伟大的Emgu C#包装器来收集家用立体声装备的图像。 Two webcams bolted down to a piece of wood, 35cm apart to hopefully let me produce depth maps in the 10-20m range. 两个网络摄像头用螺栓固定在一块35厘米的木头上,希望能让我在10-20米范围内制作深度图。 I've set them up to be as parallel as I can make it (about 89.3 degrees from a triangulation test). 我将它们设置为尽可能平行(三角测试大约89.3度)。

I'm trying to make a disparity map from these and although the process works as code the results are very random. 我正在尝试从这些中制作视差图,尽管该过程作为代码起作用,但结果非常随机。 By this I mean each time I attempt to run the stereo rectify I get very different results and the image is often so badly warped there is hardly anything to see on screen. 我的意思是每当我尝试运行立体声整流时,我会得到非常不同的结果,而且图像经常如此严重扭曲,屏幕上几乎看不到任何东西。

As I understand it the way to do this is as follows: 据我了解,这样做的方法如下:


1) Print off a chessboard pattern (eg 6 by 8 inner corners)- stick onto something flat. 1)打印棋盘图案(例如6个8个内角) - 粘在平坦的东西上。

2) Take a set of about 10 photos from camera 1 holding the chess board in full view but different positions. 2)从相机1拍摄一组约10张照片,在全景但不同的位置拿着棋盘。

3) use CameraCalibration.FindChessboardCorners to find the inner corners (6 by 8) 3)使用CameraCalibration.FindChessboardCorners查找内角(6乘8)

4) use img.FindCornerSubPix() to refine these corner locations to subpixel level 4)使用img.FindCornerSubPix()将这些角位置细化到子像素级别

5) use CameraCalibration.CalibrateCamera() to calculate the intrinsic camera details, and save this as an XML file 5)使用CameraCalibration.CalibrateCamera()计算内在的摄像头细节,并将其保存为XML文件

6) Repeat above for camera 2. 6)对相机2重复上述步骤。

7) Now you have the internal camera distortion information you can take a stereo photo pair and use CameraCalibration.StereoCalibrate() with the intrinsic data previously calculated to work out the extrinsic information (offsets and rotations between camera 1 and 2). 7)现在您有内部摄像机失真信息,您可以拍摄立体照片对,并使用CameraCalibration.StereoCalibrate()和先前计算的内在数据来计算外部信息(摄像机1和2之间的偏移和旋转)。

8) Use CvInvoke.cvStereoRectify() and CvInvoke.cvInitUndistortRectifyMap() and then CvInvoke.cvRemap() to build an output image which should be lined up in Y so you can run one of the stereo correspondence tests. 8)使用CvInvoke.cvStereoRectify()和CvInvoke.cvInitUndistortRectifyMap()然后使用CvInvoke.cvRemap()来构建一个输出图像,该图像应该在Y中排成一行,这样您就可以运行其中一个立体对应测试。

I found you need to be using Emgu 2.1 ver 806 to get the cvStereoRectify to work without an Access Violation error. 我发现你需要使用Emgu 2.1 ver 806来使cvStereoRectify工作而不会出现访问冲突错误。


I guess my questions are: 我想我的问题是:

A) Is my process correct? A)我的流程是否正确? I've been doing the camera intrinsic calibration as a separate process because as the cameras are 35cm apart it's not easy to get the chessboard in view of both of them in the office and move it around much.. as it soon goes off the side of one of the camera views. 我一直在做相机固有校准作为一个单独的过程,因为相机相距35厘米,因为它们在办公室中并且两者都移动很多而不容易从棋盘上取下棋盘...因为它很快离开了其中一个相机视图。 I figured that as the values are intrinsic these are related to the camera and therefore should transfer to the stereo procedure OK. 我认为由于值是固有的,因此它们与相机有关,因此应转移到立体声程序OK。 Is this correct? 这个对吗?

It seems that the intrinsic values are getting altered during the cvStereoRectify process, and are being made very different. 看起来内部值在cvStereoRectify过程中会发生变化,并且变得非常不同。

eg. 例如。 Distortion values from first stage = 0.22,-1.2,0.01,-0.01,2.6 after cvStereoRectify the values were changed to= 10,-489,-0.03,-0.09,13208 cvStereoRectify后,第一阶段的失真值= 0.22,-1.2,0.01,-0.01,2.6,值变为= 10,-489,-0.03,-0.09,13208

I'm no expert but the first set seem to be more like what I'd seen from other people's comments, and the second set seem pretty way out! 我不是专家,但第一套看起来更像是我从其他人的评论中看到的,第二套似乎很明显!

B) Is there any way to stop the intrinsic + distortion values being updated during cvStereoRectify? B)有没有办法阻止在cvStereoRectify期间更新内在+失真值?

C) Does this seem right for the intrinsic values (937,0,290,0,932,249,0,0,1)? C)这似乎是正确的内在价值(937,0,290,0,932,249,0,0,1)?

Thanks very much for any tips... I've been stuck on this for a while now... and I'm really not sure which part of the process is throwing up the errors. 非常感谢任何提示...我已经坚持了一段时间了......而且我真的不确定这个过程的哪个部分会引发错误。 Any tips or suggestions would be very welcome... 任何提示或建议都将非常受欢迎......

I haven't used EMGU in a couple of years, but I was using it to calibrate a camera and a Kinect. 我在几年内没有使用过EMGU,但是我用它来校准相机和Kinect。

I found that there can be some confusion with the ordering of the rectangle corners if the rectangle is completely horizontal - I never really got to the bottom of why, and this just seemed to work for me. 我发现如果矩形是完全水平的,那么矩形角的排序可能会有些混乱 - 我从来没有真正理解为什么,这似乎对我有用。 Try setting the board up so that the rectangle is at a roll of 45 degrees (ie from the front you would be look at more of a diamond shape, if that makes any sense). 尝试设置电路板,使矩形处于45度的卷(即从正面看,你会看到更多的钻石形状,如果这有任何意义)。

My very basic understanding is that this should make it easy for both cameras to ensure that they pick the same corner as the first corner to start counting from. 我的基本理解是,这应该使两个摄像机都能轻松确保它们选择与第一个角相同的角来开始计数。

I can't guarantee that this will fix your problem - it could just be that I had something deeply wrong in my code and this was why it failed to produce regular results when the chessboard was flat. 我不能保证这会解决你的问题 - 可能只是因为我的代码中存在严重错误,这就是为什么当棋盘平坦时它无法产生常规结果的原因。 Then again, it won't take you long to test and might just work. 再说一遍,它不会花费你很长时间来测试,可能只是工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM