基于祥云ocr人脸识别开发
支持https版本编译方法
配置 ./configure --prefix=$PWD/-install_ --with-ssl 若编译错误可能是缺库
下载 OpenSSL库 wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
解压 tar -vxf openssl-1.1.1a.tar.gz
安装OpenSSL: 配置./config 编译make 安装sudo make install
重新配置安装curl库
翔云OCR平台
人脸识别API
key和secret
在个人中心
编码打通翔云后台
#include <unistd.h>
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
typedef unsigned int bool;
#define true 1
#define false 0
char buf[1024] = {'\0'};
size_t readDate( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(buf, ptr,1024);
// printf("===========================get Date==============================\n");
// printf("%s\n",buf);
}
char *getpicBase64FromFile(char *filePath)
{
char *bufpic;
char cmd[128] = {'\0'};
sprintf(cmd, "base64 %s >tmpFile",filePath); //baes64 获取baes64编码
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);
close(fd);
system("rm -f tmpFile");
return bufpic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
char *key = "asdasdafsadfasdf";
char *secret ="21546145615644165156";
int typeId = 21;
char *format = "xml";
char *postString;
char* buf1 = getpicBase64FromFile("./xinfei1.jpeg");
char* buf2 = getpicBase64FromFile("./xinfei2.jpg");
int len = strlen(key)+strlen(secret)+strlen(buf1)+strlen(buf2)+124;
postString = (char *)malloc(len);
memset(postString,0,len);
sprintf(postString, "&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",buf1,buf2,key,secret,21,format);// 拼接post内容
if (curl)
{
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); // 指定cookie文件
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容
curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do"); // 指定url
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, readDate);
res = curl_easy_perform(curl);
if(strstr(buf,"是") != NULL){
printf("the same person\n");
}else{
printf("the diff person\n");
}
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
直接输出
<?xml version="1.0" encoding="UTF-8"?>
<data>
<message>
<status>0</status>
<value>比对完成</value>
</message>
<cardsinfo>
<card type="21">
<item desc="判定值"><![CDATA[0.9075357]]></item>
<item desc="判定结果"><![CDATA[是]]></item>
</card>
</cardsinfo>
</data>
优化后
the same person