Skip to content

Commit 96a7fdf

Browse files
committed
face: fix I/O for 'splitr' structure on 32-bit platforms
1 parent 386f52c commit 96a7fdf

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

modules/face/src/face_alignmentimpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class FacemarkKazemiImpl : public FacemarkKazemi{
103103
// This function randomly generates test splits to get the best split.
104104
splitr getTestSplits(std::vector<Point2f> pixel_coordinates,int seed);
105105
// This function writes a split node to the XML file storing the trained model
106-
void writeSplit(std::ofstream& os,const splitr split);
106+
void writeSplit(std::ofstream& os, const splitr& split);
107107
// This function writes a leaf node to the binary file storing the trained model
108108
void writeLeaf(std::ofstream& os, const std::vector<Point2f> &leaf);
109109
// This function writes a tree to the binary file containing the model

modules/face/src/getlandmarks.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ bool FacemarkKazemiImpl :: findNearestLandmarks( vector< vector<int> >& nearest)
2626
}
2727
void FacemarkKazemiImpl :: readSplit(ifstream& is, splitr &vec)
2828
{
29-
is.read((char*)&vec, sizeof(splitr));
29+
is.read((char*)&vec.index1, sizeof(vec.index1));
30+
is.read((char*)&vec.index2, sizeof(vec.index2));
31+
is.read((char*)&vec.thresh, sizeof(vec.thresh));
32+
uint32_t dummy_ = 0;
33+
is.read((char*)&dummy_, sizeof(dummy_)); // buggy writer structure alignment
34+
CV_CheckEQ((int)(sizeof(vec.index1) + sizeof(vec.index2) + sizeof(vec.thresh) + sizeof(dummy_)), 24, "Invalid build configuration");
3035
}
3136
void FacemarkKazemiImpl :: readLeaf(ifstream& is, vector<Point2f> &leaf)
3237
{

modules/face/src/trainFacemark.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,15 @@ void FacemarkKazemiImpl :: writeLeaf(ofstream& os, const vector<Point2f> &leaf)
219219
os.write((char*)&size, sizeof(size));
220220
os.write((char*)&leaf[0], leaf.size() * sizeof(Point2f));
221221
}
222-
void FacemarkKazemiImpl :: writeSplit(ofstream& os, splitr split)
222+
void FacemarkKazemiImpl :: writeSplit(ofstream& os, const splitr& vec)
223223
{
224-
os.write((char*)&split, sizeof(split));
224+
os.write((char*)&vec.index1, sizeof(vec.index1));
225+
os.write((char*)&vec.index2, sizeof(vec.index2));
226+
os.write((char*)&vec.thresh, sizeof(vec.thresh));
227+
uint32_t dummy_ = 0;
228+
os.write((char*)&dummy_, sizeof(dummy_)); // buggy original writer structure alignment
229+
CV_CheckEQ((int)(sizeof(vec.index1) + sizeof(vec.index2) + sizeof(vec.thresh) + sizeof(dummy_)), 24, "Invalid build configuration");
230+
225231
}
226232
void FacemarkKazemiImpl :: writeTree(ofstream &f,regtree tree)
227233
{

0 commit comments

Comments
 (0)