![](/img/trans.png)
[英]Rowwise operation of copying std::vector into cv::Mat_ of identical sizes
[英]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.