fork download
  1. #include <stdio.h>
  2. #include <cv.h>
  3. #include <highgui.h>
  4. #include <ml.h> // opencv machine learning include file
  5. #include "matrix.h"
  6. int main()
  7. {
  8. char data[]="mnist_test0.jpg";
  9. int n = mxGetNumberOfDimensions(data);
  10. int M = mxGetM(data);
  11. int N = mxGetN(data);
  12. uchar *imgData = NULL;
  13. if (mxIsUint8(data) && n == 2)
  14. {
  15. imgData = (uchar *)mxGetPr(data);
  16. h = M;
  17. w = N;
  18. cv::Mat image(h, w, CV_8UC1);
  19. size_t subs[2]; // 三通道图像就需要 subs [3], 后续程序作相应修改
  20.  
  21. for (int i = 0; i < h; i++)
  22. {
  23. subs[0] = i;
  24. for (int j = 0; j < w; j++)
  25. {
  26. subs[1] = j;
  27. int index = mxCalcSingleSubscript(data, 2, subs);
  28. image.row(i).col(j).data[0] = imgData[index];
  29. }
  30. }
  31. }
  32.  
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:16: fatal error: cv.h: No such file or directory
compilation terminated.
stdout
Standard output is empty