目录
智能家居项目(七)之Libcurl库与HTTPS协议实现人脸识别_Love小羽的博客-CSDN博客
经过上一篇文章,写的代码是在Ubuntu系统中写的,这回把代码搬到树莓派上进行测试
直接上代码
1、编辑Camera.c
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "contrlDevices.h"
#define true 1
#define false 0typedef
typedef unsigned int bool;
char buf[10240] = {'\0'};//全局变量,用来接收从OCR后台返回的数据
char* getFace1();
void postUrl();
char* getPicBase64FromFile(char *filePath);
struct Devices *addCameraContrlToDeviceLink(struct Devices *phead);
size_t readData(void *ptr,size_t size,size_t nmemb,void *stream) //回调函数
{
strncpy(buf,ptr,1024);
}
char *getFace1()
{
printf("Taking pictures...\n");
system("raspistill -q 5 -t 1 -o image.jpg"); //-q 是图片质量,在0~100之间,我们调成5,压缩图片质量,生成的照片名字为imag.jpg //-t 是拍照延时,设定1s后拍照 while (access("./image.jpg", F_OK) != 0) ; //判断是否拍照完毕 printf("拍照完成\n"); char *base64BufFaceRec = getPicFromOCRBase641("./image.jpg"); // system("rm image.jpg"); return base64BufFaceRec; //返回刚才拍照的base64}
while (access("./image.jpg", F_OK) != 0); //判断是否拍照完毕
printf("Photo taking completed\n");
char *base64BufFaceRec = getPicBase64FromFile("./image.jpg");
return base64BufFaceRec; //返回刚才拍照的base64
}
char* getPicBase64FromFile(char *filePath) //获取图片的base64流
{
char *bufPic;
char cmd[128] = {'\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);
bufPic =(char *)malloc(filelen+2);
memset(bufPic,0,filelen+2);
read(fd,bufPic,filelen);
close(fd);
system("rm -f tmpFile");
return bufPic;
}
void postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char* key = "自行购买翔云平台购买人脸识别后的key";//翔云平台购买人脸识别后的key
char* secret = "自行购买翔云平台购买人脸识别后的secret";//翔云平台购买人脸识别后的secret
int t
文章评论