cv :: Mat_到std :: vector转换

时间:2011-03-23 12:14:02

标签: c++ stl visual-studio-2005 vector opencv

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

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

实例化时,实现不会在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*吗?

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

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

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

UPD。编译器错误文本:

...\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
        ]

1 个答案:

答案 0 :(得分:0)

不,在C ++ 0x中有来自rvalues的新构造函数,但没有像这里使用的那样。

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

你的迭代器版本似乎是正确的。

相关问题