C++ SDK 人脸检测编译时头文件出现问题
阿门111阿 发布于2018-02 浏览:2988 回复:5
0
收藏
运行环境是虚拟机unbuntu 16.0.4,用的是C++ SDK,在编译时遇到如下问题,本人新手,望大牛帮忙具体一点解答:
收藏
点赞
0
个赞
共5条回复 最后由独孤焰坤回复于2018-02
#6独孤焰坤回复于2018-02

错误 C4996 'Json::FastWriter': Use StreamWriterBuilder instead BaiduFaceAI f:\project\crdemo\baidufaceai\baidufaceai\baidufaceai\baidufaceai\baidufaceai.cpp 182

解决方法:去掉 writer.h 里面的"JSONCPP_DEPRECATED("Use StreamWriterBuilder instead")"

0
#5独孤焰坤回复于2018-02

你的jsoncpp库里面要修改一个东西~

0
#4阿门111阿回复于2018-02

这些代码是人脸检测模块API的例程代码,而main函数中的代码则是人脸检测SDK的例程代码,我直接复制粘贴到一个.cpp文件中进行编译而已。

0
#3阿门111阿回复于2018-02

上面发错了,这个才是编译时的代码:

#include
#include
#include
#include "face.h"

const static std::string request_url = "https://aip.baidubce.com/rest/2.0/face/v1/detect";
static std::string detect_result;


/*curl发送http请求调用的回调函数,回调函数中对返回的json格式的body进行了解析,
解析结果储存在全局的静态变量当中*/
static size_t callback(void *ptr, size_t size, size_t nmemb, void *stream) {
// 获取到的body存放在ptr中,先将其转换为string格式
detect_result = std::string((char *) ptr, size * nmemb);
return size * nmemb;
}


/*人脸探测,成功返回0,发生错误返回其他错误码*/
int detect(std::string &json_result, const std::string &access_token) {
std::string url = request_url + "?access_token=" + access_token;
CURL *curl = NULL;
CURLcode result_code;
int is_success;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.data());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_httppost *post = NULL;
curl_httppost *last = NULL;
curl_formadd(&post, &last, CURLFORM_COPYNAME, "max_face_num", CURLFORM_COPYCONTENTS, "5", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "face_fields", CURLFORM_COPYCONTENTS, "age,beauty,expression,faceshape,gender,glasses,landmark,race,qualities", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "image", CURLFORM_COPYCONTENTS, "【base64_img】", CURLFORM_END);

curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
result_code = curl_easy_perform(curl);
if (result_code != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(result_code));
is_success = 1;
return is_success;
}
json_result = detect_result;
curl_easy_cleanup(curl);
is_success = 0;
} else {
fprintf(stderr, "curl_easy_init() failed.");
is_success = 1;
}

return is_success;
}

 


int main(void)
{
Json::Value result;

std::string image;
aip::get_file_content("/mnt/hgfs/linux_share/IMG_0413.jpg", &image);

// 设置APPID/AK/SK
std::string app_id = "10700922";
std::string api_key = "vpzGzESC69rZv1ay4KZ1yw4O";
std::string secret_key = "GpPgQlE8GMxIiFVvLxpNltIXvVfuwSPQ";

aip::Face client(app_id, api_key, secret_key);

// 调用人脸检测
result = client.detect(image, aip::null);
cout<

// 如果有可选参数
std::map options;
options["max_face_num"] = "2";
options["face_fields"] = "age";

// 带参数调用人脸检测
result = client.detect(image, options);
cout<

return 0;
}

0
#2阿门111阿回复于2018-02

这是编译的代码:

#include
#include
#include
#include "face.h"
using namespace std;

 

int main(void)
{
// 设置APPID/AK/SK
std::string app_id = "10700922";
std::string api_key = "vpzGzESC69rZv1ay4KZ1yw4O";
std::string secret_key = "GpPgQlE8GMxIiFVvLxpNltIXvVfuwSPQ";

aip::Face client(app_id, api_key, secret_key);

//人脸注册
Json::Value result;

std::string uid = "face_num5";

std::string user_info = "user's info";

std::string group_id = "group1";

std::string image;
aip::get_file_content("/mnt/hgfs/linux_share/IMG_0413.jpg", &image);

// 调用人脸注册
result = client.user_add(uid, user_info, group_id, image, aip::null);

// 如果有可选参数
std::map options;
options["action_type"] = "replace";

// 带参数调用人脸注册
result = client.user_add(uid, user_info, group_id, image, options);

cout<}

 

 

 

 

0
TOP
切换版块