From 96a7fdf35f3602719d8ea7826e5c8b8ed9222e79 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 6 Sep 2018 15:56:52 +0300 Subject: [PATCH] face: fix I/O for 'splitr' structure on 32-bit platforms --- modules/face/src/face_alignmentimpl.hpp | 2 +- modules/face/src/getlandmarks.cpp | 7 ++++++- modules/face/src/trainFacemark.cpp | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/face/src/face_alignmentimpl.hpp b/modules/face/src/face_alignmentimpl.hpp index 4c50cc337..352e0f60b 100644 --- a/modules/face/src/face_alignmentimpl.hpp +++ b/modules/face/src/face_alignmentimpl.hpp @@ -103,7 +103,7 @@ protected: // This function randomly generates test splits to get the best split. splitr getTestSplits(std::vector pixel_coordinates,int seed); // This function writes a split node to the XML file storing the trained model - void writeSplit(std::ofstream& os,const splitr split); + void writeSplit(std::ofstream& os, const splitr& split); // This function writes a leaf node to the binary file storing the trained model void writeLeaf(std::ofstream& os, const std::vector &leaf); // This function writes a tree to the binary file containing the model diff --git a/modules/face/src/getlandmarks.cpp b/modules/face/src/getlandmarks.cpp index a7da5271f..bb92082ef 100644 --- a/modules/face/src/getlandmarks.cpp +++ b/modules/face/src/getlandmarks.cpp @@ -26,7 +26,12 @@ bool FacemarkKazemiImpl :: findNearestLandmarks( vector< vector >& nearest) } void FacemarkKazemiImpl :: readSplit(ifstream& is, splitr &vec) { - is.read((char*)&vec, sizeof(splitr)); + is.read((char*)&vec.index1, sizeof(vec.index1)); + is.read((char*)&vec.index2, sizeof(vec.index2)); + is.read((char*)&vec.thresh, sizeof(vec.thresh)); + uint32_t dummy_ = 0; + is.read((char*)&dummy_, sizeof(dummy_)); // buggy writer structure alignment + CV_CheckEQ((int)(sizeof(vec.index1) + sizeof(vec.index2) + sizeof(vec.thresh) + sizeof(dummy_)), 24, "Invalid build configuration"); } void FacemarkKazemiImpl :: readLeaf(ifstream& is, vector &leaf) { diff --git a/modules/face/src/trainFacemark.cpp b/modules/face/src/trainFacemark.cpp index 3e9ecf57d..3bef45c6e 100644 --- a/modules/face/src/trainFacemark.cpp +++ b/modules/face/src/trainFacemark.cpp @@ -219,9 +219,15 @@ void FacemarkKazemiImpl :: writeLeaf(ofstream& os, const vector &leaf) os.write((char*)&size, sizeof(size)); os.write((char*)&leaf[0], leaf.size() * sizeof(Point2f)); } -void FacemarkKazemiImpl :: writeSplit(ofstream& os, splitr split) +void FacemarkKazemiImpl :: writeSplit(ofstream& os, const splitr& vec) { - os.write((char*)&split, sizeof(split)); + os.write((char*)&vec.index1, sizeof(vec.index1)); + os.write((char*)&vec.index2, sizeof(vec.index2)); + os.write((char*)&vec.thresh, sizeof(vec.thresh)); + uint32_t dummy_ = 0; + os.write((char*)&dummy_, sizeof(dummy_)); // buggy original writer structure alignment + CV_CheckEQ((int)(sizeof(vec.index1) + sizeof(vec.index2) + sizeof(vec.thresh) + sizeof(dummy_)), 24, "Invalid build configuration"); + } void FacemarkKazemiImpl :: writeTree(ofstream &f,regtree tree) {