面部识别靠自己是很做成的,故我们借助一些工具,我们利用翔云智能平台,百度搜索翔云(因为翔云便宜一些。。。)
第一次1毛钱(便宜吧。。。)加入购物车,右侧购车内进行购买
完成后,再次选择上方选项栏的产品,选择人脸识别
可以先选择本地上传试一下
接下来进入正题
根据网页下方的API文档
在Linux系统下编写程序
记得先在文件夹下放两张图片,函数详细使用见
libcurl
#include
#include
#include
#include
#include
#include
#include
#include
#define true 1
#define false 0
typedef unsigned int bool;
char Buf[12000];
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(Buf,ptr,1024);
printf("============================get data============================");
printf("%s\n",Buf);
}
//将图片转换为base64格式
char *readBase64(char *filePath)
{
char *bufPic;
char cmd[128];
memset(cmd,'\0',128);
sprintf(cmd,"base64 %s > tmpFile",filePath);
system(cmd);
int fd = open("./tmpFile",O_RDWR);
int filelen = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
bufPic = (char *)malloc(filelen+2);
bufPic = memset(bufPic,'\0',filelen+2);
read(fd,bufPic,filelen);
system("rm -f tmpFile");
close(fd);
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *pointData;
char *key = "UbkpH8e8ydNsj6uhxxxxxxx";
char *secret = "1026b30b3cb7468e9d301afxxxxxxxx";
int typeId = 21;
char *format = "xml";
char *bufPic1;
char *bufPic2;
bufPic1 = readBase64("./a.jpg");
bufPic2 = readBase64("./b.jpg");
int len = strlen(key)+strlen(secret)+strlen(bufPic1)+strlen(bufPic2)+128;
pointData = (char *)malloc(len);
memset(pointData,'\0',len);
sprintf(pointData,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",bufPic1,bufPic2,key,secret,21,format);
//printf("%s\n",pointData);
// int fp =open("./test.txt",O_RDWR|O_CREAT,0666);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,pointData);
curl_easy_setopt(curl,CURLOPT_URL,"https://netocr.com/api/faceliu.do");
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,readData);
res = curl_easy_perform(curl);
printf("OK:%d\n",res);
if(strstr(Buf, "是") != NULL){
printf("the person same\n");
}
else{
printf("the person different\n");
}
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
运行结果:
如果发现无法实现,代码运行进入不了网址,可能是没有安装openssl库,请参考
安装openssl
车牌识别demo如下
#include
#include
#include
#include
#include
#include
#include
#include
#define true 1
#define false 0
typedef unsigned int bool;
char Buf[12000];
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(Buf,ptr,1024);
printf("============================get data============================\n");
printf("%s\n",Buf);
}
//将图片转换为base64格式
char *readBase64(char *filePath)
{
char *bufPic;
char cmd[128] = {'\0'};
sprintf(cmd,"base64 %s > tmpFile",filePath);
system(cmd);
int fd = open("./tmpFile",O_RDWR);
int filelen = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET);
bufPic = (char *)malloc(filelen+2);
memset(bufPic,'\0',filelen+2);
read(fd,bufPic,filelen);
system("rm -f tmpFile");
close(fd);
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *pointData;
char *key = "HzoZTfZVTnjm7txxxxxxx";
char *secret = "d00d423761f24fc49e5817xxxxxxxx";
int typeId = 19;
char *format = "xml";
char *bufPic1;
bufPic1 = readBase64("./car1.jpg");
int len = strlen(key)+strlen(secret)+strlen(bufPic1)+128;
pointData = (char *)malloc(len);
memset(pointData,'\0',len);
sprintf(pointData,"&img=%s&key=%s&secret=%s&typeId=%d&format=%s",bufPic1,key,secret,typeId,format);
//printf("%s\n",pointData);
// int fp =open("./test.txt",O_RDWR|O_CREAT,0666);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,pointData);
curl_easy_setopt(curl,CURLOPT_URL,"https://netocr.com/api/recogliu.do");
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,readData);
res = curl_easy_perform(curl);
printf("OK:%d\n",res);
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
结果如下