10

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.

E_learner
  • 3,512
  • 14
  • 57
  • 88
  • can you elaborate on this question, why do you need to do this conversion, you can create a matrix in opencv and handle it as a vector if this helps. but I assume there is a reason why you are creating a matrix and want to convert it into a matrix. could you provide a scenario why you need that – Moataz Elmasry Dec 04 '12 at 13:54
  • actually I am using it for my another function, which has been eliminated in my question here. – E_learner Dec 04 '12 at 14:03
  • I'm asking this cuz maybe there's a way around this, right now I can't see a way other than answered here, i.e. handle a vector as a matrix which in this case will be a nx1 matrix. can u tell us which function outputs the vector and which function uses the matrix as input? – Moataz Elmasry Dec 04 '12 at 14:23

2 Answers2

16

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.

Rick Smith
  • 9,031
  • 15
  • 81
  • 85
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
3

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.

satishffy
  • 153
  • 8