Ask Your Question
0

What is the difference between Vec<Mat> and Mat

asked 2013-01-14 14:24:50 -0600

southpark gravatar image

Hi Guys,

I got confused with the usage of vector<mat> and Mat.

Example: vector<mat> images; images.push_back(imread("example.jpg")); //loop

bool CvSVM::train(const Mat& trainData, const Mat& responses, const Mat& varIdx=Mat(), const Mat& sampleIdx=Mat(), CvSVMParams params=CvSVMParams() )

For SVM, it requires the input to be Mat structure. How do you make the conversion?

Another question is with the usage of push_back.

"The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of the STL vector class. When elem is Mat , its type and the number of columns must be the same as in the container matrix."-from opencv.org

However, is push_back a concatenation operator or just grouping them into a cell structure? You can access data by images[0], images[1],...

If you define "Mat images" and then use images.push_back, the result is a concatenation of matrix.

Thanks for your clarification.

Sorry if the question seems naive.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-01-14 15:10:22 -0600

matt.hammer gravatar image
vector<mat> images; images.push_back(imread("example.jpg"))

This creates an array (vector is a C++ STL wrapper around arrays) of matrices and puts the image "example.jpg" into a matrix and pushes that matrix onto the first position of the array.

Is your confusion attributable to the fact that both a vector and an OpenCV matrix have a push_back() member function? They pretty much do the same thing, but to different data types.

To "convert" from a vector of matrices to a single matrix with concatenation, i think you could do something like this to use OpenCV push_back to build a "compound" matrix (by popping matrices off the front of the vector and concatenating):

Mat imageConcat;   while(images.size() != 0)  {imageConcat.push_back(images.front());  images.erase(0);}

However, in my (admittedly limited) experience with SVMs I don't think you want to dump a whole image in there. All you'd be doing is training on each horizontal row of pixel data - I don't think that's what you want (unless you've got some cool algorithm going that does exactly that). Training on raw image data is probably too many SVM dimensions anyways.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-01-14 14:24:50 -0600

Seen: 11,085 times

Last updated: Jan 14 '13