]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Improve debug prints
authorMichal Sojka <michal.sojka@cvut.cz>
Sat, 22 Sep 2018 14:45:46 +0000 (16:45 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Sat, 22 Sep 2018 16:56:31 +0000 (18:56 +0200)
- Prints can produce different things based on type.
- Print data pointer for matrices
- Omit matrix data for now (we may add them later)

src/complexmat.hpp
src/kcf.cpp

index e234c0e443f7c4d6af594fd9a39a9506a569f06f..c3877a85c9b095fa7291aca48592f3bc33009015 100644 (file)
@@ -145,6 +145,7 @@ template <typename T> class ComplexMat_ {
     }
 
     std::complex<T> *get_p_data() { return p_data.data(); }
+    const std::complex<T> *get_p_data() const { return p_data.data(); }
 
     // element-wise per channel multiplication, division and addition
     ComplexMat_<T> operator*(const ComplexMat_<T> &rhs) const
index 448ee03cc8cd8e1a6dc366e63b2d26f567914c1b..1ba12ead7284a4505d0f1a44823f2075cb0dae5a 100644 (file)
@@ -55,23 +55,48 @@ class DbgTracer {
             std::cerr << t.indent() << "}" << std::endl;
         }
     };
+
+    template <typename T>
+    void traceVal(const char *name, const T& obj, int line)
+    {
+        (void)line;
+        if (debug)
+            std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
+    }
+
+    template <typename T> struct Printer {
+        const T &obj;
+        Printer(const T &_obj) : obj(_obj) {}
+    };
+
+    template <typename T> Printer<T> print(const T& obj) { return Printer<T>(obj); }
+    Printer<cv::Mat> print(const MatScales& obj) { return Printer<cv::Mat>(obj); }
+    Printer<cv::Mat> print(const MatFeats& obj) { return Printer<cv::Mat>(obj); }
+    Printer<cv::Mat> print(const MatScaleFeats& obj) { return Printer<cv::Mat>(obj); }
 };
 
+template <typename T>
+std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p) {
+    os << p.obj;
+    return os;
+}
+std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p) {
+    os << p.obj.size << " " << p.obj.channels() << "ch " << static_cast<const void*>(p.obj.data);
+    return os;
+}
+template <>
+std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p) {
+    os << "<cplx> " << p.obj.size() << " " << p.obj.channels() << "ch " << p.obj.get_p_data();
+    return os;
+}
+
 DbgTracer __dbgTracer;
 
 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
 
-#define DEBUG_PRINT(obj)                                                \
-    if (__dbgTracer.debug) {                                            \
-        std::cerr << __dbgTracer.indent() << #obj /*<< " @" << __LINE__*/ << " " << /*std::endl <<*/ (obj) << \
-               std::endl;                                               \
-    }
-#define DEBUG_PRINTM(obj)                                               \
-    if (__dbgTracer.debug) {                                            \
-        std::cerr << __dbgTracer.indent() << #obj << /*" @" << __LINE__ <<*/ " " << (obj).size() << \
-               " CH: " << (obj).channels() << std::endl                 \
-               /* << (obj) << std::endl */;                             \
-    }
+#define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
+#define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)
+
 
 template <typename T>
 T clamp(const T& n, const T& lower, const T& upper)