Commit cb9e7362f6eaf2302514c4680e64128a5454f0ee
1 parent
4b34805a
improved PrintTransform
Showing
3 changed files
with
33 additions
and
21 deletions
sdk/core/opencvutils.cpp
| ... | ... | @@ -169,6 +169,30 @@ float OpenCVUtils::elemToFloat(const Mat &m, int r, int c) |
| 169 | 169 | return 0; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | +QString OpenCVUtils::matrixToString(const Mat &m) | |
| 173 | +{ | |
| 174 | + QString result; | |
| 175 | + vector<Mat> mv; | |
| 176 | + split(m, mv); | |
| 177 | + if (m.rows > 1) result += "{ "; | |
| 178 | + for (int r=0; r<m.rows; r++) { | |
| 179 | + if ((m.rows > 1) && (r > 0)) result += " "; | |
| 180 | + if (m.cols > 1) result += "["; | |
| 181 | + for (int c=0; c<m.cols; c++) { | |
| 182 | + if (mv.size() > 1) result += "("; | |
| 183 | + for (unsigned int i=0; i<mv.size()-1; i++) | |
| 184 | + result += OpenCVUtils::elemToString(mv[i], r, c) + ", "; | |
| 185 | + result += OpenCVUtils::elemToString(mv[mv.size()-1], r, c); | |
| 186 | + if (mv.size() > 1) result += ")"; | |
| 187 | + if (c < m.cols - 1) result += ", "; | |
| 188 | + } | |
| 189 | + if (m.cols > 1) result += "]"; | |
| 190 | + if (r < m.rows-1) result += "\n"; | |
| 191 | + } | |
| 192 | + if (m.rows > 1) result += " }"; | |
| 193 | + return result; | |
| 194 | +} | |
| 195 | + | |
| 172 | 196 | QStringList OpenCVUtils::matrixToStringList(const Mat &m) |
| 173 | 197 | { |
| 174 | 198 | QStringList results; |
| ... | ... | @@ -285,25 +309,8 @@ QDataStream &operator>>(QDataStream &stream, Mat &m) |
| 285 | 309 | |
| 286 | 310 | QDebug operator<<(QDebug dbg, const Mat &m) |
| 287 | 311 | { |
| 288 | - vector<Mat> mv; | |
| 289 | - split(m, mv); | |
| 290 | - if (m.rows > 1) dbg.nospace() << "{ "; | |
| 291 | - for (int r=0; r<m.rows; r++) { | |
| 292 | - if ((m.rows > 1) && (r > 0)) dbg.nospace() << " "; | |
| 293 | - if (m.cols > 1) dbg.nospace() << "["; | |
| 294 | - for (int c=0; c<m.cols; c++) { | |
| 295 | - if (mv.size() > 1) dbg.nospace() << "("; | |
| 296 | - for (unsigned int i=0; i<mv.size()-1; i++) | |
| 297 | - dbg.nospace() << qPrintable(OpenCVUtils::elemToString(mv[i], r, c)) << ", "; | |
| 298 | - dbg.nospace() << qPrintable(OpenCVUtils::elemToString(mv[mv.size()-1], r, c)); | |
| 299 | - if (mv.size() > 1) dbg.nospace() << ")"; | |
| 300 | - if (c < m.cols - 1) dbg.nospace() << ", "; | |
| 301 | - } | |
| 302 | - if (m.cols > 1) dbg.nospace() << "]"; | |
| 303 | - if (r < m.rows-1) dbg.nospace() << "\n"; | |
| 304 | - } | |
| 305 | - if (m.rows > 1) dbg.nospace() << " }"; | |
| 306 | - return dbg; | |
| 312 | + dbg.nospace() << OpenCVUtils::matrixToString(m); | |
| 313 | + return dbg.space(); | |
| 307 | 314 | } |
| 308 | 315 | |
| 309 | 316 | QDebug operator<<(QDebug dbg, const Point &p) | ... | ... |
sdk/core/opencvutils.h
| ... | ... | @@ -41,6 +41,7 @@ namespace OpenCVUtils |
| 41 | 41 | // From image |
| 42 | 42 | QString elemToString(const cv::Mat &m, int r, int c); |
| 43 | 43 | float elemToFloat(const cv::Mat &m, int r, int c); |
| 44 | + QString matrixToString(const cv::Mat &m); | |
| 44 | 45 | QStringList matrixToStringList(const cv::Mat &m); |
| 45 | 46 | QList<float> matrixToVector(const cv::Mat &m); |
| 46 | 47 | ... | ... |
sdk/plugins/misc.cpp
| ... | ... | @@ -99,13 +99,17 @@ class PrintTransform : public UntrainableMetaTransform |
| 99 | 99 | { |
| 100 | 100 | Q_OBJECT |
| 101 | 101 | Q_PROPERTY(bool error READ get_error WRITE set_error RESET reset_error) |
| 102 | + Q_PROPERTY(bool data READ get_data WRITE set_data RESET reset_data) | |
| 102 | 103 | BR_PROPERTY(bool, error, false) |
| 104 | + BR_PROPERTY(bool, data, false) | |
| 103 | 105 | |
| 104 | 106 | void project(const Template &src, Template &dst) const |
| 105 | 107 | { |
| 106 | 108 | dst = src; |
| 107 | - if (error) qDebug("%s\n", qPrintable(src.file.flat())); | |
| 108 | - else printf("%s\n", qPrintable(src.file.flat())); | |
| 109 | + const QString nameString = src.file.flat(); | |
| 110 | + const QString dataString = data ? OpenCVUtils::matrixToString(src)+"\n" : QString(); | |
| 111 | + if (error) qDebug("%s\n%s", qPrintable(nameString), qPrintable(dataString)); | |
| 112 | + else printf("%s\n%s", qPrintable(nameString), qPrintable(dataString)); | |
| 109 | 113 | } |
| 110 | 114 | }; |
| 111 | 115 | ... | ... |