I' trying to get cloud of points from two stereo images using OpenCV, but I can't get coordinates.
- I found points coordinates using Optical Flow
- I found projection matrixes for cameras.
Mat RT1;<br> hconcat(R, T1, RT1);<br> Mat P1 = C*RT1;<br>
R is 3x3 rotation matrix, T is 3x1 transform matrix (column), P1 - projection matrix.
- I pass them to triangulatePoints function
triangulatePoints(P1, P2, leftPoints, rightPoints, out);
P1 and P2 is 3x4 projection matrix (Mat_<double>). leftPoints and rightPoints is std::vector of Point2f. What is out? It should be 1xN matrix of 4D coords. Is this Vec4f?
I am trying get coordinates
for (int i = 0; i < out.cols; i++) { Vec4f vec = out.at<Vec4f>(0, i); float w = vec[3]; stream << "v " << vec[0] / w << " " << vec[1]/w << " " << vec[2]/w << "\n"; }
But I have two problems:
- This cycle throw exception (works for small i, about 20% of out.cols)
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p1 * cha nnels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file c:\opencv\build\includ e\opencv2\core\mat.inl.hpp, line 89
I think this is some kind of Index Out Range Exception
- Result is very strange: Image
So, I am doing something wrong. How correctly work with this function and get 3D coordinates of points? I'll hope you can help me.


