我正在嘗試使用 OpenCV 計算表面法線。下面是代碼片段:
// load 16bit uchar depth image (values are in millimeters)
cv::Mat img = cv::imread("depth.png", CV_16UC1);
// define our camera matrix
cv::Mat k = (cv::Mat1d(3, 3) << 900, 0, 640, 0, 900, 360, 0, 0, 1);
// compute surface normals
cv::Mat normals;
cv::rgbd::RgbdNormals normal_computer(img.rows, img.cols, CV_32F, k, 3);
normal_computer(img, normals);
std::cout << "normals" << std::endl
<< normals << std::endl
<< normals.size() << std::endl
<< normals.channels() << std::endl
<< std::endl;
不幸的是,它顯示以下錯誤:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.2.0) ../contrib/modules/rgbd/src/normal.cpp:776: error: (-215:Assertion failed) points3d_ori.channels() == 3 in function 'operator()'
Aborted (core dumped)
根據檔案,輸入點應該是 CV_32F/CV64F 的行 x 列 x 3 矩陣或行 x 列 x 1 CV_U16S。
因此,我的問題是如何將深度影像轉換為上述合適的格式(即 CV_32F/CV64F 的行 x cols x 3 矩陣或行 x cols x 1 CV_U16S)?
PS:我在 Ubuntu 20.04 LTS 上使用 OpenCV v4.2.0。
uj5u.com熱心網友回復:
原來OpenCV中有一個叫depthTo3d的函式來做這個轉換。請看以下代碼片段:
cv::Mat points3d;
cv::rgbd::depthTo3d(img, k, points3d);
轉換后,這些點應作為輸入給出,如下所示:
normal_computer(points3d, normals);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/486908.html
