注册网址:https://www.netocr.com/ 1.注册完翔云平台 2.购买0.01体验一下人脸识别(本文的车牌识别各种识别使用方法相同道理) 购买完成可在个人中心查看到
人脸识别 3.人脸识别api文档
以下操作要在同一个文件底下 我的是在~/httpHandler,将需要的两张图片也放到该文件路径下
demo3.c代码
#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[10240] = {'\0'};
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(buf,ptr,1024);
printf("========================get Data=====================");
printf("%s\n",buf);
}
char *getPicBase64FromFile(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);
close(fd);
system("rm -f tmpFile");
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *key = "************************";
char *secret = "****************************";
int typeId = 21;
char *format = "xml";
char *bufPic1 = getPicBase64FromFile("./reba1.jpg");
char *bufPic2 = getPicBase64FromFile("./reba2.jpg");
int len = strlen(key)+strlen(secret)+strlen(bufPic1)+strlen(bufPic2)+124;
postString = (char *)malloc(len);
memset(postString,'\0',len);
sprintf(postString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",bufPic1,bufPic2,key,secret,21,format);
curl = curl_easy_init();
if (curl)
{
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,readData);
res = curl_easy_perform(curl);
printf("ok:%d\n",res);
if(strstr(buf,"是") != NULL){
printf("the same Person\n");
}else{
printf("diff Person\n");
}
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
4.修改demo3.c代码 4.1将post内容定义出来并且添加 4.2将url改成人脸识别的url(接口地址)
5.进行编译生成a.out文件
gcc demo2.c -I ./curl-7.71.1/_install/include/ -L ./curl-7.71.1/_install
如果a.out运行发现出现错误:./a.out: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
export LD_LIBRARY_PATH=./curl-7.71.1/_install/lib/
只要图片符合要求即可看到结果,不符合则降低图片的分辨率。
车牌识别 将chepai2.jpg放在~httpHandler底下操作步骤同上
车牌识别api文档
democar.c代码
#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[10240] = {'\0'};
size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
strncpy(buf,ptr,1024);
printf("========================get Data=====================");
printf("%s\n",buf);
}
char *getPicBase64FromFile(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);
close(fd);
system("rm -f tmpFile");
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *key = "***************************";
char *secret = "*********************";
int typeId = 19;
char *format = "xml";
char *bufPic1 = getPicBase64FromFile("./chepai2.jpg");
int len = strlen(key)+strlen(secret)+strlen(bufPic1)+124;
postString = (char *)malloc(len);
memset(postString,'\0',len);
sprintf(postString,"&img=%s&key=%s&secret=%s&typeId=%d&format=%s",bufPic1,key,secret,21,format);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString);
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);
if(strstr(buf,"是") != NULL){
}else{
}
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
|