Commit 1fff86f3 authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

add more test before to commit/checkout compressed histogram data in Face...

add more test before to commit/checkout compressed histogram data in Face database, to prevent crashes, especially if data are corrupted from database.
CCBUGS: 335624
CCBUGS: 330342
CCBUGS: 329873
CCBUGS: 326742
CCBUGS: 326586
CCBUGS: 326585
CCBUGS: 324774
CCBUGS: 323888
CCBUGS: 320812
CCBUGS: 312440
CCBUGS: 309027
CCBUGS: 308645
CCBUGS: 301611
CCBUGS: 297558
CCBUGS: 285517
parent bc054572
......@@ -67,9 +67,9 @@ void TrainingDB::setSetting(const QString& keyword, const QString& value)
QString TrainingDB::setting(const QString& keyword) const
{
QList<QVariant> values;
d->db->execSql( QString("SELECT value FROM Settings "
"WHERE keyword=?;"),
keyword, &values );
d->db->execSql(QString("SELECT value FROM Settings "
"WHERE keyword=?;"),
keyword, &values);
if (values.isEmpty())
{
......@@ -183,24 +183,42 @@ void TrainingDB::updateLBPHFaceModel(LBPHFaceModel& model)
if (metadata.storageStatus == LBPHistogramMetadata::Created)
{
OpenCVMatData data = model.histogramData(i);
QByteArray compressed = qCompress(data.data);
QVariantList histogramValues;
QVariant insertedId;
histogramValues << model.databaseId
<< metadata.identity
<< metadata.context
<< data.type
<< data.rows
<< data.cols
<< compressed;
d->db->execSql("INSERT INTO OpenCVLBPHistograms (recognizerid, identity, context, type, rows, cols, data) "
"VALUES (?,?,?,?,?,?,?)",
histogramValues, 0, &insertedId);
model.setWrittenToDatabase(i, insertedId.toInt());
OpenCVMatData data = model.histogramData(i);
if (data.data.isEmpty())
{
kWarning() << "Histogram data to commit in database are empty for Identity " << metadata.identity;
}
else
{
QByteArray compressed = qCompress(data.data);
if (compressed.isEmpty())
{
kWarning() << "Cannot compress histogram data to commit in database for Identity " << metadata.identity;
}
else
{
QVariantList histogramValues;
QVariant insertedId;
histogramValues << model.databaseId
<< metadata.identity
<< metadata.context
<< data.type
<< data.rows
<< data.cols
<< compressed;
d->db->execSql("INSERT INTO OpenCVLBPHistograms (recognizerid, identity, context, type, rows, cols, data) "
"VALUES (?,?,?,?,?,?,?)",
histogramValues, 0, &insertedId);
model.setWrittenToDatabase(i, insertedId.toInt());
kDebug() << "Commit compressed histogram " << metadata.databaseId << " for identity " << metadata.identity << " with size " << compressed.size();
}
}
}
}
}
......@@ -246,7 +264,7 @@ LBPHFaceModel TrainingDB::lbphFaceModel() const
while (query.next())
{
LBPHistogramMetadata metadata;
OpenCVMatData data;
OpenCVMatData data;
metadata.databaseId = query.value(0).toInt();
metadata.identity = query.value(1).toInt();
......@@ -257,12 +275,28 @@ LBPHFaceModel TrainingDB::lbphFaceModel() const
data.type = query.value(3).toInt();
data.rows = query.value(4).toInt();
data.cols = query.value(5).toInt();
data.data = qUncompress(query.value(6).toByteArray());
kDebug() << "Adding histogram" << metadata.databaseId << "identity" << metadata.identity << "size" << data.data.size();
histograms << data;
histogramMetadata << metadata;
QByteArray cData = query.value(6).toByteArray();
if (!cData.isEmpty())
{
data.data = qUncompress(cData);
if (data.data.isEmpty())
{
kWarning() << "Cannot uncompress histogram data to checkout from database for Identity " << metadata.identity;
}
else
{
kDebug() << "Checkout compressed histogram " << metadata.databaseId << " for identity " << metadata.identity << " with size " << cData.size();
histograms << data;
histogramMetadata << metadata;
}
}
else
{
kWarning() << "Histogram data to checkout from database are empty for Identity " << metadata.identity;
}
}
model.setHistograms(histograms, histogramMetadata);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment