簡體   English   中英

從cv :: Mat獲取x,y,z線

[英]Get x,y,z cord from cv::Mat

使用reprojectImageTo3D(..),我得到了帶有3D點的Mat。 現在,我要訪問這些點的x,y,z值。 但是我不知道該怎么辦?

我嘗試過這樣的事情:

(new3d.row(100).col(1)).x 

但這似乎並不以這種方式工作。

非常感謝您的幫助。

正如Miki指出的那樣,您想使用Mat :: at()。 CV文檔中對此進行了概述: http : //docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-at

Mat :: at():返回對指定數組元素的引用。 這是各種簽名:

C++: template<typename T> T& Mat::at(int i) const 
C++: template<typename T> const T& Mat::at(int i) const 
C++: template<typename T> T& Mat::at(int i, int j) 
C++: template<typename T> const T& Mat::at(int i, int j) const 
C++: template<typename T> T& Mat::at(Point pt) 
C++: template<typename T> const T& Mat::at(Point pt) const 
C++: template<typename T> T& Mat::at(int i, int j, int k) 
C++: template<typename T> const T& Mat::at(int i, int j, int k) const 
C++: template<typename T> T& Mat::at(const int* idx) 
C++: template<typename T> const T& Mat::at(const int* idx) const 

Parameters:  
i – Index along the dimension 0 
j – Index along the dimension 1 
k – Index along the dimension 2 
pt – Element position specified as Point(j,i) . 
idx – Array of Mat::dims indices.

這篇文章更加詳細: 如何從cv :: Mat訪問數據

從[文檔]中您可以看到:

C ++:void reprojectImageTo3D(InputArray差異,OutputArray _3dImage,InputArray Q,布爾型handleMissingValues = false,int ddepth = -1)

_3dImage –輸出3通道浮點圖像,其大小與視差相同。 _3dImage(x,y)的每個元素都包含根據視差圖計算的點(x,y)的3D坐標。

因此,您的new3d矩陣是3通道浮點,即CV_32FC3

您可以訪問其值,例如:

for(int r=0; r<new3d.rows; ++r)
{
    for(int c=0; c<new3d.cols; ++c)
    {
        Vec3f point = new3d.at<Vec3f>(r,c);
        // x = point[0];
        // y = point[1];
        // z = point[2];

        std::cout << point << std::endl;
    }
}

暫無
暫無

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

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