Commit 5e7bdfebf569b9d12fbc368e15861c5185d3be6c
1 parent
51d9a854
load a stat model from memory without creating a temporary file
Showing
1 changed file
with
5 additions
and
9 deletions
openbr/core/opencvutils.cpp
| @@ -302,18 +302,14 @@ void OpenCVUtils::storeModel(const cv::Algorithm &model, QDataStream &stream) | @@ -302,18 +302,14 @@ void OpenCVUtils::storeModel(const cv::Algorithm &model, QDataStream &stream) | ||
| 302 | 302 | ||
| 303 | void OpenCVUtils::loadModel(CvStatModel &model, QDataStream &stream) | 303 | void OpenCVUtils::loadModel(CvStatModel &model, QDataStream &stream) |
| 304 | { | 304 | { |
| 305 | - // Copy local file contents from stream | 305 | + // Copy file contents from stream |
| 306 | QByteArray data; | 306 | QByteArray data; |
| 307 | stream >> data; | 307 | stream >> data; |
| 308 | 308 | ||
| 309 | - // Create local file | ||
| 310 | - QTemporaryFile tempFile(QDir::tempPath()+"/model"); | ||
| 311 | - tempFile.open(); | ||
| 312 | - tempFile.write(data); | ||
| 313 | - tempFile.close(); | ||
| 314 | - | ||
| 315 | - // Load MLP from local file | ||
| 316 | - model.load(qPrintable(tempFile.fileName())); | 309 | + // This code for reading a file from memory inspired by CvStatModel::load implementation |
| 310 | + CvFileStorage *fs = cvOpenFileStorage(data.data(), 0, CV_STORAGE_READ | CV_STORAGE_MEMORY); | ||
| 311 | + model.read(fs, (CvFileNode*) cvGetSeqElem(cvGetRootFileNode(fs)->data.seq, 0)); | ||
| 312 | + cvReleaseFileStorage(&fs); | ||
| 317 | } | 313 | } |
| 318 | 314 | ||
| 319 | void OpenCVUtils::loadModel(cv::Algorithm &model, QDataStream &stream) | 315 | void OpenCVUtils::loadModel(cv::Algorithm &model, QDataStream &stream) |