配合翔云平台完成人脸识别车牌识别

注册网址:https://www.netocr.com/
1.注册完翔云平台
2.购买0.01体验一下人脸识别(本文的车牌识别各种识别使用方法相同道理)
购买完成可在个人中心查看到
在这里插入图片描述

人脸识别
3.人脸识别api文档
配合翔云平台完成人脸识别车牌识别_第1张图片

以下操作要在同一个文件底下
我的是在~/httpHandler,将需要的两张图片也放到该文件路径下

demo3.c代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#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'};
//      system("base64 laopo1.jpg > tmpFile");          //使用base64解析图片并放在tmFile中

        sprintf(cmd,"base64 %s >tmpFile",filePath);
        system(cmd);

        int fd = open("./tmpFile",O_RDWR);              //可读可写的方式打开
        int filelen = lseek(fd,0,SEEK_END);             //用lseek计算长度
        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);    // 指定post内容
                curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do");   // 指定url
                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//lib/ -lcurl

如果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文档
配合翔云平台完成人脸识别车牌识别_第2张图片

democar.c代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#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'};
//      system("base64 laopo1.jpg > tmpFile");          //使用base64解析图片并放在tmFile中

        sprintf(cmd,"base64 %s >tmpFile",filePath);
        system(cmd);

        int fd = open("./tmpFile",O_RDWR);              //可读可写的方式打开
        int filelen = lseek(fd,0,SEEK_END);             //用lseek计算长度
        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,19,format);

        curl = curl_easy_init();                                        //初始化
        if (curl)
        {
     
                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString);    // 指定post内容
                curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/recogliu.do");   // 指定url
                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();
}

你可能感兴趣的:(人脸识别,https,linux)