OpenCV :创建矩阵或矩阵向量

opencv : create matrix or vector of matrices

本文关键字:向量 OpenCV 创建      更新时间:2023-10-16

我有以下代码,这是我遵循的算法的一部分。 如您所见,我需要对 10 个不同的波段进行一些计算。 并且最终会为每个波段创建一个矩阵,我需要从中重新创建图像, 问题是我不知道如何在while循环中创建/保存10个不同的矩阵, 然后在while循环之后,我可以一一构建图像。如果您有任何想法,请告诉我谢谢

cv::Mat _reconstructionMatrix(height,width,CV_8UC1);
_reconsPointer = _reconstructionMatrix.ptr<uchar>(0);   
    while(_bandIteration<_bandsNumber){                     
if(_mainMatrix.isContinuous())
{
    nCols *= nRows;
    nRows = 1;
}
//for all the pixels 
for(int i = 0; i < nRows; i++)
{           
    p = _mainMatrix.ptr<uchar>(i);
    //in the images
    for (int  j = 0; j < nCols; j++)
    {               
        if(_pCounter<_totalImgNO){              
            ....
        }else{                                                      
            ...
            _reconsPointer[_resultFlag]=_summation; 
            _resultFlag++;
            ...             
        }
    }                   
}           
_bandIteration++;
}

你的问题有点模糊。但是,如果您只是问how to create/hold the 10 different matrix on the while loop?那么您可以正常使用 STL 向量。

#include<vector>
...   
std::vector<cv::Mat> listOfMatrices;
...       
cv::Mat M = SomehowGetMatrix();
listOfMatrices.push_back(M);

如果这不是您要找的,那么请为您的问题提供更多详细信息。