【发布时间】:2016-01-15 00:51:06
【问题描述】:
我正在创建一个在 Simulink S-Function(它是 c++ 代码)中实现的视觉算法。除了颜色和深度图像的对齐之外,我完成了所有想要的事情。
我的问题是如何使 2 个图像相互对应。换句话说,我如何使用 opencv 制作 3d 图像。
我知道我的问题可能有点含糊,所以我将包含我的代码来解释问题
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
// reading in the color and depth image
Mat color = imread("whitepaint_col.PNG", CV_LOAD_IMAGE_UNCHANGED);
Mat depth = imread("whitepaint_dep.PNG", CV_LOAD_IMAGE_UNCHANGED);
// show bouth the color and depth image
namedWindow("color", CV_WINDOW_AUTOSIZE);
imshow("color", color);
namedWindow("depth", CV_WINDOW_AUTOSIZE);
imshow("depth", depth);
// thershold the color image for the color white
Mat onlywhite;
inRange(color, Scalar(200, 200, 200), Scalar(255, 255, 255), onlywhite);
//display the mask
namedWindow("onlywhite", CV_WINDOW_AUTOSIZE);
imshow("onlywhite", onlywhite);
// apply the mask to the depth image
Mat nocalibration;
depth.copyTo(nocalibration, onlywhite);
//show the result
namedWindow("nocalibration", CV_WINDOW_AUTOSIZE);
imshow("nocalibration", nocalibration);
waitKey(0);
destroyAllWindows;
return 0;
}
从我的程序输出中可以看出,当我将 onlywhite 蒙版应用于深度图像时,四旋翼机身不包含 1 种颜色。原因是 2 张图片之间存在未匹配。
我知道我需要我的相机的校准参数,我是从最后一个使用此设置的人那里得到的。在 Matlab 中进行了校准,结果如下。
我花了很多时间阅读以下关于相机校准和 3D 重建的 opencv 页面(由于堆栈交换 lvl 无法包含链接)
但我终其一生都无法弄清楚如何实现为每个彩色像素添加正确深度值的目标。
我尝试使用 reprojectImageTo3D() 但我无法计算出 Q 矩阵。 我还尝试了从该页面分配其他功能,但我似乎无法正确输入。
【问题讨论】:
-
如果您正在编写自己的 Simulink 模块,您可以尝试在 MATLAB 中使用 MATLAB Function Block。
标签: c++ matlab opencv computer-vision matlab-cvst