1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #20618 from VadimLevin:dev/vlevin/fix-vector-conversion

This commit is contained in:
Alexander Alekhin
2021-09-01 10:52:37 +00:00
5 changed files with 432 additions and 267 deletions
+47
View File
@@ -5,6 +5,7 @@
#include "precomp.hpp"
#include "opencv2/core/bindings_utils.hpp"
#include <sstream>
#include <iomanip>
namespace cv { namespace utils {
@@ -208,4 +209,50 @@ CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argume
return ss.str();
}
static inline std::ostream& operator<<(std::ostream& os, const cv::Rect& rect)
{
return os << "[x=" << rect.x << ", y=" << rect.y << ", w=" << rect.width << ", h=" << rect.height << ']';
}
template <class T, class Formatter>
static inline String dumpVector(const std::vector<T>& vec, Formatter format)
{
std::ostringstream oss("[", std::ios::ate);
if (!vec.empty())
{
oss << format << vec[0];
for (std::size_t i = 1; i < vec.size(); ++i)
{
oss << ", " << format << vec[i];
}
}
oss << "]";
return oss.str();
}
static inline std::ostream& noFormat(std::ostream& os)
{
return os;
}
static inline std::ostream& floatFormat(std::ostream& os)
{
return os << std::fixed << std::setprecision(2);
}
String dumpVectorOfInt(const std::vector<int>& vec)
{
return dumpVector(vec, &noFormat);
}
String dumpVectorOfDouble(const std::vector<double>& vec)
{
return dumpVector(vec, &floatFormat);
}
String dumpVectorOfRect(const std::vector<Rect>& vec)
{
return dumpVector(vec, &noFormat);
}
}} // namespace