4 Star 8 Fork 2

樊智慧/faceHttpd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
face_serialize.h 2.34 KB
一键复制 编辑 原始数据 按行查看 历史
樊智慧 提交于 2019-07-19 11:17 +08:00 . 异步并行优化
/*************************************************************************
> File Name: face_serialize.h
> Author: fanzhihui
> Mail: 953106194@qq.com
> Created Time: 2019年06月26日 星期三 15时58分11秒
************************************************************************/
#ifndef _FHTTPD_FACE_SERIALIZE_H_
#define _FHTTPD_FACE_SERIALIZE_H_
#include<iostream>
#include <fstream>
#include <string>
#include <vector>
#include <exception>
#include <sstream>
#include "json/json.h"
#include "face_info.h"
using namespace std;
#define SERIAL_ADD_FACE 1
#define SERIAL_DELETE_FACE 2
typedef struct face_serial_info_
{
kown_face_info_t face;
int op_flag;
void UnSerialize(const string& line)
{
//std::cout << "UnSerialize"<< std::endl;
Json::Reader reader;
Json::Value json_object;
reader.parse(line.c_str(), json_object);
op_flag = json_object["op_flag"].asInt();
face.face_id = json_object["face_id"].asString();
face.face_key = json_object["face_key"].asString();
for( uint32_t i = 0; i < 512; i++){
string key = "fe"+to_string(i);
face.features.push_back(json_object[key].asDouble());
}
}
string Serialize() const
{
Json::Value valueinfo;
valueinfo["op_flag"] = op_flag;
valueinfo["face_id"] = face.face_id;
valueinfo["face_key"] = face.face_key;
for(uint32_t i =0; i < face.features.size(); ++i) {
string key = "fe" + to_string(i);
valueinfo[key] = face.features[i];
}
Json::FastWriter writerinfo;
return writerinfo.write(valueinfo);
}
}face_serial_info_t;
class FaceSerializeIf
{
public:
FaceSerializeIf(){
}
virtual ~FaceSerializeIf()
{
}
virtual void Serialize(const face_serial_info_t & face) = 0;
virtual void UnSerialize(vector<face_serial_info_t>& faces) = 0;
virtual void Clear() = 0;
};
class FaceSerializeException : public std::exception
{
public:
FaceSerializeException(const std::string& message):
msg(message)
{
}
const char* what() const noexcept override {
return msg.c_str();
}
private:
std::string msg;
};
class FileFaceSerialize : public FaceSerializeIf
{
public:
FileFaceSerialize(const string& file);
~FileFaceSerialize();
virtual void Serialize(const face_serial_info_t& face);
virtual void UnSerialize(vector<face_serial_info_t>& faces);
virtual void Clear();
private:
string filename;
ifstream fIn;
ofstream fOut;
};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wisefan/faceHttpd.git
git@gitee.com:wisefan/faceHttpd.git
wisefan
faceHttpd
faceHttpd
20190718

搜索帮助