Home | History | Annotate | Download | only in cpp
      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/core.hpp"
      9 #include <iostream>
     10 
     11 using namespace std;
     12 using namespace cv;
     13 
     14 static void help()
     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 formated to OpenCV, matlab, python, numpy, csv and \n"
     21     << "C styles Usage:\n"
     22     << "./cvout_sample\n"
     23     << "------------------------------------------------------------------\n\n"
     24     << endl;
     25 }
     26 
     27 
     28 int main(int,char**)
     29 {
     30     help();
     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 
     35     Mat r = Mat(10, 3, CV_8UC3);
     36     randu(r, Scalar::all(0), Scalar::all(255));
     37 
     38     cout << "r (default) = \n" << r << ";" << endl << endl;
     39     cout << "r (matlab) = \n" << format(r, Formatter::FMT_MATLAB) << ";" << endl << endl;
     40     cout << "r (python) = \n" << format(r, Formatter::FMT_PYTHON) << ";" << endl << endl;
     41     cout << "r (numpy) = \n" << format(r, Formatter::FMT_NUMPY) << ";" << endl << endl;
     42     cout << "r (csv) = \n" << format(r, Formatter::FMT_CSV) << ";" << endl << endl;
     43     cout << "r (c) = \n" << format(r, Formatter::FMT_C) << ";" << endl << endl;
     44 
     45     Point2f p(5, 1);
     46     cout << "p = " << p << ";" << endl;
     47 
     48     Point3f p3f(2, 6, 7);
     49     cout << "p3f = " << p3f << ";" << endl;
     50 
     51     vector<float> v;
     52     v.push_back(1);
     53     v.push_back(2);
     54     v.push_back(3);
     55 
     56     cout << "shortvec = " << Mat(v) << endl;
     57 
     58     vector<Point2f> points(20);
     59     for (size_t i = 0; i < points.size(); ++i)
     60         points[i] = Point2f((float)(i * 5), (float)(i % 7));
     61 
     62     cout << "points = " << points << ";" << endl;
     63     return 0;
     64 }
     65