C++ SDK 人脸检测编译时头文件出现问题
Ta的回复 :上面发错了,这个才是编译时的代码: #include <iostream> #include <curl/curl.h> #include <json/json.h> #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<<result<<endl; // 如果有可选参数 std::map<std::string, std::string> options; options["max_face_num"] = "2"; options["face_fields"] = "age"; // 带参数调用人脸检测 result = client.detect(image, options); cout<<result<<endl; return 0; }