cv :: Mat_到std :: vector的转换 [英] cv::Mat_ to std::vector conversion

查看:470
本文介绍了cv :: Mat_到std :: vector的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV 2.0,在cv::Mat_<_Tp>类中有一个方法:

I use OpenCV 2.0, there is a method in the cv::Mat_<_Tp> class:

// conversion to vector.
operator vector<_Tp>() const;

实例化后,该实现将无法在MSVS 2005上编译:

When instantiated, the implementation does not compile on MSVS 2005:

template<typename _Tp> inline Mat_<_Tp>::operator vector<_Tp>() const
{
    CV_Assert( rows == 1 || cols == 1 );
    return isContinuous() ? vector<_Tp>((size_t)(rows + cols - 1), (_Tp*)data) :
        (vector<_Tp>)((Mat_<_Tp>)this->t());
}

std::vector的新式构造函数,它从TR1或其他工具中获取了size_t_Tp*吗?

Is it a new fancy constructor of std::vector that takes size_t and _Tp* from TR1 or something?

我认为他们可以通过迭代器来初始化矢量:

I thought they could just initialize the vector by an iterator instead:

vector<_Tp>((_Tp*)data, (_Tp*)data + rows + cols - 1)

是错误,还是我不知道什么?

Is it a bug, or don't I know something?

UPD.编译器错误文字:

UPD. Compiler error text:

...\lib\opencv\include\opencv\cxmat.hpp(691) : error C2665: 'std::vector<_Ty>::vector' : none of the 6 overloads could convert all the argument types
        with
        [
            _Ty=double
        ]
        c:\program files\microsoft visual studio 8\vc\include\vector(473): could be 'std::vector<_Ty>::vector(__w64 unsigned int,const _Ty &)'
        with
        [
            _Ty=double
        ]
        while trying to match the argument list '(size_t, double *)'
        ...\lib\opencv\include\opencv\cxmat.hpp(689) : while compiling class template member function 'cv::Mat_<_Tp>::operator std::vector<_Ty>(void) const'
        with
        [
            _Tp=double,
            _Ty=double
        ]
        z:\dev\mine\temp\temp\entry.cpp(37) : see reference to class template instantiation 'cv::Mat_<_Tp>' being compiled
        with
        [
            _Tp=double
        ]

推荐答案

不,在C ++ 0x中有来自rvalues的新构造函数,但与此处使用的构造函数完全不同.

No, there are new constructors from rvalues in C++0x, but nothing like the one used here.

如果isContinuous()表示所有值都相同,则可以使用vector<_Tp>((size_t)(rows + cols - 1), *(_Tp*)data)复制第一个值.

If isContinuous() means that all vales are the same, you could possibly use vector<_Tp>((size_t)(rows + cols - 1), *(_Tp*)data) to make copies of the first value.

否则,您的迭代器版本似乎正确.

Your iterator version seems correct otherwise.

这篇关于cv :: Mat_到std :: vector的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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