通过识别照片判断是否为同一人
- 1.借助工具
-
- 1.注册登录
- 2.选择人脸识别
- 3.1毛钱购买
- 2.代码测试
1.借助工具
面部识别靠自己是很做成的,故我们借助一些工具,我们利用翔云智能平台,百度搜索翔云(因为翔云便宜一些。。。)
1.注册登录
进入后,上方选项栏选择价格与购买
2.选择人脸识别
右侧选择人脸识别,以后若有其他需要亦可使用其他
3.1毛钱购买
第一次1毛钱(便宜吧。。。)加入购物车,右侧购车内进行购买
完成后,再次选择上方选项栏的产品,选择人脸识别
可以先选择本地上传试一下
2.代码测试
接下来进入正题
根据网页下方的API文档
在Linux系统下编写程序
记得先在文件夹下放两张图片,函数详细使用见
libcurl
#include <stdio.h>
#include <curl/curl.h>
#include<string.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#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 <stdio.h>
#include <curl/curl.h>
#include<string.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#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();
}
结果如下