Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert vector to mat in OpenCV

I am using opencv 2.4.3 to perform vector to matrix conversion using the following code:

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.

like image 406
E_learner Avatar asked Dec 04 '12 09:12

E_learner


2 Answers

In the documentation there is a reference to the Mat constructor in which they say which types of vector are supported:

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

So the type you are using is not supported and therefore you get an error.

like image 87
Jav_Rock Avatar answered Oct 17 '22 21:10

Jav_Rock


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.

like image 25
satishffy Avatar answered Oct 17 '22 21:10

satishffy