opencv:创建矩阵或矩阵向量

时间:2012-05-23 13:39:50

标签: c++ image-processing opencv matrix

我有以下代码,这是我正在遵循的算法的一部分。如你所见,我需要为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++;
}

1 个答案:

答案 0 :(得分:6)

你的问题有点模糊。但是,如果您只是简单地询问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);

如果这不是您想要的,请提供更详细的问题。

相关问题