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);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How should I use OpenCV images in Waffle for training models ?
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);
(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.)
Thanks for this really useful code.