Commit 274f205b82b5d4d8cf196390ca186deac2f3b24e
1 parent
db15a2f9
Fix poor error handling when logging nearest neighbors
Showing
1 changed file
with
16 additions
and
9 deletions
openbr/plugins/cluster.cpp
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | #include "openbr_internal.h" | 19 | #include "openbr_internal.h" |
| 20 | #include "openbr/core/common.h" | 20 | #include "openbr/core/common.h" |
| 21 | #include "openbr/core/opencvutils.h" | 21 | #include "openbr/core/opencvutils.h" |
| 22 | +#include <fstream> | ||
| 22 | 23 | ||
| 23 | using namespace cv; | 24 | using namespace cv; |
| 24 | 25 | ||
| @@ -225,6 +226,7 @@ class CollectNNTransform : public UntrainableMetaTransform | @@ -225,6 +226,7 @@ class CollectNNTransform : public UntrainableMetaTransform | ||
| 225 | void project(const Template &src, Template &dst) const | 226 | void project(const Template &src, Template &dst) const |
| 226 | { | 227 | { |
| 227 | dst.file = src.file; | 228 | dst.file = src.file; |
| 229 | + dst.clear(); | ||
| 228 | dst.m() = cv::Mat(); | 230 | dst.m() = cv::Mat(); |
| 229 | Neighbors neighbors; | 231 | Neighbors neighbors; |
| 230 | for (int i=0; i < src.m().cols;i++) { | 232 | for (int i=0; i < src.m().cols;i++) { |
| @@ -249,36 +251,41 @@ class LogNNTransform : public TimeVaryingTransform | @@ -249,36 +251,41 @@ class LogNNTransform : public TimeVaryingTransform | ||
| 249 | Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) | 251 | Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) |
| 250 | BR_PROPERTY(QString, fileName, "") | 252 | BR_PROPERTY(QString, fileName, "") |
| 251 | 253 | ||
| 252 | - QFile out; | 254 | + std::fstream fout; |
| 255 | + | ||
| 253 | void projectUpdate(const Template &src, Template &dst) | 256 | void projectUpdate(const Template &src, Template &dst) |
| 254 | { | 257 | { |
| 255 | dst = src; | 258 | dst = src; |
| 256 | 259 | ||
| 260 | + if (!dst.file.contains("neighbors")) { | ||
| 261 | + fout << std::endl; | ||
| 262 | + return; | ||
| 263 | + } | ||
| 264 | + | ||
| 257 | Neighbors neighbors = dst.file.get<Neighbors>("neighbors"); | 265 | Neighbors neighbors = dst.file.get<Neighbors>("neighbors"); |
| 258 | - if (neighbors.isEmpty() ) | 266 | + if (neighbors.isEmpty() ) { |
| 267 | + fout << std::endl; | ||
| 259 | return; | 268 | return; |
| 269 | + } | ||
| 260 | 270 | ||
| 261 | QString aLine; | 271 | QString aLine; |
| 262 | aLine.append(QString::number(neighbors[0].first)+":"+QString::number(neighbors[0].second)); | 272 | aLine.append(QString::number(neighbors[0].first)+":"+QString::number(neighbors[0].second)); |
| 263 | for (int i=1; i < neighbors.size();i++) | 273 | for (int i=1; i < neighbors.size();i++) |
| 264 | aLine.append(","+QString::number(neighbors[i].first)+":"+QString::number(neighbors[i].second)); | 274 | aLine.append(","+QString::number(neighbors[i].first)+":"+QString::number(neighbors[i].second)); |
| 265 | 275 | ||
| 266 | - aLine += "\n"; | ||
| 267 | - out.write(qPrintable(aLine)); | 276 | + fout << qPrintable(aLine) << std::endl; |
| 268 | } | 277 | } |
| 269 | 278 | ||
| 270 | void init() | 279 | void init() |
| 271 | { | 280 | { |
| 272 | - if (!fileName.isEmpty()) { | ||
| 273 | - out.setFileName(fileName); | ||
| 274 | - out.open(QIODevice::WriteOnly); | ||
| 275 | - } | 281 | + if (!fileName.isEmpty()) |
| 282 | + fout.open(qPrintable(fileName), std::ios_base::out); | ||
| 276 | } | 283 | } |
| 277 | 284 | ||
| 278 | void finalize(TemplateList &output) | 285 | void finalize(TemplateList &output) |
| 279 | { | 286 | { |
| 280 | (void) output; | 287 | (void) output; |
| 281 | - out.close(); | 288 | + fout.close(); |
| 282 | } | 289 | } |
| 283 | 290 | ||
| 284 | public: | 291 | public: |