Opencv 将视差贴图转换为三维点
我有一张图像的视差图。我需要将其转换为一组3D点和法线。我如何才能做到这一点?是否有任何这样的现有实现可以做到这一点 当我之前做过这件事时,我有一个深度图(或者视差图,如果你愿意的话),并且知道原始的相机校准,能够为点执行重新投影回R3 知道每个点的邻域(通过它们原始的相邻像素),然后创建一个基本的三角剖分将它们连接起来是非常简单的 (如果您不知道这一点,您将不得不尝试某种形式的Delaunay三角剖分或其他更高级的算法…) 确保每个三角形的顶点顺序正确,以确保所有法线指向正确的方向/一致性 对于任何附加的后处理来说都非常方便Opencv 将视差贴图转换为三维点,opencv,computer-vision,Opencv,Computer Vision,我有一张图像的视差图。我需要将其转换为一组3D点和法线。我如何才能做到这一点?是否有任何这样的现有实现可以做到这一点 当我之前做过这件事时,我有一个深度图(或者视差图,如果你愿意的话),并且知道原始的相机校准,能够为点执行重新投影回R3 知道每个点的邻域(通过它们原始的相邻像素),然后创建一个基本的三角剖分将它们连接起来是非常简单的 (如果您不知道这一点,您将不得不尝试某种形式的Delaunay三角剖分或其他更高级的算法…) 确保每个三角形的顶点顺序正确,以确保所有法线指向正确的方向/一致性 对
cvFindStereoCorrespondenceBM( frame1r, frame2r, disp, BMState);
/* cvShowImage("camera1", frame1);
cvShowImage("camera2", frame2); */
// cvConvertScale( disp, disp, 16, 0 );
cvNormalize( disp, vdisp, 0, 256, CV_MINMAX );
cvShowImage( "disparity", vdisp );
cvReprojectImageTo3D(disp, Image3D, &_Q);
cvShowImage("depthmap",Image3D);
我希望这段代码能对您有所帮助。这里对代码的解释如下:当我校正来自左右摄像头的图像并定义
BMstate
时,我已将其传递到cvFindStereoCorrespondenceBM
以查找视差图像。接下来定义尺寸为3的矩阵,以将三维点存储为Image3D
。通过opencvcvreprojectionmageto3d
中的函数传递我们在立体对应中获得的Q矩阵,我们获得了与该2D图像相对应的3D点集如果您的答案解释了为什么这样做是有帮助的,那么它将更有帮助;实际上,纯粹的代码片段往往得不到很多支持。Donald Fellows,编辑了解释最好在代码中添加一些解释。所以这不是一个“代码库”,而是一个帮助网站。添加解释是回答问题的最佳方式不仅代码很重要,而且它的工作原理和工作原理与问题的解决方案一样重要。如果您只需要3d点,此功能可以在速度上得到改进。。。如果你需要,请投票,我会添加速度代码。
@ here is calculation which may help you
% %Z = fB/d
% where
% Z = distance along the camera Z axis
% f = focal length (in pixels)
% B = baseline (in metres)
% d = disparity (in pixels)
% % After Z is determined, X and Y can be calculated using the usual projective camera equations:
%
% X = uZ/f
% Y = vZ/f
% where
% u and v are the pixel location in the 2D image
% X, Y, Z is the real 3d position
% Note: u and v are not the same as row and column. You must account for the image center. You can get the image center using the triclopsGetImageCenter() function. Then you find u and v by:
% u = col - centerCol
% v = row - centerRow
% Note: If u, v, f, and d are all in pixels and X,Y,Z are all in the meters, the units will always work i.e. pixel/pixel = no-unit-ratio = m/m.