基于祥云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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值