Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load a stat model from memory without creating a temporary file #534

Merged
merged 1 commit into from
May 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions openbr/core/opencvutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,14 @@ void OpenCVUtils::storeModel(const cv::Algorithm &model, QDataStream &stream)

void OpenCVUtils::loadModel(CvStatModel &model, QDataStream &stream)
{
// Copy local file contents from stream
// Copy file contents from stream
QByteArray data;
stream >> data;

// Create local file
QTemporaryFile tempFile(QDir::tempPath()+"/model");
tempFile.open();
tempFile.write(data);
tempFile.close();

// Load MLP from local file
model.load(qPrintable(tempFile.fileName()));
// This code for reading a file from memory inspired by CvStatModel::load implementation
CvFileStorage *fs = cvOpenFileStorage(data.data(), 0, CV_STORAGE_READ | CV_STORAGE_MEMORY);
model.read(fs, (CvFileNode*) cvGetSeqElem(cvGetRootFileNode(fs)->data.seq, 0));
cvReleaseFileStorage(&fs);
}

void OpenCVUtils::loadModel(cv::Algorithm &model, QDataStream &stream)
Expand Down