本帖最后由 云天 于 2023-3-27 14:07 编辑
【项目背景】
2021年5月11日,第七次全国人口普查结果显示,中国60岁及以上人口占比超18%,人口老龄化程度进一步加深。 随着我国步入老龄化社会,老年人的脑血管意外,下肢骨折以及严重的心肺疾病,老年性痴呆等导致老人长时间卧床,甚至卧床至生命终结的情况逐渐增多。
这些卧床老人当中,部分说话口齿不清,手臂无力。当身旁无人时,无法向另一个房间的亲人或陪护人表达自己的需求。
【项目设计】
本项目使用行空板结合光传感器,通过人工智能识别模型及物联网,只需卧床的老人挥挥手,如一个手指、两个手指、三个手指等等,就可以发出不同的指令。接收装置发出灯光及语音提醒,同时手机app进行震动及文字、语音提醒。
【硬件设备】
识别装置:行空板——国产开源硬件,光传感器——行空板集成,供电——双节锂电池,结构简单占用空间小。
接收装置:掌控板—— 国产开源硬件,集成LED灯3颗,语音合成传感器。
【采集数据】
利用循环程序根据读取行空板的集成的光传感器数据,在屏幕上从左到右依次画线。有遮挡时画黑线,无遮挡时画白线。当屏幕画满后,通过pyautogui库截屏保存为图片。
-
- # -*- coding: UTF-8 -*-
-
- # MindPlus
- # Python
- from pinpong.extension.unihiker import *
- from pinpong.board import Board,Pin
- from unihiker import GUI
- from PIL import Image
- import pyautogui
- import time
- import math
-
- def numberMap(x, in_min, in_max, out_min, out_max):
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
-
- # 自定义函数
- def JiSuanYanSe():
- global YanSe
- YanSe = light.read()
- YanSe = (numberMap(YanSe, 0, 1850, 0, 255))
- if (YanSe > 200):
- YanSe = (str("#ffffff"))
- else:
- YanSe = hex((math.floor(YanSe)))
- YanSe = (str("#000000"))
- return YanSe
-
- u_gui=GUI()
- Board().begin()
-
- YunXingShiJian = time.time()
- YZuoBiao = 0
- DuiXiangMing = ""
- DuiXiangXuHao = 0
- i=0
- while True:
- if ((time.time() - YunXingShiJian) > 0.0125):
- YunXingShiJian = time.time()
- DuiXiangMing = (str("D") + str(DuiXiangXuHao))
- DuiXiangMing=u_gui.draw_line(x0=0,y0=YZuoBiao,x1=240,y1=YZuoBiao,width=1,color=JiSuanYanSe())
- DuiXiangXuHao = (DuiXiangXuHao + 1)
- YZuoBiao = (YZuoBiao + 1)
- if (YZuoBiao > 320):
- img = pyautogui.screenshot(region=[0,0,240,320])
- img.save("one"+str(i)+".png")
- i=i+1
- YZuoBiao = 0
- DuiXiangXuHao=0
- u_gui.clear()
-
-
复制代码
【模型训练】
将采集的图像分类上传到“AI训练平台”进行模型训练,并将模型下载,保存到行空板。
【推理识别】
采集实时光传感器信息绘制图形,加载模型识别指令,发送物联网。
-
- # -*- coding: UTF-8 -*-
-
- # MindPlus
- # Python
- from pinpong.extension.unihiker import *
- from dfrobot_speech_synthesis import *
- from pinpong.board import Board,Pin
- import tensorflow.keras
- from unihiker import GUI
- from PIL import Image
- import numpy as np
- import pyautogui
- import time
- import math
- import siot
-
-
- def numberMap(x, in_min, in_max, out_min, out_max):
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
-
- # 自定义函数
- def JiSuanYanSe():
- global YanSe
- YanSe = light.read()
- YanSe = (numberMap(YanSe, 0, 1850, 0, 255))
- if (YanSe > 200):
- YanSe = (str("#ffffff"))
- else:
- YanSe = hex((math.floor(YanSe)))
- YanSe = (str("#000000"))
- return YanSe
- def FaSongZhiLing(ZhiLing, XianShi):
- siot.publish(topic="help/control", data=ZhiLing)
- buzzer.play(buzzer.BA_DING,buzzer.Once)
- 显示.config(text=XianShi)
- gravity_sstts.speak(XianShi)
- time.sleep(2)
-
-
- siot.init(client_id="",server="192.168.31.8",port=1883,user="siot",password="dfrobot")
- u_gui=GUI()
- Board().begin()
- siot.connect()
- siot.loop()
- gravity_sstts = DFRobot_SpeechSynthesis_I2C()
- YunXingShiJian = time.time()
- YZuoBiao = 0
- DuiXiangMing = ""
- DuiXiangXuHao = 0
- model = tensorflow.keras.models.load_model('keras_model.h5')
- labels=['back','one','two','three','four','five']
- gravity_sstts.begin(gravity_sstts.V1)
- gravity_sstts.speak("初始化成功")
-
- while True:
- if ((time.time() - YunXingShiJian) > 0.0125):
- YunXingShiJian = time.time()
- DuiXiangMing = (str("D") + str(DuiXiangXuHao))
- DuiXiangMing=u_gui.draw_line(x0=0,y0=YZuoBiao,x1=240,y1=YZuoBiao,width=1,color=JiSuanYanSe())
- DuiXiangXuHao = (DuiXiangXuHao + 1)
- YZuoBiao = (YZuoBiao + 1)
- if (YZuoBiao > 320):
- img = pyautogui.screenshot(region=[0,0,240,320])
- u_gui.clear()
- 显示=u_gui.draw_text(text="正在识别",x=10,y=100,font_size=40, color="#0000FF")
- img=img.resize((224, 224), Image.ANTIALIAS)
- img = np.array(img,dtype=np.float32)
- img = np.expand_dims(img,axis=0)
- img = img/255
- prediction = model.predict(img)
- predicted_class = labels[np.argmax(prediction)]
- if (predicted_class == (str("one"))):
- FaSongZhiLing("1", "口渴了")
- elif (predicted_class == (str("two"))):
- FaSongZhiLing("2", "想解手")
- elif (predicted_class == (str("three"))):
- FaSongZhiLing("3", "想翻身")
- elif (predicted_class == (str("four"))):
- FaSongZhiLing("4", "想吃饭")
- elif (predicted_class == (str("five"))):
- FaSongZhiLing("5", "不舒服")
- YZuoBiao = 0
- DuiXiangXuHao = 0
- 显示.config(text="请下指令")
- time.sleep(2)
- 显示.remove()
-
复制代码
【显示提醒】
1、硬件提醒装置
2、手机app提醒程序
连接行空板物联网,接收指令,屏幕显示信息,并响铃震动。
【演示视频】
|