By : zigmo
Date : November 19 2020, 12:41 AM

it helps some times I have 3D Mat and would like to convert it to Vector. I tried opencv's reshape() function but it seems to not work with matrices that have dimensions more than 2. How can I convert to 3D Mat to Vector ? I can do it by accessing all elements in the Mat. Is there any efficient way? , If we have the following 3D matrix: code :
const int ROWS=2, COLS=3, PLANES=4;
int dims[3] = {ROWS, COLS, PLANES};
cv::Mat m = cv::Mat(3, dims, CV_32SC1); // works with other types (e.g. float, double,...)
const int* p3 = m3.ptr<int>(0);
std::vector<int> flat0(p3, p3+m3.total());
cv::Mat m2(ROWS, COLS*PLANES, CV_32SC1, m3.data); // no copying happening here
cv::Mat m2xPlanes = m2.reshape(PLANES); // not sure if this involves a copy
std::vector<Mat> planes;
cv::split(m2xPlanes, planes); // usually used for splitting multichannel matrices
std::vector<int> flat;
for(size_t i=0; i<planes.size(); i++) {
cv::Mat plane_i = planes[i];
const int* plane_i_ptr = plane_i.ptr<int>(0);
flat.insert(flat.end(), plane_i_ptr, plane_i_ptr+plane_i.total());
}
int index = row * COLS * PLANES + col * PLANES + p
Share :

How do I create a vector of cv::matrix in opencv and assign submatrix of image data to matrices on all index of vector
By : Jason H
Date : March 29 2020, 07:55 AM
I wish this helpful for you I want to create a vector of cv::Matrix in a c++ program and on each index i want to copy the submatrix of an image, for example; , To make a real copy you can do code :
VectorMat[i]=threshImage(cv::Rect(x,y,max.xmin.x,max.ymin.y)).clone();
threshImage(cv::Rect(x,y,max.xmin.x,max.ymin.y)).copyTo(VectorMat[i]);

How to access vector<vector<Point>> contours in opencv like matrix element?
By : Micah Carpenter II
Date : March 29 2020, 07:55 AM
This might help you If my situation was so urgent, I would ask my question more carefully. If I try hard to understand your question, you basically want to consider a contour in pixel level. In order to do that, you should draw the contour into a blank matrix with drawContour. And then compare two matrices or match a pixel in that matrix in case you want pixel by pixel.

calling OpenCV calibration functions to calculate rotation vector and translation vector
By : Neo
Date : March 29 2020, 07:55 AM
To fix the issue you can do If I understand you well, you have 4 points in the image and you know their world coordinates (you have 4 2D3D correspondences) to find the rotation matrix and translation vector (known as the camera pose), you can use the solvePnP function. This function takes as inputs the 3D coordinates, 2D coordinates, the camera matrix (focal distance and center of projection) and the distortion coefficients, which you should have obtained by an intrinsic calibration process. The output is the rotation and translation vectors. The obtained rotation vector can be transformed in to a rotation matrix with the function Rodrigues.

OpenCV: Conversion of vector<vector<Point>> to vector<Mat>, problems with call by reference
By : user2673380
Date : March 29 2020, 07:55 AM
This might help you You are using the right constructor but incorrectly accepting the default for the second parameter. The declaration for the Mat constructor taking std::vector as an input: code :
//! builds matrix from std::vector with or without copying the data
template<typename _Tp> explicit Mat(const vector<_Tp>& vec, bool copyData=false);

OpenCV, findContours  Why do we need a <vector<vector<Point>> to store the contours? Why not just <ve
By : Rashedul Hasan
Date : March 29 2020, 07:55 AM
With these it helps For your first question, why there are no contour points stored in contours[n][k] for all n > 0, you may have only one contour in your contours vector, which is contours[0]. The reason for the vector in a vector is because the code :
vector<Point>
vector<vector<Point>>



Related Posts :
