0

With reprojectImageTo3D(..) I get an Mat with 3D Points. Now I want to access the x,y,z values of these Points. But I don't know how I can do this?

I tryed something like this:

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

But it don't seems to work this way.

I would be very thankful for any help here.

IIIIIIIIIIIIIIIIIIIIII
  • 3,958
  • 5
  • 45
  • 70

2 Answers2

2

As Miki pointed out, you want to use Mat::at(). This is outlined in the CV documentation: http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-at

Mat::at():Returns a reference to the specified array element. It's various signatures:

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.

This post goes into more detail: How to access data from cv::Mat

Community
  • 1
  • 1
Brock Hargreaves
  • 842
  • 6
  • 12
1

From the [documentation] you see that:

C++: void reprojectImageTo3D(InputArray disparity, OutputArray _3dImage, InputArray Q, bool handleMissingValues=false, int ddepth=-1 )

_3dImage – Output 3-channel floating-point image of the same size as disparity . Each element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity map.

So your new3d matrix is a 3 channel floating point, i.e. CV_32FC3.

You can access its values like:

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;
    }
}
Miki
  • 40,887
  • 13
  • 123
  • 202