基于翔云平台实现人脸识别功能

在这里插入图片描述
base64 Linux提供的图片的BCM转base64流的工具

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.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;

size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{
	char buf[1024] = {'\0'};
	strcpy(buf, ptr);
	if (strstr(ptr, "是")) {
		printf("yes\n");
	} else {
		printf("no\n");
	}
}

char* getImg(char *img)
{
	int fd;
	char *buf;
	char cmd[36] = {'\0'};
	
	sprintf(cmd, "base64 %s > imgFife", img);
	system(cmd);
	fd = open("imgFife", O_RDONLY);
	int fileLen = lseek(fd, 0, SEEK_END);
	lseek(fd, 0, SEEK_SET);
	buf = (char*)malloc(fileLen + 5);
	read(fd, buf, fileLen + 5);

	return buf;
}

bool postUrl()
{
	CURL *curl;
	CURLcode res;
	char *postString;

	char *key = " "; //自行补充
	char *secret = " "; //自行补充
	int typeId = 21;
	char *format = "xml";
	
	system("raspistill -t 200 -tl 3000 -o img2.jpg"); //拍照
	char *img1 = getImg("img1.jpg");
	char *img2 = getImg("img2.jpg");
	system("rm img2.jpg");
	
	postString = (char*)malloc(sizeof(typeId) + strlen(key) + strlen(secret) 
			+ strlen(format) + strlen(img1) + strlen(img2));
	memset(postString, '\0', strlen(postString));
	sprintf(postString, "&img1=%s&img&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_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);
		curl_easy_cleanup(curl);
	}

	return true;
}

int main(void)
{
	postUrl();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值