#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <ml.h> // opencv machine learning include file
#include "matrix.h"
int main()
{
char data[]="mnist_test0.jpg";
int n = mxGetNumberOfDimensions(data);
int M = mxGetM(data);
int N = mxGetN(data);
uchar *imgData = NULL;
if (mxIsUint8(data) && n == 2)
{
imgData = (uchar *)mxGetPr(data);
h = M;
w = N;
cv::Mat image(h, w, CV_8UC1);
size_t subs[2]; // 三通道图像就需要 subs [3], 后续程序作相应修改
for (int i = 0; i < h; i++)
{
subs[0] = i;
for (int j = 0; j < w; j++)
{
subs[1] = j;
int index = mxCalcSingleSubscript(data, 2, subs);
image.row(i).col(j).data[0] = imgData[index];
}
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdi5oPgojaW5jbHVkZSA8aGlnaGd1aS5oPgojaW5jbHVkZSA8bWwuaD4gICAgICAgIC8vIG9wZW5jdiBtYWNoaW5lIGxlYXJuaW5nIGluY2x1ZGUgZmlsZQojaW5jbHVkZSAgIm1hdHJpeC5oIgppbnQgbWFpbigpCnsKY2hhciBkYXRhW109Im1uaXN0X3Rlc3QwLmpwZyI7CmludCBuID0gbXhHZXROdW1iZXJPZkRpbWVuc2lvbnMoZGF0YSk7ICAKaW50IE0gPSBteEdldE0oZGF0YSk7ICAKaW50IE4gPSBteEdldE4oZGF0YSk7ICAKdWNoYXIgKmltZ0RhdGEgPSBOVUxMOyAgCmlmIChteElzVWludDgoZGF0YSkgJiYgbiA9PSAyKSAgCnsgIAogICBpbWdEYXRhID0gKHVjaGFyICopbXhHZXRQcihkYXRhKTsgIAogICBoID0gTTsgIAogICB3ID0gTjsgIAogICBjdjo6TWF0IGltYWdlKGgsIHcsIENWXzhVQzEpOyAgCiAgIHNpemVfdCBzdWJzWzJdOyAvLyDkuInpgJrpgZPlm77lg4/lsLHpnIDopoEgc3VicyBbM10sIOWQjue7reeoi+W6j+S9nOebuOW6lOS/ruaUuSAgCiAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGg7IGkrKykgIAogICB7ICAKICAgICAgICBzdWJzWzBdID0gaTsgIAogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgdzsgaisrKSAgCiAgICAgICAgIHsgIAogICAgICAgICAgICBzdWJzWzFdID0gajsgIAogICAgICAgICAgICBpbnQgaW5kZXggPSBteENhbGNTaW5nbGVTdWJzY3JpcHQoZGF0YSwgMiwgc3Vicyk7ICAgCiAgICAgICAgICAgICBpbWFnZS5yb3coaSkuY29sKGopLmRhdGFbMF0gPSBpbWdEYXRhW2luZGV4XTsgIAogICAgICAgICB9ICAKICAgICAgfSAgCiAgIH0gIAoKfQ==