【Arduino】试验带识别模块的吃鸡助手

news2024/9/20 14:31:19

在前面的试验中,我们试验了声音触发点击,方面多指操作的辅助功能,

【Arduino】自制声控点击器(吼叫吃鸡助手)-CSDN博客

如果声控模块换成图像识别模块,就是一个自动识别并shot的功能了,

通过这个试验,可以了解arduino串口通信的使用,蓝牙模块和arduino交互就是通过串口交互的方式。

看看arduino自带的串口例子

/*
  Serial Event example

  When new serial data arrives, this sketch adds it to a String.
  When a newline is received, the loop prints the string and clears it.

  A good test for this is to try it with a GPS receiver that sends out
  NMEA 0183 sentences.

  NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or
  other ATmega32U4 based boards.

  created 9 May 2011
  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent
*/

String inputString = "";      // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

这里我们使用一个yb k210来作为识别设备,将其tx,rx和arduino的tx,rx交叉连接,

在其人脸识别模块的代码里添加串口通信处理serial.send,

import sensor, image, time, lcd
from maix import KPU
import gc
from modules import ybserial

lcd.init()
sensor.reset()                      # Reset and initialize the sensor. It will
                                    # run automatically, call sensor.run(0) to stop
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 1000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

serial = ybserial()

anchor = (0.1075, 0.126875, 0.126875, 0.175, 0.1465625, 0.2246875, 0.1953125, 0.25375, 0.2440625, 0.351875, 0.341875, 0.4721875, 0.5078125, 0.6696875, 0.8984375, 1.099687, 2.129062, 2.425937)
kpu = KPU()
kpu.load_kmodel("/sd/KPU/yolo_face_detect/face_detect_320x240.kmodel")
kpu.init_yolo2(anchor, anchor_num=9, img_w=320, img_h=240, net_w=320 , net_h=240 ,layer_w=10 ,layer_h=8, threshold=0.5, nms_value=0.2, classes=1)

lm68_kpu = KPU()
print("ready load model")
lm68_kpu.load_kmodel("/sd/KPU/face_detect_with_68landmark/landmark68.kmodel")

RATIO = 0.08
def extend_box(x, y, w, h, scale):
    x1_t = x - scale*w
    x2_t = x + w + scale*w
    y1_t = y - scale*h
    y2_t = y + h + scale*h
    x1 = int(x1_t) if x1_t>1 else 1
    x2 = int(x2_t) if x2_t<320 else 319
    y1 = int(y1_t) if y1_t>1 else 1
    y2 = int(y2_t) if y2_t<240 else 239
    cut_img_w = x2-x1+1
    cut_img_h = y2-y1+1
    return x1, y1, cut_img_w, cut_img_h

while 1:
    gc.collect()
    #print("mem free:",gc.mem_free())
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()
    kpu.run_with_output(img)
    dect = kpu.regionlayer_yolo2()
    fps = clock.fps()
    if len(dect) > 0:
        print("dect:",dect)
        text = 'Hello11\n'
        num = serial.send(text)
        print("num:", num)
        for l in dect :
            x1, y1, cut_img_w, cut_img_h = extend_box(l[0], l[1], l[2], l[3], scale=RATIO) # 扩大人脸框
            face_cut = img.cut(x1, y1, cut_img_w, cut_img_h)
            a = img.draw_rectangle(l[0],l[1],l[2],l[3], color=(0, 255, 0))
            face_cut_128 = face_cut.resize(128, 128)
            face_cut_128.pix_to_ai()
            out = lm68_kpu.run_with_output(face_cut_128, getlist=True)
            #print("out:",len(out))
            for j in range(68):
                x = int(KPU.sigmoid(out[2 * j])*cut_img_w + x1)
                y = int(KPU.sigmoid(out[2 * j + 1])*cut_img_h + y1)
                #a = img.draw_cross(x, y, size=1, color=(0, 0, 255))
                a = img.draw_circle(x, y, 2, color=(0, 0, 255), fill=True)
            del (face_cut_128)
            del (face_cut)

    a = img.draw_string(0, 0, "%2.1ffps" %(fps), color=(0, 60, 255), scale=2.0)
    lcd.display(img)
    gc.collect()

kpu.deinit()
lm68_kpu.deinit()


arduino收到串口信号时,调用继电器来实现通电,达到点击屏幕的效果,

在串口接收上添加了一点修改

/*
  Serial Event example

  When new serial data arrives, this sketch adds it to a String.
  When a newline is received, the loop prints the string and clears it.

  A good test for this is to try it with a GPS receiver that sends out
  NMEA 0183 sentences.

  NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or
  other ATmega32U4 based boards.

  created 9 May 2011
  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent
*/
int relayPin = 4;

String inputString = "";      // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(115200);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
      pinMode(relayPin, OUTPUT);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    
    digitalWrite(relayPin, HIGH);
    delay(3000);
    digitalWrite(relayPin, LOW);
    stringComplete = false;
  }
  delay(10);
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  if (stringComplete) {
    return;
  }
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
      break;
    }
  }
}

这里使用的是人脸检测,在吃鸡实战中效果不好,

人体检测会好一些,

去训练的话可以参考

http://t.csdnimg.cn/ZfoSE

【手把手在K210上部署自己在线训练的YOLO模型 -  CSDN App】http://t.csdnimg.cn/uwcb9

http://t.csdnimg.cn/uwcb9

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2072601.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用GDIView工具排查GDI对象泄漏案例的若干细节总结

目录 1、查看任务管理器&#xff0c;发现程序中有明显的GDI对象泄漏 2、使用GDIView工具查看发生泄漏的是哪一种GDI对象 3、尝试找到复现问题的方法&#xff0c;缩小排查范围&#xff0c;逐步地找到GDI对象的泄漏点 4、本案例中的相关细节点的思考与总结&#xff08;有价值…

httpClient与openfeign

目录 介绍 maven坐标 发送请求步骤 发送get请求 ​发送post请求 介绍 是一个客户端编程的工具包&#xff0c;也就是在java程序中&#xff0c;可以构造http请求并且发送请求 maven坐标 httpclient <dependency> <groupId>org.apache.httpcomponents</g…

【Kotlin设计模式】建造者模式在Android中的应用

前言 建造者模式&#xff08;Builder Pattern&#xff09;是一种创建型设计模式&#xff0c;一步一步地构建一个复杂对象的不同部分&#xff0c;而不是直接创建该对象的实例。建造者模式的核心思想是将对象的构建过程与其表示分离&#xff0c;使得同样的构建过程可以创建不同的…

如何使用ssm实现基于ssm的疫情物质管理系统

TOC ssm170基于ssm的疫情物质管理系统jsp 第一章 绪论 1.1 研究背景 时代总是在进步的&#xff0c;自从进入了信息时代&#xff0c;面对大量的不同种类的数据&#xff0c;仅仅依靠有限的人力去处理&#xff0c;显然是不行的&#xff0c;毕竟人工处理大量的数据会耗费较长时…

git提交项目,报403无权限

这个在公司内网git上提交项目时&#xff0c;使用的是刚分配到的账号和密码。创建完组和项目后一切准备完毕了&#xff0c;但是在提交时缺出了乌龙&#xff0c;报403&#xff0c;上面一堆英文&#xff0c;大致的意思是说我没有上传本项目的权限&#xff0c;报错信息如下图所示&a…

5.1二叉树——基本概念梳理

本篇博客梳理二叉树相关的基本概念 一、树的概念与结构 1&#xff0e;树是递归定义的 树根N棵子树&#xff0c;每棵子树也可按照相同方式拆分 注意&#xff1a;子树之间不能有交集&#xff0c;否则变成图&#xff08;是另一种数据结构&#xff09; 2&#xff0e;树的相关概…

Linux进程信号——信号的概念与产生

文章目录 信号及其产生与发送什么是Linux信号信号的产生终端按键系统调用软件条件硬件条件 核心转储存储临时信号 信号及其产生与发送 我们从生活中理解信号&#xff0c;例如各种指示灯&#xff0c;红绿灯之类的&#xff0c;我们能认识红绿灯是因为每一种不同的情况在我们大脑…

Apache Doris 跨集群数据同步 CCR 全面介绍

CCR 概述 CCR&#xff08;Cross Cluster Replication&#xff09;也就是跨集群数据复制&#xff0c;能够在库/表级别将源集群的数据变更同步到目标集群&#xff0c;可用于提升在线服务的数据可用性、隔离在离线负载、建设两地三中心等。 CCR 通常被用于容灾备份、读写分离、集…

末代皇帝Intel核显黑苹果,NUC10的性能到底有多强

末代皇帝Intel核显黑苹果&#xff0c;NUC10的性能到底有多强 一、可以核显的Intel iGPU有哪些 核显是一个伟大的产物&#xff0c;它可以在我们没有多余的钱去买多余的显卡的时候排上用场&#xff0c;特别是在mini小主机的市场上&#xff0c;核显就显得尤为重要的&#xff0c;…

图形化的Agent工具

1 图形化 Agent 工具 1.1 核心组件 机器人 Bot&#xff1a;一个 AI 应用&#xff0c;或称为 Agent知识库&#xff1a;上传个人数据&#xff0c;机器人可根据其内容进行回复工作流&#xff1a;将大问题拆解成多个小问题&#xff0c;通过路径实现&#xff0c;路径上的每个节点完…

tomcat实战演练

一.tomcat介绍 Tomcat 服务器是一个免费的开放源代码的 Web 应用服务器&#xff0c;属于轻量级应用服务器&#xff0c;在中小型系统和并发访问用户不是很多的场合下被普遍使用&#xff0c; Tomcat 具有处理 HTML 页面的功能&#xff0c;它还是一个 Servlet 和 JSP容器。Tomc…

Python优化算法13——飞蛾扑火优化算法(MFO)

科研里面优化算法都用的多&#xff0c;尤其是各种动物园里面的智能仿生优化算法&#xff0c;但是目前都是MATLAB的代码多&#xff0c;python几乎没有什么包&#xff0c;这次把优化算法系列的代码都从底层手写开始。 需要看以前的优化算法文章可以参考&#xff1a;Python优化算…

三种插入排序详解和代码实现(直接插入排序、折半插入排序和希尔排序)

目录 基本思想直接插入排序排序方法代码实现复杂度分析 折半插入排序排序方法代码实现复杂度分析 希尔排序排序方法代码实现复杂度分析最佳情况平均情况最坏情况增量序列的影响 基本思想 插入排序的基本思想是&#xff1a;每一趟将一个待排序的元素按照其关键字的大小插入到已经…

Hadoop 分布式集群搭建

HDFS分布式集群搭建 一、部署规划1.1 进程规划1.2 软件规划1.3 用户规划1.4 目录规划 二、 搭建HDFS 分布式集群2.1 HDFS 集群配置2.1.1 下载安装 Hadoop2.1.2 修改 hadoop-env.sh 配置文件2.1.3 修改 core-site.xml 配置文件2.1.4 修改 hdfs-site.xml 配置文件2.1.5 修改 slav…

力扣刷题(1)

两数之和 两数之和-力扣 思路&#xff1a; 动态开辟一个数组&#xff0c;用来存放下标&#xff1b;两个for循环嵌套来判断&#xff0c;数组中的两个数相加是否与target相等若相等&#xff0c;则将 * returnSize赋值为2&#xff0c;表示数组中两个数&#xff0c;并将arr数组…

数学建模之数据分析【九】:数据清理总结

文章目录 一、什么是数据清理二、为什么数据清理很重要三、执行数据清洁的步骤四、如何执行数据清理五、数据清理的Python库实现5.1 数据检查与探索5.2 使用df.info()检查数据信息5.3 检查分类和数字列5.4 检查分类列中唯一值的总数5.5 执行数据清理的步骤5.5.1 删除所有上述不…

真的爽到了!Coze的黑神话 “循环“ 闪亮登场,啥都能循环,让你一次通关!

心心念念了很久&#xff0c;Coze工作流终于支持循环操作啦&#xff0c;泪奔~~ 看&#xff0c;就在工作流节点的“选择器”和“意图识别”当中偷偷摸摸地多了一个“循环” 这玩意可比批处理强太多了&#xff0c;批处理只能在当前节点循环&#xff0c;做一些简单的循环任务还不错…

【日记】狗尾巴草与暗恋(1519 字)

写在前面 消极内容注意 正文 好想吃火龙果。 下周会变得异常艰难。因为事情已经垒到天上去了&#xff0c;还要来检查。 上午&#xff0c;同事送了一点水果&#xff0c;我从来没见过。问了一下别人&#xff0c;有的说是灯笼果&#xff0c;有的说是菇凉果、姑娘果。搜了一下&am…

深入理解Elasticsearch:让搜索性能飞起来!

Elasticsearch 概述 Elasticsearch是一个基于lucene、分布式、通过Restful方式进行交互的近实时搜索平台框架。 ELK 技术栈是Elasticsearch、Logstash、Kibana三大开元框架首字母大写简称。 而Elasticsearch 是一个开源的高扩展的分布式全文搜索引擎&#xff0c; 是整个 ELK技术…

polarctf靶场[WEB]Don‘t touch me、机器人、uploader、扫扫看

目录 [web]Dont touch me 考点&#xff1a;查看源代码、前端 [web]机器人 考点&#xff1a;robot协议 工具&#xff1a;御剑&#xff0c;kali dirsearch [web]覆盖 考点&#xff1a;parse_str覆盖 [web]扫扫看 考点&#xff1a;目录扫描 工具&#xff1a;御剑、kali d…