当前位置: 首页 > news >正文

物品识别 树莓派4 YOLO v11

 让树莓派可以识别身边的一些物品

python3  -m venv --system-site-packages yolooo

source yolooo/bin/activate

树莓派换清华源,bookworm

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

pip install ultralytics
还会安装大量其他软件包,容易失败
如果安装失败(会显示一大片红色)
 

  • 官方PyPI源在2025年Q1出现过区域性访问故障
  • 推荐改用阿里云镜像:
    pip install ultralytics[export] -i https://mirrors.aliyun.com/pypi/simple/

如果有问题,再用这个装一下  

pip install ultralytics[export] -i https://pypi.tuna.tsinghua.edu.cn/simple

 安装完毕,接着,打开Thonny,切换到常规模式。重新打开

 

 

 

 用 Thonny 创建个文件 yolo.py

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 cameraframe = picam2.capture_array()# Run YOLO model on the captured frame and store the resultsresults = model(frame)# Output the visual detection data, we will draw this on our camera preview windowannotated_frame = results[0].plot()# Get inference timeinference_time = results[0].speed['inference']fps = 1000 / inference_time  # Convert to millisecondstext = f'FPS: {fps:.1f}'# Define font and positionfont = cv2.FONT_HERSHEY_SIMPLEXtext_size = cv2.getTextSize(text, font, 1, 2)[0]text_x = annotated_frame.shape[1] - text_size[0] - 10  # 10 pixels from the righttext_y = text_size[1] + 10  # 10 pixels from the top# Draw the text on the annotated framecv2.putText(annotated_frame, text, (text_x, text_y), font, 1, (255, 255, 255), 2, cv2.LINE_AA)# Display the resulting framecv2.imshow("Camera", annotated_frame)# Exit the program if q is pressedif cv2.waitKey(1) == ord("q"):break# Close all windows
cv2.destroyAllWindows()

点一下绿色 Run 按钮

 

相关文章:

  • 常用的Linux命令100条
  • 如何启动vue项目及vue语法组件化不同标签应对的作用说明
  • 批量图片处理的小工具
  • Paging 3.0 + Kotlin 分页加载指南
  • 计算机网络与多线程同步机制详解
  • Pytorch应用 小记 第一回:基于ResNet网络的图像定位
  • 汇编语言的温度魔法:单总线温度采集与显示的奇幻之旅
  • Python-函数
  • 备战菊厂笔试3
  • C# 使用 WinUI 3 项目模板创建桌面应用程序
  • C++GO语言微服务之图片、短信验证码生成及存储
  • Ajax基础
  • .Net HttpClient 管理客户端(初始化与生命周期管理)
  • 202534 | KafKa简介+应用场景+集群搭建+快速入门
  • kafka的安装及简单使用
  • [sklearn机器学习概述]机器学习-part3
  • 运算符与表达式 -《Go语言实战指南》
  • Scala与Go的异同教程
  • 【计算机视觉】OpenCV项目实战:基于OpenCV的图像分割技术深度解析与实践指南
  • 5.1 神经网络: 层和块
  • 陈宝良 高寿仙 彭勇︱明清社会的皇权、商帮与市井百态
  • 巴防空系统击落印度无人机,印称巴方违反停火协议
  • 龙湖集团:今年前4个月销售220.8亿元,4月新增两块土地储备
  • 人民日报钟声:平等对话是解决大国间问题的正确之道
  • 秦洪看盘|交易型资金收缩,释放短线压力
  • 外交部:习近平主席同普京总统达成许多新的重要共识