这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » 【Arduino_UNO_Q】图像检测

共2条 1/1 1 跳转至

【Arduino_UNO_Q】图像检测

工程师
2026-06-05 21:49:14     打赏

【Arduino UNO Q】图像检测

本文介绍了 Arduino UNO Q 开发板结合 Arduino App Lab 实现网页图像检测和目标识别的项目设计,包括软件安装、工程创建、流程图、工程代码、效果演示等。

项目介绍

  • 准备工作:硬件连接、Arduino App Lab 安装、软件包更新等;

  • 工程加载:目标检测例程、工程代码、流程图等;

  • 调试运行:编译上传、运行程序、加载图片测试、效果演示等。


硬件连接

  • 连接显示屏(或 SSH 远程登录、数据线 ADB 登录);

  • 连接鼠标键盘;

  • WiFi 连接无线网;

  • 使用 PD 电源供电;

hardware_connect.jpg

工程创建

  • 识别到开发板,点击连接设备;

  • 进入 Examples 标签页;

  • 打开 Detect objects on images 示例工程;

example_detect_objects.jpg

流程图


flowchart_detect_object.jpg


工程代码

展开左侧文件列表,打开 python/main.py 文件,代码如下

 from arduino.app_utils import *
 from arduino.app_bricks.web_ui import WebUI
 from arduino.app_bricks.object_detection import ObjectDetection
 from PIL import Image
 import io
 import base64
 import time
 
 object_detection = ObjectDetection()
 
 def on_detect_objects(client_id, data):
     """Callback function to handle object detection requests."""
     try:
         image_data = data.get('image')
         confidence = data.get('confidence', 0.5)
         if not image_data:
             ui.send_message('detection_error', {'error': 'No image data'})
             return
 
         image_bytes = base64.b64decode(image_data)
         pil_image = Image.open(io.BytesIO(image_bytes))
 
         start_time = time.time() * 1000
         results = object_detection.detect(pil_image, confidence=confidence)
         diff = time.time() * 1000 - start_time
 
         if results is None:
             ui.send_message('detection_error', {'error': 'No results returned'})
             return
 
         img_with_boxes = object_detection.draw_bounding_boxes(pil_image, results)
 
         if img_with_boxes is not None:
             img_buffer = io.BytesIO()
             img_with_boxes.save(img_buffer, format="PNG")
             img_buffer.seek(0)
             b64_result = base64.b64encode(img_buffer.getvalue()).decode("utf-8")
         else:
             # If drawing fails, send back the original image
             img_buffer = io.BytesIO()
             pil_image.save(img_buffer, format="PNG")
             img_buffer.seek(0)
             b64_result = base64.b64encode(img_buffer.getvalue()).decode("utf-8")
 
         response = {
             'success': True,
             'result_image': b64_result,
             'detection_count': len(results.get("detection", [])) if results else 0,
             'processing_time': f"{diff:.2f} ms"
         }
         ui.send_message('detection_result', response)
 
     except Exception as e:
         ui.send_message('detection_error', {'error': str(e)})
 
 ui = WebUI()
 ui.on_message('detect_objects', on_detect_objects)
 
 App.run()

保存代码。

编译运行

  • 点击右上角复制示例工程;

  • 点击右上角 RUN 按钮,自动编译、上传并运行程序;

arduino_web_ui_or_run.jpg

  • 待程序编译并上传完成,自动打开目标网页;

arduino_web_ui_or.jpg

  • 点击 Upload 按钮,上传目标识别图片;

  • 移动滑块,调整识别置信度,置信度阈值越高,识别越精确;

  • 点击 Run / Run Again 按钮,实现图像识别;

arduino_web_ui_or_bus.jpg

  • 识别结果由彩色外框标注,标签显示识别物体名称及置信度;

  • 更多测试结果如下

arduino_web_ui_or_baseball.jpg

  • 可以看出,识别结果较为准确,推理速度较快;

arduino_web_ui_or_desktop.jpg

总结

本文介绍了 Arduino UNO Q 开发板结合 Arduino App Lab 实现网页图像检测和目标识别的项目设计,包括软件安装、工程创建、流程图、工程代码、效果演示等,为相关产品在边缘 AI 领域的快速开发和应用设计提供了参考。





关键词: Arduino     边缘AI     图像识别     python    

专家
2026-06-06 07:58:20     打赏
2楼

谢谢分享


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]