人脸识别功能实现

​​​​​

目录

 如何将jpg图片格式转换为base64数据并且读入


 第一次编译并没有与翔云后台产生连接,问题出在OpenSSL,编译出来仅仅支持http但不支持https,而s的加密内容就是key和secret

解决方案:重装libcurl库,带ssl

./configure --prefix=$PWD_INSTALL --with-ssl
./configure --prefix=$PWD_INSTALL --host=arm-linux // 树莓派交叉编译

当你的本机没有ssl库时,会出现报错
configure: error: --with-ssl was given but OpenSSL could not be detected 

openssl version //查看版本
which openss    //查看路径

这时候需要安装OpenSSL库解决这个问题

wget http://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -vxf openssl-1.0.0d.tar.gz  //解压
cd openssl-1.1.1a/
./config 

 

 需要添加图片以字符串形式,图片的base64流

图片是以RGB组成的,而jpg是由bmp压缩过后形成的

 如何将jpg图片格式转换为base64数据并且读入

        system("base64 dong2.jpg > tmpFile2");   //系统操作base64
        int fd2 = open("./tmpFile2",O_RDWR);     // 打开文件读取
        int filelen2 = lseek(fd2,0,SEEK_END);    //读取有多少大小
        lseek(fd,0,SEEK_SET);                    //光标回到开头
        char *bufpic2 = (char *)malloc(filelen2+2);  //定义一个buf存放数据流
        memset(bufpic2,0,filelen2+2);            //清空
        read(fd,bufpic2,filelen2);               //读取内容到buf
        close(fd2);                              //关闭

        int len = strlen(key)+strlen(secret)+strlen(bufpic1)+strlen(bufpic2)+128;//定义一个len用来表示大小,很好用
        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,typeId,format);//拼接

 封装后

char *getPicBase64FromFile(char *filePath)
{
        char cmd[32]={'\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);

        char *bufpic = (char *)malloc(filelen+2);
        memset(bufpic,'\0',filelen+2);
        read(fd,bufpic,filelen);
        close(fd);

        return bufpic
}

char *bufpic1 = getPicBase64FromFile("dong1.jpg");
char *bufpic2 = getPicBase64FromFile("dong2.jpg");

 http初始化工作

 curl = curl_easy_init();
        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, readData); //函数将在libcurl接收到数据后被调用
                res = curl_easy_perform(curl);
                printf("ok %d\n",res);
                if(strstr(readBuf,"是")!= NULL){
                        printf("the same person\n");
                }else{
                        printf("different person\n");
                }
                curl_easy_cleanup(curl);
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值