1 | initial version |
if your data is from https://www.kaggle.com/c/facial-keypoints-detection, then rather try like this:
(avoid all string conversions in the 1st place)
using namespace std;
using namespace cv;
int main(int argc, char **argv) { const int imgsize = 96; // not 48, see: https://www.kaggle.com/c/facial-keypoints-detection/data?test.zip
vector<int> ids;
vector<Mat> imgs;
ifstream in("test.csv");
// skip 1st row:
string dummy;
getline(in, dummy);
while(! in.bad())
{
// read id:
int id;
in >> id;
ids.push_back(id);
// skip the bloody comma ;(
char comma;
in >> comma;
// read pixels into a flat column:
Mat img;
for (int i=0; i<imgsize*imgsize; i++)
{
int pixel;
in >> pixel;
img.push_back(uchar(pixel));
}
// reshape to quad again:
img = img.reshape(1,imgsize);
imgs.push_back(img);
cerr << id << endl;
imshow("face", img);
waitKey(200);
}
return 0;
}
2 | No.2 Revision |
if your data is from https://www.kaggle.com/c/facial-keypoints-detection, then rather try like this:
(avoid all string conversions in the 1st place)
#include <iostream>
#include <fstream>
using namespace
}
3 | No.3 Revision |
if your data is from https://www.kaggle.com/c/facial-keypoints-detection, then rather try like this:
(avoid all string conversions in the 1st place)
#include <iostream>
#include <fstream>
using namespace std;
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char **argv)
{
const int imgsize = 96; // not 48, see: https://www.kaggle.com/c/facial-keypoints-detection/data?test.zip
vector<int> ids;
vector<Mat> imgs;
ifstream in("test.csv");
// skip 1st row:
string dummy;
getline(in, dummy);
while(! in.bad())
for(int i=0; i<1783; i++)
{
// read id:
int id;
in >> id;
ids.push_back(id);
// skip the bloody comma ;(
char comma;
in >> comma;
// read pixels into a flat column:
Mat img;
for (int i=0; i<imgsize*imgsize; i++)
{
int pixel;
in >> pixel;
img.push_back(uchar(pixel));
}
// reshape to quad again:
img = img.reshape(1,imgsize);
imgs.push_back(img);
cerr << id << endl;
imshow("face", img);
waitKey(200);
waitKey(2);
}
return 0;
}