C++ 在 OpenCV 中将向量转换为 mat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13699901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert vector to mat in OpenCV
提问by E_learner
I am using opencv 2.4.3 to perform vector to matrix conversion using the following code:
我正在使用 opencv 2.4.3 使用以下代码执行向量到矩阵的转换:
struct Component
{
cv::Rect box;
double area;
double circularity;
}
int main ( ... )
{
cv::vector < Component > components;
cv::Mat componentMat ( components, true );
std::cout << componentMat;
return 0;
}
But it gives out an error, saying:
但它给出了一个错误,说:
OpenCV Error: Unsupported format or combination of formats() in unknown function, file ...\opencv\modules\core\src\out.cpp, line 111
What am I doing wrong here? Is there any other method to convert this vector into matrix form? Thank you.
我在这里做错了什么?有没有其他方法可以将此向量转换为矩阵形式?谢谢你。
回答by Jav_Rock
In the documentationthere is a reference to the Mat constructor in which they say which types of vector are supported:
在文档中有对 Mat 构造函数的引用,其中说明了支持哪些类型的向量:
"The constructor can handle arbitrary types, for which there is properly declared DataType , i.e. the vector elements must be primitive numbers or uni-type numerical tuples of numbers. Mixed-type structures are not supported, of course."
“构造函数可以处理任意类型,为其正确声明了 DataType,即向量元素必须是原始数字或数字的单类型数字元组。当然,不支持混合类型结构。”
So the type you are using is not supportedand therefore you get an error.
所以您使用的类型不受支持,因此您会收到错误消息。
回答by CV Enthusiast
You are trying to create Matrix of type "components". It would not work. Mat supports only specific data types, like Point2d, Point3d, etc. If you try with them, it should work.
您正在尝试创建“组件”类型的矩阵。这是行不通的。Mat 仅支持特定的数据类型,如 Point2d、Point3d 等。如果您尝试使用它们,它应该可以工作。