基于全志H616的智能家居

news/2025/2/6 9:45:22 标签: 智能家居

1.接线

2.配置语音模块

3.接上串口烧入安装包并且用电脑串口测试

4.板子测试语音模块

5.接入阿里云人脸识别

        人脸识别示例代码的位置

导入并配置示例代码

        修改“default” face.py

# -*- coding: utf-8 -*-
# 引入依赖包
# pip install alibabacloud_facebody20191230

import os
import io
from urllib.request import urlopen
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import SearchFaceAdvanceRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
    # 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
    # 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
    # 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
    access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
    access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
    # 访问的域名
    endpoint='facebody.cn-shanghai.aliyuncs.com',
    # 访问的域名对应的region
    region_id='cn-shanghai'
)

search_face_request = SearchFaceAdvanceRequest()
#场景一:文件在本地
stream0 = open(r'/home/orangepi/facepicture/yyqx1.jpg', 'rb')
search_face_request.image_url_object = stream0

#场景二:使用任意可访问的url
#url = 'https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/SearchFace1.png'
#img = urlopen(url).read()
#search_face_request.image_url_object = io.BytesIO(img)
search_face_request.db_name = 'default'
search_face_request.limit = 5

runtime_option = RuntimeOptions()
try:
  # 初始化Client
  client = Client(config)
  response = client.search_face_advance(search_face_request, runtime_option)
  # 获取整体结果
  print(response.body)
except Exception as error:
  # 获取整体报错信息
  print(error)
  # 获取单个字段
  print(error.code)
  # tips: 可通过error.__dict__查看属性名称

#关闭流
#stream0.close()

图片比对路径

 修改文件名指令“mv”

获取score最大的值在数据库去开锁

 将代码封装成函数并且只输出score的最大值 只保留两位小数:

需要的数据 把dict数据问AI用python写出来 face.py

# -*- coding: utf-8 -*-
# 引入依赖包
# pip install alibabacloud_facebody20191230

import os
import io
from urllib.request import urlopen
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import SearchFaceAdvanceRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
    # 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
    # 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
    # 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
    access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
    access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
    # 访问的域名
    endpoint='facebody.cn-shanghai.aliyuncs.com',
    # 访问的域名对应的region
    region_id='cn-shanghai'
)
def alibaba_face():
  search_face_request = SearchFaceAdvanceRequest()
  #场景一:文件在本地
  stream0 = open(r'/home/orangepi/facepicture/yyqx1.jpg', 'rb')
  search_face_request.image_url_object = stream0

  #场景二:使用任意可访问的url
  #url = 'https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/SearchFace1.png'
  #img = urlopen(url).read()
  #search_face_request.image_url_object = io.BytesIO(img)
  search_face_request.db_name = 'default'
  search_face_request.limit = 5

  runtime_option = RuntimeOptions()
  try:
    # 初始化Client
    client = Client(config)
    response = client.search_face_advance(search_face_request, runtime_option)
    # 获取整体结果
    #print(response.body)
    match_list = response.body.to_map()['Data']['MatchList']
    scores = [item['Score'] for item in match_list[0]['FaceItems']]
    highest_score = max(scores)
    #print(highest_score)
    value = round(highest_score, 2)
    print(value)
  except Exception as error:
    # 获取整体报错信息
    print(error)
    # 获取单个字段
    print(error.code)
    # tips: 可通过error.__dict__查看属性名称

  #关闭流
  stream0.close()
if __name__ == "__main__":
  alibaba_face()

运行结果:

 实现c语言调用python代码 face.c

#include <Python.h>

void face_init(void)
{
    Py_Initialize();
    
    // 将当前路径添加到sys.path中
    PyObject *sys = PyImport_ImportModule("sys");
    PyObject *path = PyObject_GetAttrString(sys, "path");
    PyList_Append(path, PyUnicode_FromString("."));

}

void face_final(void)
{
	Py_Finalize();
}

double face_category(void)
{
    // 导入para模块
    PyObject *pModule = PyImport_ImportModule("face");
    if (!pModule)
    {
        PyErr_Print();
        printf("Error: failed to load face.py\n");
		goto FAILED_MODULE;
    }
    
    //获取say_funny函数对象
    PyObject *pFunc = PyObject_GetAttrString(pModule, "alibaba_face");
    if (!pFunc)
    {
        PyErr_Print();
        printf("Error: failed to load alibaba_face\n");
		goto FAILED_FUNC;
    }
    

    //调用say_funny函数并获取返回值
    PyObject *pValue = PyObject_CallObject(pFunc, NULL);
    if (!pValue)
    {
        PyErr_Print();
        printf("Error: function call failed\n");
		goto FAILED_FUNC;
    }
    
    //将返回值转换为C类型
    double result = 0.0;
    if (!PyArg_Parse(pValue, "d", &result))
    {
        PyErr_Print();
        printf("Error: parse failed\n");
		goto FAILED_RESULT;
    }

	printf("result = %0.2lf\n", result);
	


FAILED_RESULT:
	Py_DECREF(pValue);
FAILED_VALUE:
	Py_DECREF(pFunc);
FAILED_FUNC:
	Py_DECREF(pModule);
FAILED_MODULE:
	return result;
}

int main(int argc,char *argv[])
{
  double face_result = 0.0;
  face_init();
  face_result = face_category();
  face_final();

}

gcc -o face face.c -I /usr/include/python3.10 -L /usr/lib/python3.10/ -lpython3.10 -lwiringPi

./face

结果:


http://www.niftyadmin.cn/n/5842840.html

相关文章

Debian 安装 Nextcloud 使用 MariaDB 数据库 + Caddy + PHP-FPM

前言 之前通过 docker在ubuntu上安装Nextcloud&#xff0c;但是现在我使用PVE安装Debian虚拟机&#xff0c;不想通过docker安装了。下面开始折腾。 安装过程 步骤 1&#xff1a;更新系统并安装必要的软件 sudo apt update && sudo apt upgrade -y sudo apt install…

大一计算机的自学总结:数据结构设计相关题

前言 说实在的&#xff0c;感觉这种设计数据结构的题比链表题还要ex&#xff0c;尤其是当哈希表和链表一起上的时候&#xff01; 一、设计有setAll功能的哈希表 #include <bits/stdc.h> using namespace std;int cnt0,setAllTime0,setAllValue; map<int,pair<in…

AI工具如何辅助写文章(科研版)

文章总览:[YuanDaiMa2048博客文章总览](https://blog.csdn.net/2301_79288416/article/details/137397359?spm=1001.2014.3001.5501)https://blog.csdn.net/2301_79288416/article/details/137397359?spm=1001.2014.3001.5501 在科研领域,撰写论文是一个复杂且耗时的过程。…

63.网页请求与按钮禁用 C#例子 WPF例子

这是一个简单的从网页获得一些数据的代码&#xff0c;使用了按钮禁用功能防止连续点击。使用了Dispatcher.Invoke从UI线程更新。使用了throw丢出异常。 System.Windows.Application.Current.Dispatcher.Invoke(() >{TextBlock2.Text $"错误&#xff1a;{ex.Message}&q…

回溯算法简单理解

leecode每日一题 回溯算法是一种通过试错来解决问题的算法&#xff0c;当发现当前路径无法得到正确解时&#xff0c;会回溯到上一步尝试其他可能。它特别适合解决 组合问题、排列问题、子集问题、棋盘类问题 等。以下是详细解析和C实现&#xff1a; 一、回溯算法核心思想 “选…

rust安装笔记

安装笔记 安装加速cargo 国内源nightly版本安装其他目标将现有项目迁移到新版本升级 安装加速 export RUSTUP_UPDATE_ROOT"https://mirrors.ustc.edu.cn/rust-static/rustup" export RUSTUP_DIST_SERVERhttps://mirrors.tuna.tsinghua.edu.cn/rustup curl --proto h…

DeepSeek R1技术报告关键解析(8/10):DeepSeek-R1 的“aha 时刻”,AI 自主学习的新突破

1. 什么是 AI 的“aha 时刻”&#xff1f; 在强化学习过程中&#xff0c;AI 的推理能力并不是线性增长的&#xff0c;而是会经历一些关键的“顿悟”时刻&#xff0c;研究人员将其称为“aha 时刻”。 这是 AI 在训练过程中突然学会了一种新的推理方式&#xff0c;或者能够主动…

嵌入式八股文面试题(一)C语言部分

1. 变量/函数的声明和定义的区别&#xff1f; &#xff08;1&#xff09;变量 定义不仅告知编译器变量的类型和名字&#xff0c;还会分配内存空间。 int x 10; // 定义并初始化x int x; //同样是定义 声明只是告诉编译器变量的名字和类型&#xff0c;但并不为它分配内存空间…