本帖最后由 云天 于 2023-3-13 16:37 编辑
【项目背景】
截至2018年底,中国残疾人总数为8,890.7万人,其中手部残疾人数为1,890.7万人。手部残疾人在生活中有很多不方便,其中一些现代化设备上的按钮、及各种遥控器,都是为有手指的健康人设计,上面小按键,对于手部有残疾的人,尤其是无手掌的残疾人,更无法使用。
【项目设计】
本项目使用行空板,加上腕带,固定在手臂上,通过手臂的摆动,可在行空板上画出各种图形。使用行空板加载人工智能模型识别这些图形,向物联网发送指令,控制相应设备,启动、关闭、调节等,如遥控电视开关、调台、音量,空调、热水器、风扇、照明灯等。
【项目实现】
本项目,通过掌控板接收物联网指令,模拟控制风扇、台灯。
【采集数据】
通过行空板的内置的加速度传感器配合unihiker库中基于tkinter库封装的一个GUI类,在屏幕上画图,再利用“pyautogui”库截屏分类保存图片(back,up,down,left,right)。
Mind+图形化程序
python代码
-
- # -*- coding: UTF-8 -*-
-
- # MindPlus
- # Python
- from pinpong.extension.unihiker import *
- from pinpong.board import Board,Pin
- from unihiker import GUI
- import pyautogui
- import time
-
-
- u_gui=GUI()
- Board().begin()
- YunXingShiJian = time.time()
- x=u_gui.draw_text(text="行空板",x=0,y=0,font_size=20, color="#0000FF")
- yuan=u_gui.fill_circle(x=120,y=160,r=10,color="#0000FF")
- S0y = 0
- S0x = 0
- DuiXiangMing = "xian"
- XuHao = 0
- BiaoShi = 0
- i = 0
-
- while True:
- ShiJianCha = (time.time() - YunXingShiJian)
- if (ShiJianCha > 0.06):
- YunXingShiJian = time.time()
- Sty = (S0y + (accelerometer.get_x() * 10))
- Stx = (S0x + (accelerometer.get_y() * 10))
- yuan.config(y=(160 + Sty))
- yuan.config(x=(120 - Stx))
- if (((Stx > 10) or (Stx < -10)) or ((Sty > 10) or (Sty < -10))):
- if (BiaoShi == 0):
- QiDongShiJian = time.time()
- BiaoShi = 1
- if (BiaoShi == 1):
- DuiXiangMingZuHe = (str(DuiXiangMing) + str(XuHao))
- DuiXiangMingZuHe=u_gui.draw_line(x0=(120 - S0x),y0=(160 + S0y),x1=(120 - Stx),y1=(160 + Sty),width=5,color="#0000FF")
- XuHao = (XuHao + 1)
- if ((time.time() - QiDongShiJian) > 5):
- img = pyautogui.screenshot(region=[0,0,240,320]) # x,y,w,h
- img.save('back'+str(i)+'.png')
- i = (i + 1)
- BiaoShi = 0
- u_gui.clear()
- yuan=u_gui.fill_circle(x=120,y=160,r=10,color="#0000FF")
- Stx = 0
- Sty = 0
- time.sleep(3)
- S0y = Sty
- S0x = Stx
-
复制代码
图形可扩展到数字、多边形、各种简易图案等
【训练模型】
将图片数据集,上传到”英艻AI训练平台“进行模型训练,下载模型到行空板。
【识别指令】
采集实时控制图形,加载模型识别指令,发送物联网。
-
- # -*- coding: UTF-8 -*-
-
- # MindPlus
- # Python
- from pinpong.extension.unihiker 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 siot
-
-
- u_gui=GUI()
- siot.init(client_id="",server="192.168.31.9",port=1883,user="siot",password="dfrobot")
- Board().begin()
- siot.connect()
- siot.loop()
- YunXingShiJian = time.time()
- yuan=u_gui.fill_circle(x=120,y=160,r=10,color="#0000FF")
- S0y = 0
- S0x = 0
- DuiXiangMing = "xian"
- XuHao = 0
- BiaoShi = 0
- i = 0
- model = tensorflow.keras.models.load_model('keras_model.h5')
- labels=['back','up','down','left','right']
-
- while True:
- ShiJianCha = (time.time() - YunXingShiJian)
- if (ShiJianCha > 0.06):
- YunXingShiJian = time.time()
- Sty = (S0y + (accelerometer.get_x() * 10))
- Stx = (S0x + (accelerometer.get_y() * 10))
- yuan.config(y=(160 + Sty))
- yuan.config(x=(120 - Stx))
- if (((Stx > 10) or (Stx < -10)) or ((Sty > 10) or (Sty < -10))):
- if (BiaoShi == 0):
- QiDongShiJian = time.time()
- BiaoShi = 1
- if (BiaoShi == 1):
- DuiXiangMingZuHe = (str(DuiXiangMing) + str(XuHao))
- DuiXiangMingZuHe=u_gui.draw_line(x0=(120 - S0x),y0=(160 + S0y),x1=(120 - Stx),y1=(160 + Sty),width=5,color="#0000FF")
- XuHao = (XuHao + 1)
- if ((time.time() - QiDongShiJian) > 5):
- img = pyautogui.screenshot(region=[0,0,240,320]) # x,y,w,h
- 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)]
- i = (i + 1)
- BiaoShi = 0
- u_gui.clear()
- yuan=u_gui.fill_circle(x=120,y=160,r=10,color="#0000FF")
- Stx = 0
- Sty = 0
- 识别结果=u_gui.draw_text(text=predicted_class,x=0,y=100,font_size=40, color="#0000FF")
- if (predicted_class == "up"):
- siot.publish(topic="ai/hand", data="1")
- if (predicted_class == "down"):
- siot.publish(topic="ai/hand", data="2")
- if (predicted_class == "left"):
- siot.publish(topic="ai/hand", data="3")
- if (predicted_class == "right"):
- siot.publish(topic="ai/hand", data="4")
- time.sleep(3)
- 识别结果.remove()
- S0y = Sty
- S0x = Stx
-
-
复制代码
【模拟控制】
使用掌控板连接物联网接收指令,通过电磁继 电器控制台灯,通过L289N驱动板控制风扇。模拟控制家用电器。
【演示视频】
|