Ask Your Question

Revision history [back]

OpenCV does not contain a builtin file reading system. Just use the C++ interface. Starting from the idea that you are using the ifstream interface and that each row is a new line and the colums are stured by a seperator which is a comma. this code can work for you.

ifstream inputfle("periods of arnold transform.csv"); string current_line; // vector allows you to add data without knowing the exact size beforehand vector< vector<int> > all_data; // Start reading lines as long as there are lines in the file while(getline(inputfile, current_line)){ // Now inside each line we need to seperate the cols vector<int> values; stringstream temp(current_line); string single_value; while(getline(current_line,single_value,',')){ // convert the string element to a integer value values.push_back(atoi(single_value.c_str())); } // add the row to the complete data vector all_data.push_back(values); }

// Now add all the data into a Mat element Mat vect = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1); // Loop over vectors and add the data for(int rows = 0; row < (int)all_data.size(); rows++){ for(int cols= 0; cols< (int)all_data[0].size(); cols++){ vect.at<uchar>(rows,cols) = all_data[rows][cols]; } }

OpenCV does not contain a builtin file reading system. Just use the C++ interface. Starting from the idea that you are using the ifstream interface and that each row is a new line and the colums are stured by a seperator which is a comma. this code can work for you.

ifstream inputfle("periods of arnold transform.csv");
string current_line;
// vector allows you to add data without knowing the exact size beforehand
vector< vector<int> > all_data;
// Start reading lines as long as there are lines in the file
while(getline(inputfile, current_line)){
// Now inside each line we need to seperate the cols
vector<int> values;
stringstream temp(current_line);
string single_value;
while(getline(current_line,single_value,',')){
// convert the string element to a integer value
values.push_back(atoi(single_value.c_str()));
}
// add the row to the complete data vector
all_data.push_back(values);
}

} // Now add all the data into a Mat element Mat vect = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1); // Loop over vectors and add the data for(int rows = 0; row < (int)all_data.size(); rows++){ for(int cols= 0; cols< (int)all_data[0].size(); cols++){ vect.at<uchar>(rows,cols) = all_data[rows][cols]; } }

}

OpenCV does not contain a builtin file reading system. Just use the C++ interface. Starting from the idea that you are using the ifstream interface and that each row is a new line and the colums are stured by a seperator which is a comma. this code can work for you.

ifstream inputfle("periods of arnold transform.csv");
string current_line;
// vector allows you to add data without knowing the exact size beforehand
vector< vector<int> > all_data;
// Start reading lines as long as there are lines in the file
while(getline(inputfile, current_line)){
   // Now inside each line we need to seperate the cols
   vector<int> values;
   stringstream temp(current_line);
   string single_value;
   while(getline(current_line,single_value,',')){
while(getline(temp,single_value,',')){
        // convert the string element to a integer value
        values.push_back(atoi(single_value.c_str()));
   }
   // add the row to the complete data vector
   all_data.push_back(values);
}

// Now add all the data into a Mat element
Mat vect = Mat::zeros((int)all_data.size(), (int)all_data[0].size(), CV_8UC1);
// Loop over vectors and add the data
for(int rows = 0; row < (int)all_data.size(); rows++){
   for(int cols= 0; cols< (int)all_data[0].size(); cols++){
      vect.at<uchar>(rows,cols) = all_data[rows][cols];
   }
}