I have this matrix in openCV:
cv::Matx44d m;
and I want to get the top left 3x3 matrix out of this matrix. What is the simplest and fastest way to do this?
I can do it in the following ways:
cv::Matx44d m;
cv::Matx33d o;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
o(i,j)=m(i,j);
}
}
but I am looking for a simpler and faster way if it exist!
CV_32F defines the depth of each element of the matrix, while. CV_32FC1 defines both the depth of each element and the number of channels.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.
In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.
Here's example for CV_64FC1 : CV_ - this is just a prefix. 64 - number of bits per base matrix element (e.g. pixel value in grayscale image or single color element in BGR image) F - type of the base element.
Matx has a function called get_minor() that does exactly what you want. I don't see it in documentation of OpenCV but it is present inside the implementation. In your case it will be:
o = m.get_minor<3,3>(0,0);
Template parameters <3,3> is the height and width of small matrix. Value (0,0) is the starting point from which the matrix is cropped.
why not use a simple constructor ?
Matx44d m = ...;
Mat33xd o( m(0), m(1), m(2),
m(4), m(5), m(6),
m(8), m(9), m(10) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With