拓冰建站拓冰建站
首页 / 资讯中心 / 正文

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

0. 要实现的效果让树莓派可以识别身边的一些物品比如电脑鼠标键盘杯子行李箱双肩包床椅子等1. 硬件设备树莓派 5 raspberrypi.com/products/raspberry-pi-5/树莓派官方摄像头 v3 raspberrypi.com/products/camera-module-3/自己的电脑windows 或者 mac2. 前置条件给树莓派烧录好操作系统下面我们会用现在最新的2024年12月 bookwormVNC 连接或者用一根 HDMI 或者用官方的 raspberrypi connect我写过一篇关于给树莓派烧录操作系统的 blog blog.csdn.net/u013633921/article/details/121433186也有一篇 VNC 的 blog blog.csdn.net/u013633921/article/details/1296771053. 开始更新一下下面 4 个截图都好理解不懂问问 AI下面这条命令将安装 OpenCV 以及运行 YOLO 所需的基础设施pipinstallultralytics[export]还会安装大量其他软件包容易失败如果安装失败会显示一大片红色只需重新执行已经安装过的不会再安装我是一次过的哈哈哈哈哈哈过程大概有 2 个小时 安装后重启树莓派Pi 5 有物理按键连续按两次会关机。等等再按一次就会启动。4. Thonny切换到常规模式。关闭 Thonny 再打开 Thonny。用 Thonny 创建个文件 yolo.pyimportcv2 from picamera2importPicamera2 from ultralyticsimportYOLO# Set up the camera with Picampicam2Picamera2()picam2.preview_configuration.main.size(1280,1280)picam2.preview_configuration.main.formatRGB888picam2.preview_configuration.align()picam2.configure(preview)picam2.start()# Load YOLOv8modelYOLO(yolov8n.pt)whileTrue:# Capture a frame from the cameraframepicam2.capture_array()# Run YOLO model on the captured frame and store the resultsresultsmodel(frame)# Output the visual detection data, we will draw this on our camera preview windowannotated_frameresults[0].plot()# Get inference timeinference_timeresults[0].speed[inference]fps1000/ inference_time# Convert to millisecondstextfFPS: {fps:.1f}# Define font and positionfontcv2.FONT_HERSHEY_SIMPLEX text_sizecv2.getTextSize(text, font,1,2)[0]text_xannotated_frame.shape[1]- text_size[0]-10# 10 pixels from the righttext_ytext_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 pressedifcv2.waitKey(1)ord(q):break# Close all windowscv2.destroyAllWindows()点一下绿色 Run 按钮三角等一小会然后你就能看到这样的运行效果了。按 q 可以关闭。可以改改第 7 行第 14 行再运行看看喜欢或对你有帮助点个赞吧自己先点个嘿嘿。有错误或者疑问还请评论指出。我的个人网站点击访问 hongweizhu.com。END推荐一下我写的的 App 熊猫小账本熊猫小账本一个简洁的记账 App用于记录日常消费开支收入使用 iCloud 保存同步数据。支持备注自定义时间偶尔忘记记账也没关系。搜索历史记账支持分类、金额、备注。启动时需要面容/指纹验证保护个人隐私。支持自定义分类功能自由添加修改分类。统计图表支出收入一目了然。每天提醒记账不会有其他推送。桌面锁屏小组件等。点击了解更多详情
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门