【问题标题】:How to fill vector with images in OpenCV? C++如何在 OpenCV 中用图像填充矢量? C++
【发布时间】:2016-07-01 08:03:19
【问题描述】:

我创建了向量std::vector<cv::Mat> main_layers; 放在一个类中。向量尚未启动。我还在构造函数启动列表中启动了公共成员cv::Mat source;。现在我有了一个复制方法,可以将图像的片段复制到 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);
            }
        };
    };

这里我有错误: gaussian.cpp(133): error C2664: 'void cv::Mat::copyTo(cv::OutputArray) const' : cannot convert parameter 1 from 'std::_Vector_iterator&lt;_Myvec&gt;' to 'cv::OutputArray' 在线 copyTo。如何从向量中的当前图像中获取数组?关于 C++98,使用 Visual Studio 2010。

【问题讨论】:

  • 这个问题source(roi).copyTo(*primarySegment);可能很容易解决,迭代器基本上是一个元素的指针,所以需要解引用。
  • 顺便说一句,autostd::next 来自 C++11,因此如果您想要 C++98 解决方案,则不应使用它们。
  • @Ken:嗯,它使用 *primarySegment 编译我只是想知道 Visual Studio 2010 编译了 C++11——因为我认为 VS2010 具有 C++98 标准。但是如果编译没有问题,那就没问题了。谢谢,您可以将其作为答案发送,以便我投票。
  • @Ken:但在运行时我发现:调试断言失败:向量迭代器不可引用 ... *primarySegment

标签: c++ opencv vector c++98


【解决方案1】:

完美运行

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

【讨论】:

    猜你喜欢
    • 2021-07-20
    • 2017-05-28
    • 1970-01-01
    • 2011-05-19
    • 2015-12-02
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多