-1

I have a 1D vector of point2f. I am storing those points in 2D Mat of size 6x6. How to access these points now?

van
  • 15
  • 9
  • Which language are you using? Can you also attach sample code snippet as well ? – ZdaR Jul 26 '18 at 09:49
  • what's the type of the mat elements? Why 6x6 Mat? Doesn't it depend on the number of points (the size of the vector)? – Micka Jul 26 '18 at 09:58
  • @ZdaR I am using VS open CV 3.2, C++. I will attach the code now. – van Jul 31 '18 at 05:09
  • @Micka Type of Mat is float. 6x6 is my requirement. And yes it also depends on the size of vector. I will attach the code snippet for clarification – van Jul 31 '18 at 05:11

1 Answers1

0

Thanks for the help:) I sorted the answer now.

vector<Point2f>centers(36); //I have 1D vector of points which is of size 36
Mat new_mat = Mat(centers).reshape(6, 6); //1d vector to 6x6matrix

**/*Actually the Point2f, when stored in Mat makes use of the channels for storing the float values*/**

Mat test = new_mat.reshape(2, 6);// this makes 6 channels into two rows

**/*My objective here is to transpose the vector  which is now stored in Mat*/**

Mat q1 = test.t();//transposed 6 channel mat

vector<Point2f>x(q1.begin<Point2f>(), q1.end<Point2f>());//transposed vector

Now we can access the Point2f stored in Mat, by test.at(0,1) or accordingly.

Summary: vectorx -> Mat (2D) size 6x6 -> reshape-> do req changes or modification in the Mat ->Converted again to vectorx_output

van
  • 15
  • 9