通過識别照片判斷是否為同一人
- 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();
}
結果如下