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