I have a vectorimageSlices and a 3D :
cv::Mat RTstruct3D(3,DImensions3D, CV_8U, Scalar(0))
I want to put my vector into the specific index of 3D cv::Mat.
//Make a 3D Organ
int programCounter = 0;
vector<Mat>imageSlices;
for (size_t k = 0; k < Npoint_Z.size(); k )
{
Mat finalSliceImage = Mat :: zeros(DImensions3D[0], DImensions3D[1],CV_8U);
vector<vector<int>> polies;
for (size_t h = 0; h < Npoint_Z[k][0]; h )
{
vector<int>x_y;
x_y.push_back(ContourData[programCounter][0]); //x
x_y.push_back(ContourData[programCounter][1]); //y
polies.push_back(x_y);
programCounter ;
}
fillPoly(finalSliceImage, polies, Scalar(0, 255, 0));
imageSlices.push_back(finalSliceImage);
}
//Add Organ to RTSTRUCT 3D
Mat RTstruct3D(3,DImensions3D, CV_8U, Scalar(0));
Please help me! Thanks.
CodePudding user response:
You can try to use
Mat cv::Mat::operator() ( const std::vector< Range > & ranges ) const
to access the submatrix and then use
Mat& cv::Mat::operator= ( const Mat & m )
Example:
int main() {
cv::Mat m1(10, 10, CV_8U, cv::Scalar(1));
vector<cv::Mat> v = {m1, m1, m1};
std::array<int, 3> dims = {10, 10, 10};
cv::Mat m2(3, dims.data(), CV_8U);
vector<cv::Range> rV = {cv::Range(0, 1), cv::Range(0, 10), cv::Range(0, 10)};
m2(rV.data()) = v[0];
return 0;
}
CodePudding user response:
vector<Mat> RTstruct3D(DImensions3D[0]);
for (size_t f = 0; f < Npoint_Z.size(); f )
{
RTstruct3D[Npoint_Z[f][1]] = imageSlices[f];
}