Skip to content

Commit

Permalink
add remove face data
Browse files Browse the repository at this point in the history
  • Loading branch information
skye-z committed Nov 25, 2023
1 parent 085e01d commit ba7c81e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ jobs:
with:
languages: ${{ matrix.language }}
- run: |
sudo apt install libavdevice-dev libavfilter-dev libavformat-dev && \
sudo apt install libavcodec-dev libswresample-dev libswscale-dev && \
sudo apt install libavutil-dev && \
sudo apt install libopenblas-dev liblapack-dev libjpeg8-dev libx11-dev && \
git clone -b 'v19.24.2' --single-branch https://github.com/davisking/dlib.git && \
cd dlib && \
mkdir build && \
Expand Down
6 changes: 6 additions & 0 deletions face_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class FaceData
return true;
}

// 删除人脸数据
bool remove(const std::string &uid){
std::string sql = "DELETE FROM face WHERE uid = '" + uid + "';";
return executeSQL(sql.c_str());
}

// 获取全部列表
std::vector<FaceObject> all_list()
{
Expand Down
33 changes: 33 additions & 0 deletions http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class HttpServer
// 设置HTTP路由
server.Post("/add", [&](const Request &req, Response &res)
{ handleAddFace(req, res); });
server.Post("/remove", [&](const Request &req, Response &res)
{ handleRemoveFace(req, res); });
server.Post("/match", [&](const Request &req, Response &res)
{ handleMatchFace(req, res); });
}
Expand Down Expand Up @@ -195,6 +197,37 @@ class HttpServer
}
}

// 删除人脸数据
void handleRemoveFace(const Request &req, Response &res){
json result_json;
try
{
// 检查是否提供uid
if (req.has_param("uid"))
{
std::string uid = req.get_param_value("uid");
result_json["state"] = data.remove(uid);
res.set_content(result_json.dump(), "application/json");
}
else
{
result_json["state"] = false;
result_json["result"] = "未提供uid";

res.status = 400;
res.set_content(result_json.dump(), "application/json");
}
}
catch (const std::exception &e)
{
result_json["state"] = false;
result_json["result"] = "服务出错";

res.status = 500;
res.set_content(result_json.dump(), "application/json");
}
}

// 匹配人脸
void handleMatchFace(const Request &req, Response &res)
{
Expand Down

0 comments on commit ba7c81e

Please sign in to comment.