Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to load multiple images using videocapture and then store it in 1D matrices?

I have tried to use the following code to do the above task: Can you say what did I do wrong?

include <iostream>

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 ml="" ml.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

using namespace std; using namespace cv;

int main(int argc, char** argv) { VideoCapture cap("/home/bapi/workspace/%03d.jpg"); int img_files= 2; int img_area=250000; int k=0;

Mat trainmat(img_files,img_area,CV_32FC1);

Mat image_mat; Mat gray;

for(;;) { cap >> image_mat; cvtColor(image_mat,gray,CV_BGR2GRAY); if(gray.empty())

{ cout << "end of sequence" << std::endl; return -1; }

int ii=0;

for (int i=0; i<gray.rows; i++)<="" p="">

{ for (int j=0; j<gray.cols; j++)="" {="" trainmat.at<float="">(k,ii++) = gray.at<uchar>(i,j);

}

}

k=k+1; } cout << trainmat << endl;

}

click to hide/show revision 2
No.2 Revision

updated 2015-02-22 08:44:18 -0600

berak gravatar image

How to load multiple images using videocapture and then store it in 1D matrices?

I have tried to use the following code to do the above task: Can you say what did I do wrong?

include <iostream>

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
#include <opencv2/imgproc/imgproc.hpp>
  

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 ml="" ml.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

using namespace std; using namespace cv;

cv;

int main(int argc, char** argv) { VideoCapture cap("/home/bapi/workspace/%03d.jpg"); int img_files= 2; int img_area=250000; int k=0;

k=0; Mat trainmat(img_files,img_area,CV_32FC1);

Mat trainmat(img_files,img_area,CV_32FC1);

Mat image_mat; Mat gray;

gray;

for(;;) { cap >> image_mat; cvtColor(image_mat,gray,CV_BGR2GRAY); if(gray.empty())

if(gray.empty())

{ cout << "end of sequence" << std::endl; return -1; }

} int ii=0;

int ii=0;

for (int i=0; i<gray.rows; i++)<="" p=""> i++)

{ for (int j=0; j<gray.cols; j++)="" {="" trainmat.at<float="">(k,ii++) j++) { trainmat.at<float>(k,ii++) = gray.at<uchar>(i,j);

gray.at<uchar>(i,j);

}

} }

}

k=k+1; } cout << trainmat << endl;

endl;

}

}