cout_mat.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. * cvout_sample just demonstrates the serial out capabilities of cv::Mat
  4. * That is, cv::Mat M(...); cout << M; Now works.
  5. *
  6. */
  7. #include "opencv2/core.hpp"
  8. #include <iostream>
  9. using namespace std;
  10. using namespace cv;
  11. static void help(char** argv)
  12. {
  13. cout
  14. << "\n------------------------------------------------------------------\n"
  15. << " This program shows the serial out capabilities of cv::Mat\n"
  16. << "That is, cv::Mat M(...); cout << M; Now works.\n"
  17. << "Output can be formatted to OpenCV, matlab, python, numpy, csv and \n"
  18. << "C styles Usage:\n"
  19. << argv[0]
  20. << "\n------------------------------------------------------------------\n\n"
  21. << endl;
  22. }
  23. int main(int argc, char** argv)
  24. {
  25. cv::CommandLineParser parser(argc, argv, "{help h||}");
  26. if (parser.has("help"))
  27. {
  28. help(argv);
  29. return 0;
  30. }
  31. Mat I = Mat::eye(4, 4, CV_64F);
  32. I.at<double>(1,1) = CV_PI;
  33. cout << "I = \n" << I << ";" << endl << endl;
  34. Mat r = Mat(10, 3, CV_8UC3);
  35. randu(r, Scalar::all(0), Scalar::all(255));
  36. cout << "r (default) = \n" << r << ";" << endl << endl;
  37. cout << "r (matlab) = \n" << format(r, Formatter::FMT_MATLAB) << ";" << endl << endl;
  38. cout << "r (python) = \n" << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl;
  39. cout << "r (numpy) = \n" << format(r, Formatter::FMT_NUMPY) << ";" << endl << endl;
  40. cout << "r (csv) = \n" << format(r, Formatter::FMT_CSV) << ";" << endl << endl;
  41. cout << "r (c) = \n" << format(r, Formatter::FMT_C) << ";" << endl << endl;
  42. Point2f p(5, 1);
  43. cout << "p = " << p << ";" << endl;
  44. Point3f p3f(2, 6, 7);
  45. cout << "p3f = " << p3f << ";" << endl;
  46. vector<float> v;
  47. v.push_back(1);
  48. v.push_back(2);
  49. v.push_back(3);
  50. cout << "shortvec = " << Mat(v) << endl;
  51. vector<Point2f> points(20);
  52. for (size_t i = 0; i < points.size(); ++i)
  53. points[i] = Point2f((float)(i * 5), (float)(i % 7));
  54. cout << "points = " << points << ";" << endl;
  55. return 0;
  56. }