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 | 19 | #include "openbr_internal.h" |
| 20 | 20 | #include "openbr/core/common.h" |
| 21 | 21 | #include "openbr/core/opencvutils.h" |
| 22 | +#include <fstream> | |
| 22 | 23 | |
| 23 | 24 | using namespace cv; |
| 24 | 25 | |
| ... | ... | @@ -225,6 +226,7 @@ class CollectNNTransform : public UntrainableMetaTransform |
| 225 | 226 | void project(const Template &src, Template &dst) const |
| 226 | 227 | { |
| 227 | 228 | dst.file = src.file; |
| 229 | + dst.clear(); | |
| 228 | 230 | dst.m() = cv::Mat(); |
| 229 | 231 | Neighbors neighbors; |
| 230 | 232 | for (int i=0; i < src.m().cols;i++) { |
| ... | ... | @@ -249,36 +251,41 @@ class LogNNTransform : public TimeVaryingTransform |
| 249 | 251 | Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) |
| 250 | 252 | BR_PROPERTY(QString, fileName, "") |
| 251 | 253 | |
| 252 | - QFile out; | |
| 254 | + std::fstream fout; | |
| 255 | + | |
| 253 | 256 | void projectUpdate(const Template &src, Template &dst) |
| 254 | 257 | { |
| 255 | 258 | dst = src; |
| 256 | 259 | |
| 260 | + if (!dst.file.contains("neighbors")) { | |
| 261 | + fout << std::endl; | |
| 262 | + return; | |
| 263 | + } | |
| 264 | + | |
| 257 | 265 | Neighbors neighbors = dst.file.get<Neighbors>("neighbors"); |
| 258 | - if (neighbors.isEmpty() ) | |
| 266 | + if (neighbors.isEmpty() ) { | |
| 267 | + fout << std::endl; | |
| 259 | 268 | return; |
| 269 | + } | |
| 260 | 270 | |
| 261 | 271 | QString aLine; |
| 262 | 272 | aLine.append(QString::number(neighbors[0].first)+":"+QString::number(neighbors[0].second)); |
| 263 | 273 | for (int i=1; i < neighbors.size();i++) |
| 264 | 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 | 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 | 285 | void finalize(TemplateList &output) |
| 279 | 286 | { |
| 280 | 287 | (void) output; |
| 281 | - out.close(); | |
| 288 | + fout.close(); | |
| 282 | 289 | } |
| 283 | 290 | |
| 284 | 291 | public: | ... | ... |