c++ - 在 OpenCV 中将 vector 转换为垫子

标签 c++ opencv vector matrix type-conversion

我正在使用 opencv 2.4.3 使用以下代码执行 vector 到矩阵的转换:

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; 
}

但是它给出了一个错误,说:

OpenCV Error: Unsupported format or combination of formats() in unknown function, file ...\opencv\modules\core\src\out.cpp, line 111

我在这里做错了什么?还有其他方法可以将此 vector 转换为矩阵形式吗?谢谢你。

最佳答案

the documentation有一个对 Mat 构造函数的引用,其中他们说支持哪些类型的 vector :

"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."

所以不支持您使用的类型,因此您会收到错误消息。

关于c++ - 在 OpenCV 中将 vector 转换为垫子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13699901/

相关文章:

python - 在 Python、OpenCV 中使用切片从图像中提取区域

vector - 如何在不出现错误 "cannot borrow as mutable more than once at a time"的情况下递增向量中的每个数字?

c++ - STL vector 错误 : Unknown type name

C++ - 按字母顺序排列字符串

c++ - 模板函数和 const 限定符中的类型推导

xcode - OpenCV编译有关 “cvloadimage”的错误,在main.o中引用自:_main

c++ - 我的 C++ 程序正在打印地址而不是值

c++ - 如果互斥量由成员管理,您是否需要类/结构的互斥量?

c++ - 为什么将枚举声明标记为 const?

c++ - OpenCV 轮廓时刻?