簡體   English   中英

opencv :: Mat結構用於使用深度圖?

[英]opencv::Mat structure for using depth maps?

我正在將圖像讀取到cv::Mat.

cv::Mat depth_map = cv::imread("patio_depth.jpg", -1);

然后將Mat傳遞給此函數:(從深度圖獲取xyz坐標)。

inline cv::Point3d getPoint3D(int x, int y) const
{
    cv::Point3d point;
    point.x = depth_map.at<cv::Vec3f>(y, x)[0];
    point.y = depth_map.at<cv::Vec3f>(y, x)[1];
    point.z = depth_map.at<cv::Vec3f>(y, x)[2];

    return point;
}

這會導致斷言錯誤。

Assertion failed <dims <= 2 && data && <unsigned>i0 <unsigned>size.p[0] && <unsigned><i1*DataType<_Tp>::channels>

在\\ core \\ mat.hpp中

我認為這意味着我正在使用的Mat與該功能不兼容,但是哪種Mat結構會起作用? 還是我需要通過某種方式對其進行轉換?

嗯,這是因為我使用的是jpg圖片。 (如opencv論壇上回答)

'您正在讀取JPG圖片,因此您會在depth_map中獲得BGR圖片,而不是浮動圖片。 您應該使用cv :: Vec3b而不是cv :: Vec3f來訪問像素。

奇跡般有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM