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

物品识别 树莓派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 按钮

 

http://www.xdnf.cn/news/5288.html

相关文章:

  • 青少年编程与数学 02-019 Rust 编程基础 05课题、复合数据类型
  • 解锁 DevOps 新境界 :使用 Flux 进行 GitOps 现场演示 – 自动化您的 Kubernetes 部署
  • 大模型(LLMs)强化学习——RLHF及其变种
  • 基于强化学习 Q-learning 算法求解城市场景下无人机三维路径规划研究,提供完整MATLAB代码
  • linux测试硬盘读写速度
  • uniapp|实现商品分类与列表数据联动,左侧菜单右侧商品列表(瀑布流、高度自动计算、多端兼容)
  • 音频类网站或者资讯总结
  • 电子电器架构 --- 车载以太网拓扑
  • OSPF的四种特殊区域(Stub、Totally Stub、NSSA、Totally NSSA)详解
  • PyTorch 线性回归模型构建与神经网络基础要点解析
  • 数据结构精解:优先队列、哈希表与树结构
  • AI 入门资源:微软 AI-For-Beginners 项目指南
  • Kotlin 协程 vs RxJava vs 线程池:性能与场景对比
  • 【论文阅读】Efficient and secure federated learning against backdoor attacks
  • MySQL 索引(一)
  • 【C++ Qt】容器类(GroupBox、TabWidget)内附思维导图 通俗易懂
  • 发行基础:本地化BUG导致审核失败
  • 动态规划:最长递增子序列
  • 通俗的桥接模式
  • Kubernetes生产实战(十七):负载均衡流量分发管理实战指南
  • 第三天——贪心算法——区间问题
  • 【Java ee初阶】网络编程 UDP socket
  • 无法更新Google Chrome的解决问题
  • 手写系列——transformer网络完成加法和字符转译任务
  • 【Linux进程控制一】进程的终止和等待
  • CDGP重点知识梳理
  • dropout层
  • [C++类和对象]类和对象的引入
  • 计算机的基本组成
  • 最优化方法Python计算:有约束优化应用——线性Lasso回归分类器