parent
f2df784830
commit
08b7855edc
6 changed files with 455 additions and 226 deletions
@ -1,79 +0,0 @@ |
|||||||
#ifndef __OPENCV_CORE_CVOUT_HPP__ |
|
||||||
#define __OPENCV_CORE_CVOUT_HPP__ |
|
||||||
#ifdef __cplusplus |
|
||||||
|
|
||||||
#ifndef SKIP_INCLUDES |
|
||||||
#include <iomanip> |
|
||||||
#include <iostream> |
|
||||||
#include <vector> |
|
||||||
#endif |
|
||||||
|
|
||||||
namespace cv |
|
||||||
{ |
|
||||||
|
|
||||||
/** Writes a point to an output stream in Matlab notation
|
|
||||||
*/ |
|
||||||
inline std::ostream & operator<<(std::ostream & out, const Point2f & p) |
|
||||||
{ |
|
||||||
out << "[ " << p.x << "," << p.y << " ]"; |
|
||||||
return out; |
|
||||||
} |
|
||||||
|
|
||||||
/** Writes a point to an output stream in Matlab notation
|
|
||||||
*/ |
|
||||||
inline std::ostream & operator<<(std::ostream & out, const Point3f & p) |
|
||||||
{ |
|
||||||
out << "[ " << p.x << "," << p.y << "," << p.z << " ]"; |
|
||||||
return out; |
|
||||||
} |
|
||||||
|
|
||||||
/** \brief write points to and output stream
|
|
||||||
* \param out typically cout |
|
||||||
* \param points the points to be written to the stream |
|
||||||
* \return the stream |
|
||||||
**/ |
|
||||||
CV_EXPORTS std::ostream & operator<<(std::ostream & out, const std::vector<Point2f> & points); |
|
||||||
|
|
||||||
/** \brief write points to and output stream
|
|
||||||
* \param out typically cout |
|
||||||
* \param points the points to be written to the stream |
|
||||||
* \return the stream |
|
||||||
**/ |
|
||||||
std::ostream & operator<<(std::ostream & out, const std::vector<Point3f> & points); |
|
||||||
|
|
||||||
/** \brief allows each output of Mat in Matlab for Mat to std::cout
|
|
||||||
* use like |
|
||||||
@verbatim |
|
||||||
Mat my_mat = Mat::eye(3,3,CV_32F); |
|
||||||
std::cout << my_mat; |
|
||||||
@endverbatim |
|
||||||
*/ |
|
||||||
CV_EXPORTS std::ostream & operator<<(std::ostream & out, const Mat & mat); |
|
||||||
|
|
||||||
/** \brief write a Mat in csv compatible for Matlab.
|
|
||||||
This means that the rows are seperated by newlines and the |
|
||||||
columns by commas .... |
|
||||||
331.413896619595,0,122.365880226491 |
|
||||||
0,249.320451610369,122.146722131871 |
|
||||||
0,0,1 |
|
||||||
|
|
||||||
* \param out output stream to write to |
|
||||||
* \param Mat write a Mat to a csv |
|
||||||
*/ |
|
||||||
CV_EXPORTS std::ostream & writeCSV(std::ostream & out, const Mat & mat); |
|
||||||
|
|
||||||
/** \brief write a vector of points to an
|
|
||||||
output stream if possible |
|
||||||
**/ |
|
||||||
CV_EXPORTS std::ostream & writeCSV(std::ostream & out, const std::vector<Point2f> & points); |
|
||||||
|
|
||||||
/** \brief write a vector of points to an
|
|
||||||
output stream if possible |
|
||||||
**/ |
|
||||||
CV_EXPORTS std::ostream & writeCSV(std::ostream & out, const std::vector<Point3f> & points); |
|
||||||
|
|
||||||
} //namespace cv
|
|
||||||
|
|
||||||
#endif |
|
||||||
|
|
||||||
#endif |
|
@ -1,34 +1,41 @@ |
|||||||
#include "opencv2/core/core.hpp" |
#include "opencv2/core/core.hpp" |
||||||
|
#include <iostream> |
||||||
|
|
||||||
using namespace std; |
using namespace std; |
||||||
using namespace cv; |
using namespace cv; |
||||||
|
|
||||||
int main() |
int main(int,char**) |
||||||
{ |
{ |
||||||
Mat i = Mat::eye(4, 4, CV_32F); |
Mat i = Mat::eye(4, 4, CV_64F); |
||||||
cout << "i = " << i << ";" << endl; |
i.at<double>(1,1) = CV_PI; |
||||||
|
cout << "i = " << i << ";" << endl; |
||||||
|
|
||||||
Mat r = Mat(10, 10, CV_8UC1); |
Mat r = Mat(10, 3, CV_8UC3); |
||||||
randu(r, Scalar(0), Scalar(255)); |
randu(r, Scalar::all(0), Scalar::all(255)); |
||||||
|
|
||||||
cout << "r = " << r << ";" << endl; |
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; |
||||||
|
|
||||||
Point2f p(5, 1); |
Point2f p(5, 1); |
||||||
cout << "p = " << p << ";" << endl; |
cout << "p = " << p << ";" << endl; |
||||||
|
|
||||||
Point3f p3f(2, 6, 7); |
Point3f p3f(2, 6, 7); |
||||||
cout << "p3f = " << p3f << ";" << endl; |
cout << "p3f = " << p3f << ";" << endl; |
||||||
|
|
||||||
vector<Point2f> points(20); |
vector<float> v; |
||||||
for (size_t i = 0; i < points.size(); ++i) |
v.push_back(1); |
||||||
{ |
v.push_back(2); |
||||||
points[i] = Point2f(i * 5, i % 7); |
v.push_back(3); |
||||||
} |
|
||||||
cout << "points = " << points << ";" << endl; |
|
||||||
|
|
||||||
cout << "#csv" << endl; |
cout << "shortvec = " << Mat(v) << endl; |
||||||
|
|
||||||
writeCSV(cout, r); |
vector<Point2f> points(20); |
||||||
|
for (size_t i = 0; i < points.size(); ++i) |
||||||
|
points[i] = Point2f(i * 5, i % 7); |
||||||
|
|
||||||
return 1; |
cout << "points = " << points << ";" << endl; |
||||||
|
return 0; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue