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++)
{
for (int j=0; j<gray.cols; j++)
{
trainmat.at<float>(k,ii++) = gray.at<uchar>(i,j);
}
}
k=k+1;
}
cout << trainmat << endl;
}
int img_area=250000; // how did you get this number ?