8 #include <opencv2/opencv.hpp>
10 #include "complexmat.hpp"
14 #include "nvToolsExt.h"
21 std::ios::fmtflags flags;
22 std::streamsize precision;
25 IOSave( std::ios& userStream )
26 : stream( userStream )
27 , flags( userStream.flags() )
28 , precision( userStream.precision() )
29 , fill( userStream.fill() )
34 stream.flags( flags );
35 stream.precision( precision );
45 static constexpr int precision = 2;
47 std::string indent() { return std::string(indentLvl * 4, ' '); }
54 FTrace(DbgTracer &dt, const char *fn, const char *format, ...) : t(dt), funcName(fn)
63 if (-1 == vasprintf(&arg, format, vl))
64 throw std::runtime_error("vasprintf error");
67 std::cerr << t.indent() << funcName << "(" << arg << ") {" << std::endl;
77 std::cerr << t.indent() << "}" << std::endl;
82 void traceVal(const char *name, const T& obj, int line, bool always = false)
85 if (debug || always) {
87 std::cerr << std::setprecision(precision);
88 std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
92 template <typename T> struct Printer {
94 Printer(const T &_obj) : obj(_obj) {}
97 template <typename T> Printer<T> print(const T& obj) { return Printer<T>(obj); }
98 Printer<cv::Mat> print(const MatScales& obj) { return Printer<cv::Mat>(obj); }
99 Printer<cv::Mat> print(const MatFeats& obj) { return Printer<cv::Mat>(obj); }
100 Printer<cv::Mat> print(const MatScaleFeats& obj) { return Printer<cv::Mat>(obj); }
103 template <typename T>
104 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p)
110 #if CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION < 3
111 static inline std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
113 int i, dims = msize.p[-1];
114 for (i = 0; i < dims; i++) {
123 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p);
126 static inline std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
133 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p);
135 extern DbgTracer __dbgTracer;
137 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
139 #define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
140 #define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)
141 #define PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__, true)