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

大兔子大兔子 提交于 2019-12-12 05:07:02

问题


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


来源:https://stackoverflow.com/questions/38140179/how-to-fill-vector-with-images-in-opencv-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!