智能家居项目(八)之树莓派+摄像头进行人脸识别

本文介绍了将智能家居项目中的人脸识别功能移植到树莓派上的过程。通过编辑Camera.c、contrlDevices.h和mainPro.c文件,然后进行编译和运行,虽然人脸识别未能成功,但程序运行正常。文章还分享了项目图片演示。
摘要由CSDN通过智能技术生成

目录

1、编辑Camera.c

2、编辑contrlDevices.h

3、编辑mainPro.c

4、进行编译:

5、运行结果: ./test1

6、项目图片演示


智能家居项目(七)之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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值