cout_mat.cpp 1.68 KB
Newer Older
wester committed
1 2 3 4 5 6 7
/*
 *
 * cvout_sample just demonstrates the serial out capabilities of cv::Mat
 *  That is, cv::Mat M(...); cout << M;  Now works.
 *
 */

a  
Kai Westerkamp committed
8
#include "opencv2/core/core.hpp"
wester committed
9 10 11 12 13 14 15 16 17 18 19
#include <iostream>

using namespace std;
using namespace cv;

static void help()
{
    cout
    << "\n------------------------------------------------------------------\n"
    << " This program shows the serial out capabilities of cv::Mat\n"
    << "That is, cv::Mat M(...); cout << M;  Now works.\n"
wester committed
20 21
    << "Output can be formated to OpenCV, python, numpy, csv and C styles"
    << "Usage:\n"
wester committed
22 23 24 25 26 27
    << "./cvout_sample\n"
    << "------------------------------------------------------------------\n\n"
    << endl;
}


wester committed
28
int main(int,char**)
wester committed
29
{
wester committed
30
    help();
wester committed
31 32
    Mat I = Mat::eye(4, 4, CV_64F);
    I.at<double>(1,1) = CV_PI;
wester committed
33
    cout << "I = " << I << ";" << endl;
wester committed
34 35 36 37

    Mat r = Mat(10, 3, CV_8UC3);
    randu(r, Scalar::all(0), Scalar::all(255));

wester committed
38 39 40 41 42
    cout << "r (default) = " << r << ";" << endl << endl;
    cout << "r (python) = " << format(r,"python") << ";" << endl << endl;
    cout << "r (numpy) = " << format(r,"numpy") << ";" << endl << endl;
    cout << "r (csv) = " << format(r,"csv") << ";" << endl << endl;
    cout << "r (c) = " << format(r,"C") << ";" << endl << endl;
wester committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

    Point2f p(5, 1);
    cout << "p = " << p << ";" << endl;

    Point3f p3f(2, 6, 7);
    cout << "p3f = " << p3f << ";" << endl;

    vector<float> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);

    cout << "shortvec = " << Mat(v) << endl;

    vector<Point2f> points(20);
    for (size_t i = 0; i < points.size(); ++i)
        points[i] = Point2f((float)(i * 5), (float)(i % 7));

    cout << "points = " << points << ";" << endl;
    return 0;
}