簡體   English   中英

cv :: Mat_到std :: vector的轉換

[英]cv::Mat_ to std::vector conversion

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

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

當實例化,實施不會對2005年MSVS編譯:

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
        ]

不,在C ++ 0x中有一些來自rvalues的新構造函數,但與這里使用的類似。

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

否則,您的迭代器版本似乎正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM