Commit 1e738bfcf6de401af52ac8153824ddab43c51c23

Authored by bklare
1 parent 68a02b5a

Added functions to serialize opencv Algorithm class

openbr/core/opencvutils.cpp
... ... @@ -280,6 +280,24 @@ void OpenCVUtils::storeModel(const CvStatModel &model, QDataStream &stream)
280 280 stream << data;
281 281 }
282 282  
  283 +void OpenCVUtils::storeModel(const cv::Algorithm &model, QDataStream &stream)
  284 +{
  285 + // Create local file
  286 + QTemporaryFile tempFile;
  287 + tempFile.open();
  288 + tempFile.close();
  289 +
  290 + // Save MLP to local file
  291 + cv::FileStorage fs(tempFile.fileName().toStdString(), cv::FileStorage::WRITE);
  292 + model.write(fs);
  293 +
  294 + // Copy local file contents to stream
  295 + tempFile.open();
  296 + QByteArray data = tempFile.readAll();
  297 + tempFile.close();
  298 + stream << data;
  299 +}
  300 +
283 301 void OpenCVUtils::loadModel(CvStatModel &model, QDataStream &stream)
284 302 {
285 303 // Copy local file contents from stream
... ... @@ -296,6 +314,23 @@ void OpenCVUtils::loadModel(CvStatModel &amp;model, QDataStream &amp;stream)
296 314 model.load(qPrintable(tempFile.fileName()));
297 315 }
298 316  
  317 +void OpenCVUtils::loadModel(cv::Algorithm &model, QDataStream &stream)
  318 +{
  319 + // Copy local file contents from stream
  320 + QByteArray data;
  321 + stream >> data;
  322 +
  323 + // Create local file
  324 + QTemporaryFile tempFile(QDir::tempPath()+"/model");
  325 + tempFile.open();
  326 + tempFile.write(data);
  327 + tempFile.close();
  328 +
  329 + // Load MLP from local file
  330 + cv::FileStorage fs(tempFile.fileName().toStdString(), cv::FileStorage::READ);
  331 + model.read(fs["em"]);
  332 +}
  333 +
299 334 Point2f OpenCVUtils::toPoint(const QPointF &qPoint)
300 335 {
301 336 return Point2f(qPoint.x(), qPoint.y());
... ...
openbr/core/opencvutils.h
... ... @@ -52,7 +52,9 @@ namespace OpenCVUtils
52 52  
53 53 // Model storage
54 54 void storeModel(const CvStatModel &model, QDataStream &stream);
  55 + void storeModel(const cv::Algorithm &model, QDataStream &stream);
55 56 void loadModel(CvStatModel &model, QDataStream &stream);
  57 + void loadModel(cv::Algorithm &model, QDataStream &stream);
56 58  
57 59 template <typename T>
58 60 T getElement(const cv::Mat &m, int r, int c)
... ...