基于翔云OCR云平台的人脸识别

本节通过翔云OCR云平台来实现人脸识别。调用人脸对比API,通过https post方式向云服务器提交两张需要对比的图片Base64流以及其他信息,云服务器处理后返回判断结果。

翔云OCR云平台:https://www.netocr.com/

libcurl库支持https版本的编译方法

上一节安装了libcurl库,有以下步骤:

1、./configure --prefix=$PWD/_install 配置安装路径为当前路径下_install文件夹
2、make 编译
3、make install 编译后的文件拷贝到指定文件夹,此时才会出现_install文件夹

我们会发现程序使用https协议不能连通,因为https=http+ssl,还需要安装并使用ssl相关库,可以查看下curl-7.71.1/docs/INSTALL.md,有以下说明:

The configure script always tries to find a working SSL library unless
explicitly told not to. If you have OpenSSL installed in the default search
path for your compiler/linker, you don’t need to do anything special. If you
have OpenSSL installed in /usr/local/ssl, you can run configure like:

./configure --with-ssl

If you have OpenSSL installed somewhere else (for example, /opt/OpenSSL) and
you have pkg-config installed, set the pkg-config path first, like this:

env PKG_CONFIG_PATH=/opt/OpenSSL/lib/pkgconfig ./configure --with-ssl

Without pkg-config installed, use this:

./configure --with-ssl=/opt/OpenSSL

我们需要安装下OpenSSL库,./configure --with-ssl默认从/usr/local/路径找OpenSSL库并调用。

1、先移除_install文件夹(之前libcurl安装的路径)
rm _install -rf

2、从网络上自动下载openssl-1.1.1a.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz

3、解压openssl-1.1.1a.tar.gz
tar -xvf opemssl-1.1.1a.tar.gz

4、浏览/openssl-1.1.1a/INSTALL文件,查看安装步骤说明:

If you want to just get on with it, do:

on Unix (again, this includes Mac OS/X):

$ ./config
$ make
$ make install
This will build and install OpenSSL in the default location, which is: Unix: normal installation directories under
/usr/local

5、Openssl库安装步骤:
(1)./config
(2)make
(3)sudo make install(安装在usr/local,需要root模式)

6、Openssl库安装完成后,进入curl-7.71.1文件夹,通过./configure配置
./configure --prefix=$PWD/_install --with-ssl
后面的步骤一样:
make 编译
make install 编译后的文件拷贝到指定文件夹,此时才会出现_install文件夹
libcurl库安装完成

翔云平台API


用户ocrKey和ocrSecret在个人中心页面可以看到。

注意的是,img1和img2是图片base64流,base64流简单来说就是将图片二进制数据通过Base64编码成字符串类型数据。

利用libcurl函数要设置的参数

1、url设置
curl_easy_setopt(curl, CURLOPT_URL, “https://netocr.com/api/faceliu.do”);
2、提交参数的设置
提交参数格式:&attr1=value1&attr2=value2…
sprintf(PostString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",img1,img2,key,secret,typeId,format);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,PostString);
3、返回的数据(xml格式)

<?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>  //对比率为0.9075357<item desc="判定结果"><![CDATA[是]]></item>    //判断为是同一个人</card></cardsinfo>
</data>

shell指令补充
将图片数据进行base64编码,得到图片base64流
base64 xxx (xxx为图片文件,可以为png、jpg等格式)

例程

#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>#define true 1
#define false 0
typedef unsigned int bool;char post_info[500];
size_t ReadHandler( void *ptr, size_t size, size_t nmemb, void *stream)
{int buf_size=size*nmemb;char *buf=malloc(buf_size+1);memset(buf,'\0',buf_size+1);strncpy(buf,ptr,buf_size);printf("%s\n",buf);strcat(post_info,buf);free(buf);return buf_size;
}
char* getBase64(char *img_name)
{int fd;    int size=0;char cmd[30];char *img_buf;sprintf(cmd,"base64 %s >tmpfile.txt",img_name);if(system(cmd)==256){return NULL;}fd=open("tmpfile.txt",O_RDWR);size=lseek(fd,0,SEEK_END);img_buf=malloc(size+2);memset(img_buf,'\0',size+2);lseek(fd,0,SEEK_SET);read(fd,img_buf,size);close(fd);system("rm tmpfile.txt");return img_buf;
}
bool postUrl(char* img1_name,char* img2_name)
{CURL *curl;CURLcode res;char *PostString;char *img1;char *img2;char *key="yourkey";char *secret="yoursecret";int  typeId=21;char *format="xml";img1=getBase64(img1_name);img2=getBase64(img2_name);if((img1==NULL)||(img2==NULL)){printf("img dont exist!\n");return false;}PostString=malloc(strlen(img1)+strlen(img2)+strlen(key)+strlen(secret)+sizeof(typeId)+strlen(format));sprintf(PostString,"&img1=%s&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",img1,img2,key,secret,typeId,format);curl = curl_easy_init();if (curl){curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do");curl_easy_setopt(curl, CURLOPT_POSTFIELDS,PostString);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ReadHandler);res = curl_easy_perform(curl);printf("OK:%d\n",res);curl_easy_cleanup(curl);if(strstr(post_info,"是")!=NULL){printf("same person\n");}else{printf("different person\n");}}return true;
}
int main(int argc,char* argv[])
{memset(post_info,'\0',500);if(argc!=3){return -1;}curl_global_init(CURL_GLOBAL_ALL);postUrl(argv[1],argv[2]);curl_global_cleanup();
}

代码运行

通过运行如下命令,来进行人脸对比,img1和img2代表两张要对比的图片。

./mycurl img1 img2

准备图片文件

从左到右文件名依次是reba1.png、reba2.png、xiang1.png。

运行结果

sh@ubuntu:~/Desktop/mycurl/test$ export LD_LIBRARY_PATH="/home/sh/Desktop/mycurl/curl-7.71.1/_install/lib"
sh@ubuntu:~/Desktop/mycurl/test$ gcc demo3.c -I /home/sh/Desktop/mycurl/curl-7.71.1/_install/include -lcurl -L /home/sh/Desktop/mycurl/curl-7.71.1/_install/lib -o mycurl
sh@ubuntu:~/Desktop/mycurl/test$ ./mycurl reba1.png reba2.png
<?xml version="1.0" encoding="UTF-8"?>
<data><message><status>0</status><value>比对完成</value></message><cardsinfo><card type="21"><item desc="判定值"><![CDATA[0.9565811]]></item><item desc="判定结果"><![CDATA[是]]></item></card></cardsinfo>
</data>OK:0
same person
sh@ubuntu:~/Desktop/mycurl/test$ ./mycurl reba1.png xiang1.png
<?xml version="1.0" encoding="UTF-8"?>
<data><message><status>0</status><value>比对完成</value></message><cardsinfo><card type="21"><item desc="判定值"><![CDATA[0.5085605]]></item><item desc="判定结果"><![CDATA[否]]></item></card></cardsinfo>
</data>OK:0different person

总结

本节仅仅是两张已准备好的图片进行对比,下节采用摄像头采集图片的方式进行人脸识别。

基于翔云OCR云平台的人脸识别(1)相关推荐

  1. 基于翔云OCR云平台的人脸识别(2)

    基于翔云OCR云平台的人脸识别(2) 项目思路 raspistill命令的相关参数说明 -v:调试信息查看 -w:图像宽度 -h:图像高度 -rot:图像旋转角度,只支持 0.90.180.270 度 ...

  2. C语言实现基于翔云平台的人脸识别demo1(linux)

    C语言实现基于翔云平台的人脸识别demo1(linux) 实现的目标 安装openssl第三方的库 安装libcurl第三方的库 购买使用翔云平台人脸识别的次数 libcurl的使用 **参考以下博文 ...

  3. C语言实现基于翔云平台的人脸识别demo2(树莓派)

    C语言实现基于翔云平台的人脸识别demo2(树莓派3B) 实现目标 树莓派安装mjpg-streamer 在树莓派下依次执行以下指令 修改start.sh文件(用来开启摄像头进行监控) A:树莓派摄像 ...

  4. 基于树莓派(C语音)实现人脸识别(翔云平台)

    1.树莓派中安装摄像头并测试摄像头 1.1.安装mjpg-streamer 在CRT中依次输入一下指令 sudo apt-get update #更新软件列表 sudo apt-get upgrade ...

  5. android 人脸识别 方法研究,基于Android平台的人脸识别技术研究

    摘要: 在计算机视觉与模式识别领域中,人脸检测与识别技术是一个非常热门的研究课题,同时也具备非常广阔的商业价值.在诸多的目标检测算法中,基于AdaBoost算法的目标检测方法具有检测速度快,检测效果好 ...

  6. 基于百度AI开放平台的人脸识别

    文章目录 前言 人脸识别流程图 一.注册账号 二.创建应用 三.下载SDK文件 四.创建工具类 五.创建用于人脸识别的网页 1.引入css文件 2.创建注册按钮 3.创建模态框,用于捕捉人脸 4.引入 ...

  7. GB28181/RTSP/Onvif/HikSDK/Ehome协议视频共享平台EasyCVR人脸识别系统助力打造智慧安检系统

    一.项目需求 随着经济及交通的发展,海关和陆路边境口岸之间每天都有大量的人和货物在此周转,随之而来的安检工作也越来越重要,检查藏匿的违禁品和危险品一直是相关安全部门的重要工作.一套人行.物检等全方位的 ...

  8. 基于深度学习的端到端人脸识别技术:全面调研

    44页,共计371篇参考文献.本文全面介绍了端到端深度学习人脸识别技术,包括人脸检测,人脸预处理和人脸表征等方向,详细介绍了最新的算法设计,评估指标,数据集,性能比较等. The Elements o ...

  9. 国标GB28181(EasyGBS)/RTSP/HIKSDK/EHOME协议视频智能分析平台EasyCVR人脸识别智能分析功能拓展

    计算机视觉技术作为人工智能(AI)技术发展的重要应用之一已经在我们的日常生活中屡见不鲜,AI人脸识别智能分析是基于人的脸部特征信息进行身份识别的一种生物识别技术,通常采用摄像机或摄像头采集含有人脸的图 ...

最新文章

  1. 对代理ARP技术的误读、无法完成代理ARP实验的故障分析
  2. vue适配移动端px自动转化为rem
  3. mysql5.7.25my.ini_mysql5.7 没有my.ini 的解决办法
  4. 使用Windows software center进行在线更新的后台进程SCClient.exe
  5. 1.3字符串 确定两串乱序同构
  6. linux卡在x windows,Linux下显卡配置错误 无法进入X Windows的解决
  7. ReflectionClass与Closure
  8. C语言 scanf()和gets()函数的区别
  9. 自定义异常 java
  10. ASP.NET抓取网页内容
  11. Redis底部的几种存储结构(sds、dict、ziplist、intset、skiplist)
  12. 图片上传的ajax代码,一个伪ajax图片上传代码的例子
  13. 从 Microsoft SQL Server 迁移到 Oracle
  14. poj1036-dp
  15. 华为hs8145v5刷机包_华为hs8145v5刷机包_华为P40 Pro(ELSAN00/TN00)官方11.0.0.155固件卡刷包强刷包救砖包...
  16. C语言中的各种百分号都代表什么意思
  17. solidworks创新作业无限魔方
  18. 写给女儿青春生日的信(转载)
  19. 2022春招——芯动科技FPGA岗技术面(一面心得)
  20. intellij idea字体大小设置一秒完成

热门文章

  1. OpenJudge_P8207 和为给定数
  2. AS中类微信界面设计
  3. 【Lintcode】1015. Find Eventual Safe States
  4. 可编程电源输出过冲怎么办?解决方案在这里
  5. Paint - 简介
  6. python的数组批量赋值_python – 为numpy数组赋值的花式索引
  7. 蓝牙等级、发射功率、射程范围
  8. SpringMVC整合SwaggerUI
  9. 抢抓东数西算落地:英特尔聚焦计算与能耗有效性,全面优化数据中心资源配置...
  10. 白种人—上帝的骄子? (朱自清散文选读)