How to fill vector with images in OpenCV? C++

2019-09-10 21:52发布

问题:

I created vector std::vector<cv::Mat> main_layers; placed in a class. The vector has not been initiated yet. I have also public member cv::Mat source; initiated in constructor initiation list. Now I have a copy method to copy segments of the image to main_layers:

void copy(){
    Rect roi;           
    auto primarySegment = main_layers.begin();
    for (int c = 0; c< primaryKernelsLoad; c++)
        {
        if (heightPriority)
            {
            roi = Rect(0, c, size.width, segment1Size);
            source(roi).copyTo(primarySegment);
            auto nx = std::next(primarySegment, 2);
            }
        };
    };

Here I have error: gaussian.cpp(133): error C2664: 'void cv::Mat::copyTo(cv::OutputArray) const' : cannot convert parameter 1 from 'std::_Vector_iterator<_Myvec>' to 'cv::OutputArray' on line with copyTo. How can I get the array from the current image in vector? With regards to C++98, using Visual Studio 2010.

回答1:

Works perfectly

void copy(){
    Rect roi;           
    for (int c = 0; c< primaryKernelsLoad; c++)
        {
        if (heightPriority)
            {
            roi = cv::Rect(0, c, size.width, segment1Size);
            main_layers.push_back(source(roi));
            }
        };
};