opencv 2.3 copyTo函数无法像在2.2中那样工作 [英] opencv 2.3 copyTo function not working as it was in 2.2

查看:96
本文介绍了opencv 2.3 copyTo函数无法像在2.2中那样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在编写一些OpenCV C ++代码,但无法将代码从OpenCV 2.2移植到2.3.1.现在的主要问题是Mat::copyTo函数.他们在文档或发行说明中提到,虽然此函数的新版本采用了OutputArray,但旧代码仍将起作用(即Mat::copyTo(Mat &m)).问题是它不起作用.

So, I am writing some OpenCV C++ code and I am having trouble porting my code from OpenCV 2.2 to 2.3.1. The main problem right now is the Mat::copyTo function. In the documentation or the release notes, they have mentioned that while the new version of this function takes OutputArray, the old code should still work (i.e., Mat::copyTo(Mat &m)). The thing is that it does not work.

这是我的代码

void copyMatRows(Mat &src,Mat &dest,int start_pos)
{
    for(int i=0; i < src.rows;i++)
    {
        int dest_y = start_pos;

        if(start_pos < 1)
        {
            dest_y = dest_y+i;
        }
        src.row(i).copyTo(dest.row(dest_y));

    }
}

因此在上面的代码行中

src.row(i).copyTo(dest.row(dest_y));

出现错误

没有匹配函数可调用cv :: Mat :: copyTo(cv :: Mat)候选对象 是:void cv :: Mat :: copyTo(const cv :: _ OutputArray&)const

no matching function for call to cv::Mat::copyTo(cv::Mat) candidates are: void cv::Mat::copyTo(const cv::_OutputArray&) const

任何帮助将不胜感激?我可以以任何方式解决此问题?

Any help would be appreciated? any way in which i can fix this?

我想做的是获得N个矩阵并将它们全部组合成一个大矩阵.

What I am trying to do is to get N number of matrices and combine them all in one big matrix.

推荐答案

这应该可以修复您的功能,但是我不确定它是否在完全按照您的要求进行操作:

This should fix your function, but I'm not sure it's doing exactly what you want:

void copyMatRows(Mat &src, Mat &dest, int start_pos)
{
    for(int i = 0; i < src.rows; i++)
    {
        int dest_y = start_pos;

        if(start_pos < 1)
        {
            dest_y = dest_y + i;
        }

        Mat destRow = dest.row(dest_y);
        src.row(i).copyTo(destRow);
    }
}

这应该可以满足您的需求:

EDIT : This should do pretty much what you're looking for:

void appendMatRows(Mat &src, Mat &dst, int start_pos)
{
    for(int i = start_pos; i < src.rows; i++)
    {
        dst.push_back(src.row(i));
    }
}

push_back成员函数的主要警告是列数必须相同,但是我认为您不必为此担心.

The main caveat with the push_back member function is that the number of columns must be the same, but I don't think you're too worried about that.

希望有帮助!

这篇关于opencv 2.3 copyTo函数无法像在2.2中那样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆