物品识别 树莓派 5 YOLO v5 v8 v10 11 计算机视觉

0. 要实现的效果


让树莓派可以识别身边的一些物品,比如电脑,鼠标,键盘,杯子,行李箱,双肩包,床,椅子等



1. 硬件设备



2. 前置条件

  1. 给树莓派烧录好操作系统,下面我们会用现在最新的(2024年12月) bookworm
  2. VNC 连接或者用一根 HDMI 或者用官方的 raspberrypi connect

我写过一篇关于给树莓派烧录操作系统的 blog blog.csdn.net/u013633921/article/details/121433186

也有一篇 VNC 的 blog blog.csdn.net/u013633921/article/details/129677105


3. 开始!


更新一下,下面 4 个截图都好理解,不懂问问 AI


下面这条命令将安装 OpenCV 以及运行 YOLO 所需的基础设施

bash 复制代码
pip install ultralytics[export]

还会安装大量其他软件包,容易失败

如果安装失败(会显示一大片红色)

只需重新执行,已经安装过的不会再安装

我是一次过的,哈哈哈哈哈哈~(过程大概有 2 个小时 🤔)

安装后,重启树莓派

Pi 5 有物理按键,连续按两次会关机。等等再按一次,就会启动。


4. Thonny

切换到常规模式。

关闭 Thonny 再打开 Thonny。


用 Thonny 创建个文件 yolo.py

bash 复制代码
import cv2
from picamera2 import Picamera2
from ultralytics import YOLO

# Set up the camera with Picam
picam2 = Picamera2()
picam2.preview_configuration.main.size = (1280, 1280)
picam2.preview_configuration.main.format = "RGB888"
picam2.preview_configuration.align()
picam2.configure("preview")
picam2.start()

# Load YOLOv8
model = YOLO("yolov8n.pt")

while True:
    # Capture a frame from the camera
    frame = picam2.capture_array()
    
    # Run YOLO model on the captured frame and store the results
    results = model(frame)
    
    # Output the visual detection data, we will draw this on our camera preview window
    annotated_frame = results[0].plot()
    
    # Get inference time
    inference_time = results[0].speed['inference']
    fps = 1000 / inference_time  # Convert to milliseconds
    text = f'FPS: {fps:.1f}'

    # Define font and position
    font = cv2.FONT_HERSHEY_SIMPLEX
    text_size = cv2.getTextSize(text, font, 1, 2)[0]
    text_x = annotated_frame.shape[1] - text_size[0] - 10  # 10 pixels from the right
    text_y = text_size[1] + 10  # 10 pixels from the top

    # Draw the text on the annotated frame
    cv2.putText(annotated_frame, text, (text_x, text_y), font, 1, (255, 255, 255), 2, cv2.LINE_AA)

    # Display the resulting frame
    cv2.imshow("Camera", annotated_frame)

    # Exit the program if q is pressed
    if cv2.waitKey(1) == ord("q"):
        break

# Close all windows
cv2.destroyAllWindows()

点一下绿色 Run 按钮(三角),等一小会,

然后你就能看到这样的运行效果了。按 q 可以关闭。

可以改改第 7 行,第 14 行,再运行看看


喜欢或对你有帮助,点个赞吧,自己先点个嘿嘿。
有错误或者疑问还请评论指出。
我的个人网站 点击访问 hongweizhu.com

END

推荐一下我写的的 App 熊猫小账本

熊猫小账本 一个简洁的记账 App,用于记录日常消费开支收入,使用 iCloud 保存同步数据。

  • 支持备注,自定义时间偶尔忘记记账也没关系。
  • 搜索历史记账,支持分类、金额、备注。
  • 启动时需要面容/指纹验证,保护个人隐私。
  • 支持自定义分类功能,自由添加修改分类。
  • 统计图表,支出收入一目了然。
  • 每天提醒记账,不会有其他推送。
  • 桌面锁屏小组件等。

点击了解更多详情 👀

相关推荐
算法与编程之美1 天前
探究pytorch中多个卷积层和全连接层的输出方法
人工智能·pytorch·深度学习·神经网络·cnn
CoderJia程序员甲1 天前
GitHub 热榜项目 - 日榜(2025-11-12)
ai·开源·大模型·github·ai教程
Master_oid1 天前
机器学习21:可解释机器学习(Explainable Machine Learning)(上)
人工智能·机器学习
MobotStone1 天前
边际成本趋近于零:如何让AI智能体"说得清、讲得明"
人工智能·架构
新智元1 天前
李飞飞「世界模型」正式开放,人人可用! Pro 版首月仅 7 元
人工智能·openai
新智元1 天前
GPT-5.1 凌晨突袭,奥特曼听劝!全网呼唤的人味回来了
人工智能
钅日 勿 XiName1 天前
一小时速通Pytorch之自动梯度(Autograd)和计算图(Computational Graph)(二)
人工智能·pytorch·python
拓端研究室1 天前
专题:2025中国医疗器械出海现状与趋势创新发展研究报告|附160+份报告PDF、数据、可视化模板汇总下载
大数据·人工智能·pdf
算家计算1 天前
PaddleOCR-VL-vLLM-OpenAI-API使用教程来了!手把手教你搞定文档解析
人工智能·开源
算家计算1 天前
GPT-5.1深夜发布却无惊喜?从GPT-5.1看大模型发展瓶颈
人工智能·chatgpt·openai