Ask Your Question

Revision history [back]

click to hide/show revision 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)

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())
{
    // 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;

}

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>

#include <iostream>
#include <fstream>
using namespace std;

include <opencv2 opencv.hpp="">

std; #include <opencv2/opencv.hpp> using namespace cv;

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

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;
}

}

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;
}