Menu

How can we use OpenCV image for training NN model in Waffle?

Help
Eren Golge
2015-04-18
2015-04-20
  • Eren Golge

    Eren Golge - 2015-04-18

    How should I use OpenCV images in Waffle for training models ?

     
  • Mike Gashler

    Mike Gashler - 2015-04-19

    Waffles is designed to work with arrays of doubles. Code to convert from OpenCV CV_8UC3 format might look something like this. (Disclaimer: untested code)

    uint8_t pixelPtr = (uint8_t)foo.data;
    int cn = foo.channels();
    double pVec = new double[foo.rows * foo.cols * 3];
    double
    v = pVec;
    for(int i = 0; i < foo.rows; i++)
    {
    for(int j = 0; j < foo.cols; j++)
    {
    v++ = (double)pixelPtr[ifoo.colscn + j*cn + 0] / 256.0; // B
    v++ = (double)pixelPtr[ifoo.colscn + j*cn + 1] / 256.0; // G
    *v++ = (double)pixelPtr[ifoo.colscn + j*cn + 2] / 256.0; // R
    }
    }
    ...
    neural_net.trainIncremental(pVec, &label);

     
  • Mike Gashler

    Mike Gashler - 2015-04-19

    (It looks like the SF forum removed my indentation. Also, there is an asterisk in front of each "v++", and between i and foo and cn.)

     
  • Eren Golge

    Eren Golge - 2015-04-20

    Thanks for this really useful code.

     

Anonymous
Anonymous

Add attachments
Cancel