智能家居 (6) ——人脸识别控制开关电磁锁

本文介绍了一个基于树莓派的智能门禁系统,该系统利用语音识别控制人脸识别过程,并通过电磁锁实现门禁开关。系统使用wiringPi库进行GPIO控制,并通过Libcurl库发送HTTP请求与远程OCR服务交互。

🔺1、前序文章:

【智能家居 (1) ——工厂模式继电器控制灯】

【智能家居 (2) ——工厂模式火焰报警器】

【智能家居 (3) ——语音识别控制端线程】

【智能家居 (4) ——网络控制端线程】

【智能家居 (5) ——前四章内容整合】

【基于 Libcurl 通过 https 访问翔云 OCR 实现人脸识别】

【树莓派安装mjpg-streamer使用摄像头】

🔺2、main.c 函数:

通过语音控制开启人脸识别,摄像头亮灯2秒拍照

此 main.c 函数仅用于 “人脸识别控制开关电磁锁” 功能调试

#include <stdio.h>
#include <string.h>
#include "equipment.h"
#include "command.h"
#include <pthread.h>
#include <unistd.h>

#include <curl/curl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

char buf[1024] = {
   
   '\0'};		//用于存放翔云返回的数据

struct Equipment *findEquipByName(char *name,struct Equipment *phead);		//一些函数声明
struct Command *findCommandByName(char *name,struct Command *phead);
void *voiceControlThread(void *data);
char *getPicBase64FromFile(char *filePath);
size_t readData(void *ptr, size_t size, size_t nmemb, void *stream);
unsigned int postUrl();

struct Equipment *equiphead = NULL;			//设备工厂链表头节点
struct Command *cmdhead = NULL;				//指令控制工厂链表节点头

int main()
{
   
   
	if(wiringPiSetup() == -1){
   
   					//使用wiringPi库需要初始化
		printf("wiringPiSetup failed!\n");
		return -1; 
	}

	equiphead = addEleLockToLink(equiphead);			//各设备加入设备工厂
	
	cmdhead = addVoiceControlToLink(cmdhead);		//各指令控制加入指令控制工厂

	struct Equipment *tmpequiphead = equiphead;
	while(tmpequiphead != NULL){
   
   						//设备工厂所有设备初始化
		tmpequiphead->Init(tmpequiphead->pinNum);
		tmpequiphead = tmpequiphead->next;
	}

	pthread_t voiceControl_thread;
	pthread_create(&voiceControl_thread,NULL,voiceControlThread,NULL);		//创建线程:语音控制
	
	pthread_join(voiceControl_thread, NULL);		//主函数等待线程退出

	return 0;
}

void *voiceControlThread(void *data)			//“语音控制线程”执行的函数
{
   
   
	int nread;
	char *temName = NULL;
	struct Command *voiceHandler = NULL;
	struct Equipment *linkHandler;


	voiceHandler = findCommandByName("voiceControl",cmdhead);		//寻找“语音控制”所在节点,返回给voiceHandler
	if(voiceHandler <
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~莘莘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值