8 #include <opencv2/opencv.hpp>
13 std::ios::fmtflags flags;
14 std::streamsize precision;
17 IOSave( std::ios& userStream )
18 : stream( userStream )
19 , flags( userStream.flags() )
20 , precision( userStream.precision() )
21 , fill( userStream.fill() )
26 stream.flags( flags );
27 stream.precision( precision );
38 std::string indent() { return std::string(indentLvl * 4, ' '); }
45 FTrace(DbgTracer &dt, const char *fn, const char *format, ...) : t(dt), funcName(fn)
51 if (-1 == vasprintf(&arg, format, vl))
52 throw std::runtime_error("vasprintf error");
55 std::cerr << t.indent() << funcName << "(" << arg << ") {" << std::endl;
62 std::cerr << t.indent() << "}" << std::endl;
67 void traceVal(const char *name, const T& obj, int line)
71 std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
74 template <typename T> struct Printer {
76 Printer(const T &_obj) : obj(_obj) {}
79 template <typename T> Printer<T> print(const T& obj) { return Printer<T>(obj); }
80 Printer<cv::Mat> print(const MatScales& obj) { return Printer<cv::Mat>(obj); }
81 Printer<cv::Mat> print(const MatFeats& obj) { return Printer<cv::Mat>(obj); }
82 Printer<cv::Mat> print(const MatScaleFeats& obj) { return Printer<cv::Mat>(obj); }
86 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p)
91 #if CV_VERSION_MAJOR < 3 || CV_VERSION_MINOR < 3
92 std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
94 int i, dims = msize.p[-1];
95 for (i = 0; i < dims; i++) {
103 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p)
106 os << std::setprecision(3);
107 os << p.obj.size << " " << p.obj.channels() << "ch ";// << static_cast<const void *>(p.obj.data);
109 constexpr size_t num = 10;
110 for (size_t i = 0; i < std::min(num, p.obj.total()); ++i)
111 os << p.obj.ptr<float>()[i] << ", ";
112 os << (num < p.obj.total() ? "... ]" : "]");
116 std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
123 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p)
126 os << std::setprecision(3);
127 os << "<cplx> " << p.obj.size() << " " << p.obj.channels() << "ch "; // << p.obj.get_p_data();
129 constexpr int num = 10;
130 for (int i = 0; i < std::min(num, p.obj.size().area()); ++i)
131 os << p.obj.get_p_data()[i] << ", ";
132 os << (num < p.obj.size().area() ? "... ]" : "]");
136 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
138 #define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
139 #define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)