一、实现人脸识别的平台 这边选用翔云ocr平台进行人脸识别 涉及到一个人脸识别调用API和六个字符串拼接 二、编码
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned int bool;
#define true 1
#define false 0
size_t ReadDatas( void *ptr, size_t size, size_t nmemb, void *stream)
{
char buf[1024] = {'\0'};
strncpy(buf,ptr,1024);
printf("%s\n",buf);
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *img1[12];
char *img2[12];
char *key = "Ame5iiSxY6yFwHjr4SPNuC";
char *secret = "08d4e1c219834e04affd3198c199e206";
int typeId = 21;
char *format = "xml";
postString = (char *)malloc(strlen(key)+strlen(secret)+2048);
sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s","","",key,secret,21,"xml");
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString);
curl_easy_setopt(curl, CURLOPT_URL, " https://netocr.com/api/faceliu.do ");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,ReadDatas);
res = curl_easy_perform(curl);
printf("%d\n",res);
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
然后gcc demo2.c -I ./curl-7.71.1/_install/include/ -L ./curl-7.71.1/_install/lib/ -lcurl -odemo2test ./demo2test 发现以下错误: 说明没有安装OpenSSL库 三、安装openssl库 (1)下载openssl-1.1.1a.tar.gz依赖库 wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz tar -vxf openssl-1.1.1a.tar.gz cd openssl-1.1.1a ./config//默认安装在/usr/local/下 make make install (2)重新编译libcurl库
./configure --prefix=$PWD/_install --with-ssl
make
make install
最后重新编译生成可执行文件
gcc demo1.c -I ./curl-7.71.1/_install/include/ -L ./curl-7.71.1/_install/lib/ -lcurl
./a.out
|