adding the Brief descriptor, associated hamming distance functors for bruteforce matching. Also adding cout << cv::Mat functions in core.
This commit is contained in:
@@ -4055,5 +4055,6 @@ public:
|
||||
|
||||
#include "opencv2/core/operations.hpp"
|
||||
#include "opencv2/core/mat.hpp"
|
||||
#include "opencv2/core/cvout.hpp"
|
||||
|
||||
#endif /*__OPENCV_CORE_HPP__*/
|
||||
|
79
modules/core/include/opencv2/core/cvout.hpp
Normal file
79
modules/core/include/opencv2/core/cvout.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#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
|
139
modules/core/src/cvout.cpp
Normal file
139
modules/core/src/cvout.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
std::ostream & writevec(std::ostream & out, const std::vector<T> & points)
|
||||
{
|
||||
typedef T MT_T;
|
||||
typedef typename std::vector<T>::const_iterator CIT;
|
||||
/* Draw Me:
|
||||
plot2( pts1(:,1),pts1(:,2),'r.') */
|
||||
std::streamsize pp = out.precision();
|
||||
out.precision(15);
|
||||
out << "[";
|
||||
|
||||
CIT it = points.begin();
|
||||
|
||||
for (; it != points.end(); ++it)
|
||||
{
|
||||
|
||||
out << *it;
|
||||
CIT next = it;
|
||||
if (++next != points.end())
|
||||
{
|
||||
out << " ";
|
||||
}
|
||||
}
|
||||
out << "]";
|
||||
out.precision(pp);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & writeelem(std::ostream & out, const Mat & mat, int i, int j)
|
||||
{
|
||||
if (mat.type() == CV_32F)
|
||||
out << mat.at<float> (i, j);
|
||||
else if (mat.type() == CV_64F)
|
||||
out << mat.at<double> (i, j);
|
||||
else if (mat.type() == CV_32S)
|
||||
out << mat.at<int> (i, j);
|
||||
else if (mat.type() == CV_8U)
|
||||
out << int(mat.at<unsigned char> (i, j));
|
||||
else if (mat.type() == CV_16U)
|
||||
out << int(mat.at<unsigned short> (i, j));
|
||||
else
|
||||
out << "?";
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const std::vector<Point2f> & points)
|
||||
{
|
||||
return writevec(out, points);
|
||||
}
|
||||
std::ostream & operator<<(std::ostream & out, const std::vector<Point3f> & points)
|
||||
{
|
||||
return writevec(out, points);
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const Mat & _mat)
|
||||
{
|
||||
std::streamsize pp = out.precision();
|
||||
out.precision(15);
|
||||
std::vector<Mat> channels;
|
||||
split(_mat, channels);
|
||||
for (int chn = 0; chn < _mat.channels(); chn++)
|
||||
{
|
||||
Mat mat = channels[chn];
|
||||
out << "[";
|
||||
for (int i = 0; i < mat.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < mat.cols; j++)
|
||||
{
|
||||
writeelem(out,mat,i,j);
|
||||
if (j < mat.cols - 1)
|
||||
out << " ";
|
||||
}
|
||||
if (i < mat.rows - 1)
|
||||
out << ";\n";
|
||||
}
|
||||
out << "]";
|
||||
}
|
||||
out.precision(pp);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & writeCSV(std::ostream & out, const std::vector<Point3f> & points)
|
||||
{
|
||||
std::streamsize pp = out.precision();
|
||||
out.precision(15);
|
||||
std::vector<Point3f>::const_iterator it = points.begin();
|
||||
|
||||
for (; it != points.end(); ++it)
|
||||
{
|
||||
out << it->x << "," << it->y << ","<< it->z << "\n";
|
||||
}
|
||||
out.precision(pp);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & writeCSV(std::ostream & out, const std::vector<Point2f> & points)
|
||||
{
|
||||
std::streamsize pp = out.precision();
|
||||
out.precision(15);
|
||||
std::vector<Point2f>::const_iterator it = points.begin();
|
||||
|
||||
for (; it != points.end(); ++it)
|
||||
{
|
||||
out << it->x << "," << it->y << "\n";
|
||||
}
|
||||
out.precision(pp);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & writeCSV(std::ostream & out, const Mat & mat)
|
||||
{
|
||||
std::streamsize pp = out.precision();
|
||||
out.precision(15);
|
||||
for (int i = 0; i < mat.rows; i++)
|
||||
{
|
||||
|
||||
for (int j = 0; j < mat.cols; j++)
|
||||
{
|
||||
writeelem(out,mat,i,j);
|
||||
if (j < mat.cols - 1)
|
||||
out << ",";
|
||||
}
|
||||
out << "\n";
|
||||
}
|
||||
out.precision(pp);
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user