opencv 将std::vector导入< Mat>3D cv::Mat的特定索引

w1jd8yoj  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(173)

我有一个矢量图像切片和一个3D:

cv::Mat RTstruct3D(3,DImensions3D, CV_8U, Scalar(0))

我想把我的向量放到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));

类似于以下图像:

请帮帮我!谢谢。

cngwdvgl

cngwdvgl1#

您可以尝试使用Mat cv::Mat::operator()(const std::vector < Range >& ranges)const来访问子矩阵,然后使用Mat& cv::Mat::operator=(const Mat & m)
示例:

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;
}
vof42yt1

vof42yt12#

//Add Organ to RTSTRUCT 3D
        vector<Mat>RTstruct3D(DImensions3D[0], Mat(DImensions3D[1], DImensions3D[2], CV_8U));
        for (size_t i = 0; i < Npoint_Z.size(); i++)
        {
            RTstruct3D[Npoint_Z[i][1]] = imageSlices[i];
        }

相关问题