opencv/samples/cpp/cout_mat.cpp

64 lines
1.7 KiB
C++
Raw Normal View History

2010-11-20 10:04:41 +08:00
/*
*
* cvout_sample just demonstrates the serial out capabilities of cv::Mat
* That is, cv::Mat M(...); cout << M; Now works.
*
*/
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace std;
using namespace cv;
2012-06-08 01:21:29 +08:00
static void help()
2010-11-20 10:04:41 +08:00
{
2012-06-08 01:21:29 +08:00
cout
<< "\n------------------------------------------------------------------\n"
<< " This program shows the serial out capabilities of cv::Mat\n"
<< "That is, cv::Mat M(...); cout << M; Now works.\n"
<< "Output can be formated to OpenCV, python, numpy, csv and C styles"
<< "Usage:\n"
<< "./cvout_sample\n"
<< "------------------------------------------------------------------\n\n"
<< endl;
2010-11-20 10:04:41 +08:00
}
int main(int,char**)
{
2012-06-08 01:21:29 +08:00
help();
Mat I = Mat::eye(4, 4, CV_64F);
I.at<double>(1,1) = CV_PI;
cout << "I = " << I << ";" << endl;
Mat r = Mat(10, 3, CV_8UC3);
randu(r, Scalar::all(0), Scalar::all(255));
cout << "r (default) = " << r << ";" << endl << endl;
cout << "r (python) = " << format(r,"python") << ";" << endl << endl;
cout << "r (numpy) = " << format(r,"numpy") << ";" << endl << endl;
2012-06-08 01:21:29 +08:00
cout << "r (csv) = " << format(r,"csv") << ";" << endl << endl;
cout << "r (c) = " << format(r,"C") << ";" << endl << endl;
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);
2012-06-08 01:21:29 +08:00
cout << "shortvec = " << Mat(v) << endl;
2012-06-08 01:21:29 +08:00
vector<Point2f> points(20);
for (size_t i = 0; i < points.size(); ++i)
2010-11-26 00:55:46 +08:00
points[i] = Point2f((float)(i * 5), (float)(i % 7));
cout << "points = " << points << ";" << endl;
return 0;
}